VC++ 链接异常 其中调用了delphi中的动态库
VC++ 链接错误 其中调用了delphi中的动态库
以下是C++代码
#include <Windows.h>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
typedef int (_stdcall *TStateCallback)(int iState) ;
typedef int(_stdcall *lpAddFun)(int, int); //宏定义函数指针类型
int _stdcall test (int bt);
int main(int argc, char *argv[])
{
typedef int (_stdcall *PTestCallBack)(TStateCallback);
HINSTANCE hDll; //DLL句柄
lpAddFun addFun; //函数指针
PTestCallBack CBFun; //函数指针
hDll = LoadLibrary("MyDll.dll");
if (hDll != NULL)
{
CBFun = (PTestCallBack)GetProcAddress(hDll, "RegisterStateCallback");
if (CBFun != NULL)
{
int result = CBFun(test);
printf("%d\n", result);
}
addFun = (lpAddFun)GetProcAddress(hDll, "add");
if (addFun != NULL)
{
int result = addFun(3, 3);
printf("%d\n", result);
}
int _stdcall test (int bt );
{
int bt;
printf("%d\n", bt);
return 0;
}
FreeLibrary(hDll);
}
return 0;
}
以下是运行时产生的错误
--------------------Configuration: main - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol "int __stdcall test(int)" (?test@@YGHH@Z)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
main.exe - 2 error(s), 0 warning(s)
------解决思路----------------------
以下是C++代码
#include <Windows.h>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
typedef int (_stdcall *TStateCallback)(int iState) ;
typedef int(_stdcall *lpAddFun)(int, int); //宏定义函数指针类型
int _stdcall test (int bt);
int main(int argc, char *argv[])
{
typedef int (_stdcall *PTestCallBack)(TStateCallback);
HINSTANCE hDll; //DLL句柄
lpAddFun addFun; //函数指针
PTestCallBack CBFun; //函数指针
hDll = LoadLibrary("MyDll.dll");
if (hDll != NULL)
{
CBFun = (PTestCallBack)GetProcAddress(hDll, "RegisterStateCallback");
if (CBFun != NULL)
{
int result = CBFun(test);
printf("%d\n", result);
}
addFun = (lpAddFun)GetProcAddress(hDll, "add");
if (addFun != NULL)
{
int result = addFun(3, 3);
printf("%d\n", result);
}
int _stdcall test (int bt );
{
int bt;
printf("%d\n", bt);
return 0;
}
FreeLibrary(hDll);
}
return 0;
}
以下是运行时产生的错误
--------------------Configuration: main - Win32 Debug--------------------
Linking...
main.obj : error LNK2001: unresolved external symbol "int __stdcall test(int)" (?test@@YGHH@Z)
Debug/main.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.
main.exe - 2 error(s), 0 warning(s)
------解决思路----------------------
#include <Windows.h>
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
typedef int (_stdcall *TStateCallback)(int iState) ;
typedef int(_stdcall *lpAddFun)(int, int); //宏定义函数指针类型
int _stdcall test (int bt);
int main(int argc, char *argv[]) {
typedef int (_stdcall *PTestCallBack)(TStateCallback);
HINSTANCE hDll; //DLL句柄
lpAddFun addFun; //函数指针
PTestCallBack CBFun; //函数指针
hDll = LoadLibrary("MyDll.dll");
if (hDll != NULL) {
CBFun = (PTestCallBack)GetProcAddress(hDll, "RegisterStateCallback");
if (CBFun != NULL) {
int result = CBFun(test);
printf("%d\n", result);
}
addFun = (lpAddFun)GetProcAddress(hDll, "add");
if (addFun != NULL) {
int result = addFun(3, 3);
printf("%d\n", result);
}
FreeLibrary(hDll);
}
return 0;
}
int _stdcall test (int bt ) {
printf("%d\n", bt);
return 0;
}