I am trying to program something that I assume is possible. Essentially I want to load a DLL library function in one program (say, program A), and using getprocaddress, I want to call this function from another program, B, purely by using the function's pointer/address.
My question is basically; how do I define and use the DLL function in program B? (only knowing its address in memory.)
The dll's function is loaded into the memory space of program A and only usable from whitin this memory space.
This use to be possible on older OS but when a program crashes it could take other programs to.
Therefore each program has it own memory space where the dll is loaded in for each program.
I think however it is still possible to place some data (contained in the dll) in a shared memory block so that each dll can use this data (dangerous) but I don't think it is possible to do the same with funtion blocks.
if u know the function proto, first typedef it and then create an object of that type. for example if we want to call the
BOOL ShowWindow(HWND hWnd, int nCmdShow);
1. typedef its proto typedef BOOL (WINAPI * myShowWindow)(HWND hWnd,int nCmdShow);
2.Create an object myShowWindow fun_myShowWindow;
3. Assign the pointer obtained from GetProcAddress() to fun_myShowWindow
$. now u can call the function fun_myShowWindow as usual
eg :- fun_myShowWindow( m_hwnd, SW_SHOW);
you cannot know at what address your function will be loaded
Well, right now, I have the applications messaging eachother via Winsock (TCP). I thought that this could be simplified by sending an initial message containing the function address, and from there the second program could use the functions directly.
I got it to compile shortly after my last message, roughly:
The function in the DLL does not have a real address until that DLL is loaded into your processes address space. Since a normal DLL cannot be reliably forced into a specific address (it may collide with an already-loaded DLL's load address), you cannot presume what the function's address will be.
Your second program, B, will have to load the DLL into its address space in order to get a valid address for the function.
Going the hack route, you may be able to directly allocate virtual memory in process B, copy the actual code from the function from process A to process B (by some other means), place it into the allocated buffer, set the protection on the buffer to PAGE_EXECUTE_READ, create a suitable function pointer and set it to the address of the buffer, and try to execute it.
-But you are going to have to find out further details about that route on your own...!
-=- JamesIf you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong! Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road! DeleteFXPFiles & CheckFavorites (Please rate this post!)
My application is crashing at customer's computer (Win XP). I've told him to run drwtsn32 -I to get minidump. Although drwtsn said it was installed, after crash there is still only standard "Send report" dialog. Any ideas why drwtsn is not catching the crash ?