DLL以动态方式加载时出错!
semir 2000-09-04 01:00:00 有人用过动态链接库的动态链接吗?
为什么用LOADLIBRARY可以获得DLL的正确句柄,但用GetProcAddress得到的函数指针
总是NULL。而且用GetLastError获得的错误代码为126。
但用静态链接方式时正常。
关键部分代码为:
typedef int (*LOAD)();//定义函数指针
HINSTANCE hinstance;
LOAD testdll; //声明
int retvalue; //函数返回
...
hinstance = loadlibrary("filename.dll");//获得句柄
//此处省略判断
testdll = (LOAD)GetProcAdress(hinstance,"testfunction");//得到函数入口
retvalue = testdll(); //函数调用