getProcAddress - NULL is returned
我有以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | //mydll.cpp #include <Windows.h> #include <io.h> #define STDOUT_FILEDESC 1 class MYSTDOUT { bool shouldClose; bool isBuffered; public: MYSTDOUT(bool buf = true, bool cl = true) : isBuffered(buf), shouldClose(cl) {} ~MYSTDOUT() { if (shouldClose) { close(STDOUT_FILEDESC); } } }; __declspec(dllexport) void* mydll_init_stdout() { static MYSTDOUT outs; return &outs; } //test_dll.cpp #include <stdio.h> #include <stdlib.h> #include <Windows.h> #include <io.h> typedef void* (__cdecl *MYPROC)(void); int main(void) { int fd; void *pstdout; MYPROC init_stdout; HMODULE handle = LoadLibrary(TEXT("mydll.dll")); init_stdout = (MYPROC)GetProcAddress(handle,"mydll_init_stdout");//NULL FreeLibrary((HMODULE) handle); return 0; } |
我知道init_stdout为NULL。可能是什么问题?
句柄确定(非NULL)
谢谢
那是由于名字处理。
您需要将导出的函数包装在
1 2 3 4 5 6 7 8 | extern"C" { __declspec(dllexport) void* mydll_init_stdout() { static MYSTDOUT outs; return &outs; } } |
在Dependency Walker或
使用
1 2 3 4 5 6 7 8 | extern"C" { __declspec(dllexport) void* mydll_init_stdout() { static MYSTDOUT outs; return &outs; } } |