第一种:
__declspec(dllexport) int __stdcall myfunction(int a,int b)
{
return 1;
}
第二种:
__declspec(dllexport) int myfunction(int a,int b)
{
return 1;
}
然后在工程设置的C/C++选项卡设Code Generation为__stdcall.第三种:
int __stdcall myfunction(int a,int b)
{
return 1;
}
然后在.def文件中加上myfunction。我发现第三种可以正常调用,但第一、二种根本就找不到这个函数。
另外,如果dll导出的时候用的是__stdcall,但我用VC调用的时候,默认为__cdecl,那么我怎样才能以__stdcall的方式调用这些函数呢(用动态加载的方式)?
望指点。
__declspec(dllexport) int __stdcall myfunction(int a,int b)
{
return 1;
}
第二种:
__declspec(dllexport) int myfunction(int a,int b)
{
return 1;
}
然后在工程设置的C/C++选项卡设Code Generation为__stdcall.第三种:
int __stdcall myfunction(int a,int b)
{
return 1;
}
然后在.def文件中加上myfunction。我发现第三种可以正常调用,但第一、二种根本就找不到这个函数。
另外,如果dll导出的时候用的是__stdcall,但我用VC调用的时候,默认为__cdecl,那么我怎样才能以__stdcall的方式调用这些函数呢(用动态加载的方式)?
望指点。
HANDLE m_ResDll;
m_ResDll=LoadLibrary("eresdll.dll");
myfun=(LPLoadResString)GetProcAddress(m_ResDll,"LoadResMenu");
myfun(1,(TCAHR*)"test",12);
typedef __stdcall int (*proc)(
SQLHWND,
SQLCHAR *,
SQLSMALLINT,
SQLSMALLINT * ,
SQLUSMALLINT);proc pfn;
pfn=(proc)GetProcAddress(hdll,"PbDriverConnect");结果有以下一大堆错:D:\Project\testdll2\testdll2View.cpp(114) : error C2629: unexpected 'int ('
D:\Project\testdll2\testdll2View.cpp(121) : error C2065: 'proc' : undeclared identifier
D:\Project\testdll2\testdll2View.cpp(121) : error C2146: syntax error : missing ';' before identifier 'pfn'
D:\Project\testdll2\testdll2View.cpp(121) : error C2065: 'pfn' : undeclared identifier
D:\Project\testdll2\testdll2View.cpp(122) : error C2146: syntax error : missing ';' before identifier 'GetProcAddress'
Error executing cl.exe.testdll2.exe - 5 error(s), 0 warning(s)
EXPORTS
myfunction @1
如果不在.def文件中加入那些东西,难道就不行吗?因为我已经声明是导出函数的了。
__declspec(dllexport)
好像是MFC的东西~如果我没弄错的话~
我手头没有MSDN~
无法考证~
#pragma comment(linker, "/export:myfunction=_myfunction@8");
// 方在CPP文件里就行了.