My call to GetProcAddress looks as such...
HOOKPROC procAddr = (HOOKPROC)GetProcAddress(hDll, "CBTProc");
hDll is a properly returned handle from LoadLibrary. Within the dll being used, CBTProc looks like so...
#include <windows.h>
void ourfunc(void);
int PatchAddress(int type, DWORD AddressToPatch, DWORD AddressToUse, DWORD PadSize);
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved) {
switch (dwReason) {
case DLL_PROCESS_ATTACH: {
// PatchAddress(2, 0x004120d4, (DWORD)&ourfunc, NULL);
break;
}
case DLL_PROCESS_DETACH:
break;
}
return true;
}
LRESULT CALLBACK CBTProc(int nCode, WPARAM wParam, LPARAM lParam) {
return CallNextHookEx(0, nCode, wParam, lParam);
};
For all intensive purposes, that is my entire basic dll. Does anyone know why GetProcAddress would be returning NULL, and GetLastError is returning ERROR_PROC_NOT_FOUND? CBTProc exists.
Make CBTProc:
LRESULT CALLBACK __declspec(dllexport) CBTProc(int nCode, WPARAM wParam, LPARAM lParam) {
return CallNextHookEx(0, nCode, wParam, lParam);
}
Alternatively you could create a .def (module definition) file:
LIBRARY ADDRPTCH
EXPORTS
CBTProc #1
For more information, see the MSDN article (http://msdn2.microsoft.com/en-us/library/z4zxe9k8.aspx) about exporting from a DLL.
BTW, it's intents and purposes.
Perhaps you didn't export by name, but instead by ordinal? Check it with dependency walker. Dunno I could be wrong ;)
For whatever reason I've never been able to dynamically import by-name, until atleast I realized by compiler added additional characters to the export names.
-Matt
Quote from: Win32 on September 29, 2006, 05:58 PM
For whatever reason I've never been able to dynamically import by-name, until atleast I realized by compiler added additional characters to the export names.
-Matt
You can override the compiler name mangling.
// do not add c++ type info to name; export as a C function
extern "C" {
_declspec(dllexport) void __stdcall myfunction(int a, int b) {/ * ... */ }
}
with no additional changes, this will be exported as _myfunction@8 by microsoft's c++ compiler (on a 32-bit system).
you can add the following .def file to cause the function to be exported as myfunction:
LIBRARY somedll
EXPORTS
myfunction=_myfunction@8
I tried the .def file route first and it worked. So I guess I'll continue to use that method.