调用DLL的一点小异常
调用DLL的一点小错误
#include "stdio.h "
#include "windows.h "
typedef int(*lpAddFun)(int,int); //宏定义函数指针类型
int main(int argc,char *argv[])
{
HINSTANCE hDLL; //DLL句柄
lpAddFun addFun; //函数指针
hDll=LoadLibrary( "..\\Debug\\dllTest.dll ");
if(hDll!=NULL)
{
addFun=(lpAddFun)GetProcAddress(hDll, "add ");
if(addFun!=NULL)
{
int result=addFun(2,3);
printf( "%d ",result);
}
FreeLibrary(hDll);
}
return 0;
}
——————————————————————
c:\program files\microsoft visual studio\myprojects\libtest\dlltest\dllcall\source.cpp(8) : error C2065: 'hDll ' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\libtest\dlltest\dllcall\source.cpp(8) : error C2440: '= ' : cannot convert from 'struct HINSTANCE__ * ' to 'int '
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
请帮我看看这两个错误是什么意思,是不是少调用了什么头文件呢,谢谢帮忙:)
------解决方案--------------------
HINSTANCE hDLL;
hDll=LoadLibrary....
if(hDll!=NULL)...
//hDll写错了,应该是hDLL
------解决方案--------------------
hDll=LoadLibrary( "..\\Debug\\dllTest.dll ");//hDll中的ll应该为大写
#include "stdio.h "
#include "windows.h "
typedef int(*lpAddFun)(int,int); //宏定义函数指针类型
int main(int argc,char *argv[])
{
HINSTANCE hDLL; //DLL句柄
lpAddFun addFun; //函数指针
hDll=LoadLibrary( "..\\Debug\\dllTest.dll ");
if(hDll!=NULL)
{
addFun=(lpAddFun)GetProcAddress(hDll, "add ");
if(addFun!=NULL)
{
int result=addFun(2,3);
printf( "%d ",result);
}
FreeLibrary(hDll);
}
return 0;
}
——————————————————————
c:\program files\microsoft visual studio\myprojects\libtest\dlltest\dllcall\source.cpp(8) : error C2065: 'hDll ' : undeclared identifier
c:\program files\microsoft visual studio\myprojects\libtest\dlltest\dllcall\source.cpp(8) : error C2440: '= ' : cannot convert from 'struct HINSTANCE__ * ' to 'int '
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
Error executing cl.exe.
请帮我看看这两个错误是什么意思,是不是少调用了什么头文件呢,谢谢帮忙:)
------解决方案--------------------
HINSTANCE hDLL;
hDll=LoadLibrary....
if(hDll!=NULL)...
//hDll写错了,应该是hDLL
------解决方案--------------------
hDll=LoadLibrary( "..\\Debug\\dllTest.dll ");//hDll中的ll应该为大写