|
-
Sep 9th, 2001, 11:23 PM
#1
Thread Starter
New Member
get exe name
is there anyway to get the name of the exe at runtime? Not through a console app so theres no Main the first sub ran is int WINAPI WinMain(HINSTANCE hinstance,
HINSTANCE hprevinstance,
LPSTR lpcmdline,
int ncmdshow)
thanks for helpin out a newbie
-
Sep 10th, 2001, 06:40 AM
#2
You can use either
PHP Code:
GetModuleFileName(HMODULE, LPTSTR, DWORD)
or
PHP Code:
GetModuleFileNameEx(HANDLE, HMODULE, LPTSTR, DWORD)
-
Sep 10th, 2001, 02:49 PM
#3
Thread Starter
New Member
ok that second post looks like it will work but how do you use it? Could someone give me an example or explain how to use it better, thanks
-
Sep 10th, 2001, 03:16 PM
#4
PowerPoster
OK, Here is an example:
PHP Code:
#include <iostream.h>
#include <windows.h>
int main()
{
int x;
char *exefile;
GetModuleFileName(GetModuleHandle(NULL), exefile, 200);
cout<<exefile;
cin>>x;
return 0;
}
-
Sep 10th, 2001, 03:33 PM
#5
Thread Starter
New Member
my program keeps on crashing right away when i run that code, even the code alone crashes. Does this happen for anyone else? How could i possibly fix this? Err msg: "The instruction at "0x77f82cc5" referenced memory at "0xcccccccc". The memory could not be "written"." I dont know if that will help at all but its one of thoes illegal operation type error messages. Thanks
-
Sep 10th, 2001, 04:05 PM
#6
PowerPoster
-
Sep 10th, 2001, 04:12 PM
#7
Thread Starter
New Member
yep it causes an illegal operation on my 2k box and my 98se box
-
Sep 10th, 2001, 04:33 PM
#8
PowerPoster
Hmmm...
Well, I am running windows 98 SE and it works fine for me. Try this now with a little change:
PHP Code:
#include <iostream.h>
#include <windows.h>
int main()
{
int x;
char exefile[MAX_PATH];
GetModuleFileName((HMODULE)GetModuleHandle(NULL), exefile, MAX_PATH);
cout<<exefile;
cin>>x;
return 0;
}
-
Sep 10th, 2001, 05:17 PM
#9
Monday Morning Lunatic
The difference between the two is that in the first one you hadn't allocated a buffer, so the pointer was totally random. Therefore you get an Access Violation.
The second one has a buffer, which is why it works
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Sep 10th, 2001, 07:55 PM
#10
Thread Starter
New Member
ok I think I narrowed the illegal op down to the end of the app, whats the correct way to end it? Right now im using return 0; but thats causing it to crash for some reason, Ive also tried not putting anything and it still crashes. What to do?
-
Sep 11th, 2001, 04:01 AM
#11
Monday Morning Lunatic
Can you post the exact source of your main() function, please?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|