Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

LoadString & I...:]..

As i understood my reference i could load strings from another
executable file through LoadString function, where in HINSTANCE part i should put module handle of desired executable file, received through GetModuleHandle or LoadLibrary....but it aint working.
Anybody knows another way, if possible, or what's wrong with this one.

thanks in advance!

bLaGoYe

Comments

  • AsmGuru62AsmGuru62 Posts: 6,519Member
    : As i understood my reference i could load strings from another
    : executable file through LoadString function, where in HINSTANCE part i should put module handle of desired executable file, received through GetModuleHandle or LoadLibrary....but it aint working.
    : Anybody knows another way, if possible, or what's wrong with this one.
    :
    : thanks in advance!
    :
    : bLaGoYe
    :

    It will help if you post the piece of code in question. There can be a lot wrong with the code itself...

    Advice: when Win32 API function fails you should always call 'GetLastError()' to see the error code which you can find in MSDN under the key "error codes [Win32]".

  • bLaGoYebLaGoYe Posts: 26Member
    here's the deal....
    in my TEST.EXE file there are stored some strings with resource numbers wich i, ofcourse, know. It works fine when i try to load them within the program TEST, but i want to load them from another program. Here's the code:
    ....
    ....
    ....
    invoke GetModuleHandle,offset filename
    mov hinst,eax
    ....
    invoke LoadString,hinst,100,offset buf,50
    ....
    ....
    Thanks for the hint with error codes.
    GetLastError retrieves from GetModuleHandle - ERROR_BAD_FORMAT.
    In the tutorial it says i have to load the module, and then to retrieve handle through GetModuleHandle. How should i load it?
    :) thank you for patience....
    bLaGoYe

  • pingpongpingpong Posts: 937Member
    i think the problem with strings is you have to load the EXE into your own address space, this might work (havent tried):

    HINSTANCE inst = LoadLibrary("bla.exe");
    char buf[51];
    LoadString(inst, 100, buf, 50);
    FreeLibrary(inst); // if you dont need it anymore.


    : here's the deal....
    : in my TEST.EXE file there are stored some strings with resource numbers wich i, ofcourse, know. It works fine when i try to load them within the program TEST, but i want to load them from another program. Here's the code:
    : ....
    : ....
    : ....
    : invoke GetModuleHandle,offset filename
    : mov hinst,eax
    : ....
    : invoke LoadString,hinst,100,offset buf,50
    : ....
    : ....
    : Thanks for the hint with error codes.
    : GetLastError retrieves from GetModuleHandle - ERROR_BAD_FORMAT.
    : In the tutorial it says i have to load the module, and then to retrieve handle through GetModuleHandle. How should i load it?
    : :) thank you for patience....
    : bLaGoYe
    :


  • bLaGoYebLaGoYe Posts: 26Member
    I figured it out. LoadLibrary should work, but only on DLL-s.
    To load EXE file in memory you need LoadLibraryEx function.

    this should do the trick on loading EXE file:
    invoke LoadLibraryEx,offset exefile,0,LOAD_LIBRARY_AS_DATAFILE

    loading a string from here is the same as we said before.
    thank you anyway !

    bLaGoYe

  • pingpongpingpong Posts: 937Member
    i never tested that code so you are probably right. although, i was pretty much sure that i used LoadLibrary once to load an exe. but what do you know, thanks for the tip and good luck on your project.

    : I figured it out. LoadLibrary should work, but only on DLL-s.
    : To load EXE file in memory you need LoadLibraryEx function.
    :
    : this should do the trick on loading EXE file:
    : invoke LoadLibraryEx,offset exefile,0,LOAD_LIBRARY_AS_DATAFILE
    :
    : loading a string from here is the same as we said before.
    : thank you anyway !
    :
    : bLaGoYe
    :


  • ColdShineColdShine Posts: 597Member
    Everything fine, just keep in mind if all you need is a resource (that is, no code), do load DLLs with LoadLibraryEx and LOAD_LIBRARY_AS_DATAFILE. This will avoid calling DllMain for the loaded library, saving a lot of CPU time and resources (since the library code will not be mapped into the caller's address space).
    _____________________________
    [size=1][b][grey]Cold[/grey][blue]Shine[/blue][/b]
    http://www16.brinkster.com/rafonline[/size]


Sign In or Register to comment.