windows - Dynamically loading exe file -
i'm trying dynamically load exe file program , run someprocedure dynamicaly loaded exe. here's i'm doing in loaded exe - library.exe
interface procedure someprocedure; stdcall; implementation procedure someprocedure; begin showmessage('ala has cat'); end;
and here's exe load's library.exe , try run someprocedure it.
type thandle = integer; tproc = procedure(); var ahandle: thandle; proc: tproc; procedure tform1.button1click(sender: tobject); begin ahandle := loadlibrary('library.exe'); if ahandle <> 0 begin @proc := getprocaddress(ahandle, 'someprocedure'); if @proc <> nil try proc; freelibrary(ahandle); end; end; end; end;
unfortunately it's not working - ahandle has address getprocaddress returns nil. doing wrong?
to best of knowledge, attempting not possible. cannot use loadlibrary load .exe file, , call exported functions. can have 1 .exe file loaded process. you'll need move functionality library, or com server, or other solution.
as sertac points out, documentation cover this:
loadlibrary can used load other executable modules. example, function can specify .exe file handle can used in findresource or loadresource. however, not use loadlibrary run .exe file. instead, use createprocess function.
you can use getprocaddress module handle of executable. have obtain module handle calling getmodulehandle(0), example.
Comments
Post a Comment