Results 1 to 11 of 11

Thread: get exe name

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Minnesota
    Posts
    15

    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

  2. #2
    amac
    Guest
    You can use either

    PHP Code:
    GetModuleFileName(HMODULELPTSTRDWORD
    or

    PHP Code:
    GetModuleFileNameEx(HANDLEHMODULELPTSTRDWORD

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Minnesota
    Posts
    15
    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

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    OK, Here is an example:

    PHP Code:
    #include <iostream.h>
    #include <windows.h>

    int main()
    {
        
    int x;
        
    char *exefile;
        
    GetModuleFileName(GetModuleHandle(NULL), exefile200);
        
    cout<<exefile;
        
    cin>>x;
        return 
    0;

    Baaaaaaaaah

  5. #5

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Minnesota
    Posts
    15
    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

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I works find for me. Try to run this code after restarting your machine

    If it still does not work then reply again
    Baaaaaaaaah

  7. #7

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Minnesota
    Posts
    15
    yep it causes an illegal operation on my 2k box and my 98se box

  8. #8
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827

    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), exefileMAX_PATH);
        
    cout<<exefile;
        
    cin>>x;
        return 
    0;

    Baaaaaaaaah

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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

  10. #10

    Thread Starter
    New Member
    Join Date
    Jan 2001
    Location
    Minnesota
    Posts
    15
    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?

  11. #11
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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
  •  



Click Here to Expand Forum to Full Width