Been trying to figure out how to get my applications name and path all in one string. I have searched for a while now (more than an hour), but could not find anything on this.

In Delphi (please, refrain from tossing various fruits/vegetables at me), I can simply use Application.ExeName to get this. Of course, this is not so easy in ASM, which is understandable and one of the reasons I have taken on the task of learning ASM in the first place.

I am using MASM and this program will be run on Win9x/ME machines only. So no need to take NT/2k/XP into account for this.

I know GetModuleHandle() plays a role here somewhere, but using it has actually proved to be more confusing than I thought.

Thanks in advance.
Posted on 2002-06-16 10:04:03 by The Beginner
Use GetCommandLine. If you'd read Iczelion's tutorials you would know that ;)
Posted on 2002-06-16 10:20:40 by Dr. Manhattan

Use GetCommandLine. If you'd read Iczelion's tutorials you would know that ;)


Below are all of the tutorials listed on Iczelion's pages. Where in this list do you see something that hints at an example of getting your own executable's file name and path? I can only go so far alone, so I seek help when I cannot solve a problem on my own. Other than that, I have done most of what I have accomplished with the help of these tutorials and from playing around with ideas. Just asking for a little help is all, or maybe a hint. And still not sure how GetCommandLine() will help me here... and I -do- have the latest Win32 help files.

Tutorial 1: The Basics
Tutorial 2: MessageBox
Tutorial 3: A Simple Window
Tutorial 4: Painting with Text
Tutorial 5: More about Text
Tutorial 6: Keyboard Input
Tutorial 7: Mouse Input
Tutorial 8: Menu
Tutorial 9: Child Window Controls
Tutorial 10: Dialog Box as Main Window
Tutorial 11: More about Dialog Box
Tutorial 12: Memory Management and File I/O
Tutorial 13: Memory Mapped File
Tutorial 14: Process
Tutorial 15: Multithreading Programming
Tutorial 16: Event Object
Tutorial 17: Dynamic Link Libraries
Tutorial 18: Common Controls
Tutorial 19: Tree View Control
Tutorial 20: Window Subclassing
Tutorial 21: Pipe
Tutorial 22: Window Superclassing
Tutorial 23: Tray Icon
Tutorial 24: Windows Hooks
Tutorial 25: Simple Bitmap
Tutorial 26: Splash Screen
Tutorial 27: Tooltip Control
Tutorial 28: Win32 Debug API part 1
Tutorial 29: Win32 Debug API part 2
Tutorial 30: Win32 Debug API part 3
Tutorial 31: Listview Control
Tutorial 32: Multiple Document Interface (MDI)
Tutorial 33: RichEdit Control: Basics
Tutorial 34: RichEdit Control: More Text Operations
Tutorial 35: RichEdit Control: Syntax Hilighting
Posted on 2002-06-16 10:31:05 by The Beginner
Tutorial 35.

http://www.asmcommunity.net/board/index.php?topic=106&highlight=getmodulehandle+getmodulefilename

Look up GetModuleHandle and GetModuleFilename in your API reference.
Posted on 2002-06-16 10:49:35 by bazik
Sorry if I offended you, I didn't mean to. It's in Tutorial 3 "A simple Window"

"I'll outline the steps required to create a window on the desktop below

1. Get the instance handle of your program (required)
--> 2. Get the command line (not required unless your program wants to process a command line)"

The name of the executable (path and executable name) is the first argument of the command line. There is also a function in the MASM32 library, GetCL. Look in the \MASM32\M32Lib directory. Good luck ! :alright:
Posted on 2002-06-16 10:49:53 by Dr. Manhattan
You can always use GetModuleFileName to retrieve the "fullpath\app.exe" form of your running instance.

If you want the path and the executable's name seperately, just code a parsing procedure which seeks the last "\" in the string.
Posted on 2002-06-16 10:51:02 by C.Z.

You can always use GetModuleFileName to retrieve the "fullpath\app.exe" form of your running instance.

If you want the path and the executable's name seperately, just code a parsing procedure which seeks the last "\" in the string.


bomb01:

Thanks for the hint. Here is what I was trying to use before posting my message.. I thought I had pasted it into the text box, but I guess I missed it.



GetMyPathName proc ;*** Get application path/name
invoke GetModuleFileName, NULL, MyRealName, SizeOf MyRealName
invoke MessageBox, hWnd, addr MyRealName, addr myCaption, MB_ICONINFORMATION or MB_APPLMODAL
ret
GetMyPathName endp


Now, being new to this, I know the above code is most likely wrong in a lot of ways. I guess I am just trying to figure out HOW to get the name in to a message box so that I can learn to work with the GetModuleFileName() procedure. It is a slow method of self-teaching, but it works for me.

Thanks again.
Posted on 2002-06-16 10:59:53 by The Beginner
your just missing an addr in your GetModuleFileName call

invoke GetModuleFileName,NULL,addr MyRealName,sizeof MyRealName

its not a silly question. ive been here for over a year and i still ask stupid questions.
Posted on 2002-06-16 11:34:07 by smurf
The only stopid question is the one you never ask.

Now THATS just being silly!
Posted on 2002-06-16 14:58:43 by Ernie

your just missing an addr in your GetModuleFileName call

invoke GetModuleFileName,NULL,addr MyRealName,sizeof MyRealName

its not a silly question. ive been here for over a year and i still ask stupid questions.


Thank you very much, this was exactly the problem and the solution. I tend to forget to use addr now and then, but I am getting used to it now through trial and error.

Thanks again!
Posted on 2002-06-16 16:15:58 by The Beginner
Hello all.
It is the sarcastic remarks some of the "expert" coders give to the newbies that turn them off using this board to ask questions.
I have searched the Help files many times and not found, or missed the answer. I always thought this Board was to help Coders, experienced or not.
Bob. :confused:
Posted on 2002-06-16 18:46:45 by BobMcK

your just missing an addr in your GetModuleFileName call

invoke GetModuleFileName,NULL,addr MyRealName,sizeof MyRealName

its not a silly question. ive been here for over a year and i still ask stupid questions.


Isn't the first parameter of GetModuleFileName the module handle? I think it has to be 400000h anyway...
Posted on 2002-06-16 23:41:08 by C.Z.
Handle to the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process

So if you are using NULL it may work but when another program is used to start your program it will give the address of that program.
Just use the value returned by GetModuleHandle, NULL

EDIT
wait maybe "file used to create the calling process" Dose mean the program's executable and not some other program that ran the program.
Posted on 2002-06-16 23:48:03 by Kudos
Kudos, thank you for this info.:grin:
Posted on 2002-06-17 00:17:28 by C.Z.


So if you are using NULL it may work but when another program is used to start your program it will give the address of that program.
Just use the value returned by GetModuleHandle, NULL

EDIT
wait maybe "file used to create the calling process" Dose mean the program's executable and not some other program that ran the program.



Parameters

hModule

Identifies the module whose executable filename is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file used to create the calling process.


You are absolutely right. If it is left null, and you create the process with another application, it will return the initiator's path and file name.

I tested this by making a small app to spawn the app I am working on in (M)ASM, and I invoked a MessageBox to see what it would return. It returned the calling application's path and filename.

Now, I am not sure if this holds true across different platforms, but it -did- behave this way on my WinME machine and my Win98SE machine.

Anyone else have a similar result?
Posted on 2002-06-17 10:04:00 by The Beginner