• Welcome to Valhalla Legends Archive.
 

GetProcAddress returning NULL - why?

Started by warz, September 29, 2006, 01:31 AM

Previous topic - Next topic

warz

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.

MyndFyre

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 about exporting from a DLL.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

RealityRipple


TheMinistered

Perhaps you didn't export by name, but instead by ordinal?  Check it with dependency walker.  Dunno I could be wrong ;)

Win32

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

K

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

warz

I tried the .def file route first and it worked. So I guess I'll continue to use that method.