User forums > Help

GetProcAddress problem

(1/3) > >>

MarshMan1101:
My program needs to install a windows hook (SetWindowsHookEx), so I created a DLL with the necessary code and everything compiled fine. In my main program, I used LoadLibrary to load the DLL and GetProcAddress to retrieve the function's address. LoadLibrary works fine, but GetProcAddress always fails. GetLastError returns ERROR_PROC_NOT_FOUND.

I did this type of thing many times before using Dev-C++ and never had problems. What on earth am I doing wrong?

mandrav:
Have you exported your function?
For GCC you can export all symbols automatically by adding --export-all-symbols (duh) to the linker options.

MarshMan1101:
I wen't to the Project's build options, clicked on the Linker tab, and added --export-all-symbols, and it still didn't work. I've also made sure I haven't misspelled the function name for GetProcAddress, so that can't be it.

The function looks like this:

DLL_EXPORT LRESULT CALLBACK CBTProc(int code, WPARAM wParam, LPARAM lParam) {
        // my code here.
}

and here is the code that trys to load it:

dllInst = LoadLibrary("loader.dll");
if (dllInst != NULL) {
    cbtProc = (HOOKPROC) GetProcAddress(dllInst, "CBTProc");
    if (cbtProc != NULL) {
        cbtHook = SetWindowsHookEx(WH_CBT, cbtProc, dllInst, tId);
    }
}

thomas:
Hmm... this looks like Joe Normal's standard keylogger template number 34... should certainly work.

MarshMan1101:
Ok, so I'm not the best programmer in the world. I mainly do it for fun. Does anyone have any ideas on what's going on?

Navigation

[0] Message Index

[#] Next page

Go to full version