我想使用DLLImport在C#中使用Win32 dll方法。DLL導入:無法找到入口點「fnMultiply」在DLL「ImportDLL」
的Win32 DLL C++ // h文件
#ifdef IMPORTDLL_EXPORTS
#define IMPORTDLL_API __declspec(dllexport)
#else
#define IMPORTDLL_API __declspec(dllimport)
#endif
// This class is exported from the ImportDLL.dll
class IMPORTDLL_API CImportDLL {
public:
CImportDLL(void);
// TODO: add your methods here.
int Add(int a , int b);
};
extern IMPORTDLL_API int nImportDLL;
IMPORTDLL_API int fnImportDLL(void);
IMPORTDLL_API int fnMultiply(int a,int b);
// cpp文件
// ImportDLL.cpp:定義導出的函數爲DLL應用。 //
#include "stdafx.h"
#include "ImportDLL.h"
// This is an example of an exported variable
IMPORTDLL_API int nImportDLL=0;
// This is an example of an exported function.
IMPORTDLL_API int fnImportDLL(void)
{
return 42;
}
IMPORTDLL_API int fnMultiply(int a , int b)
{
return (a*b);
}
一旦我建立這個我得到ImportDLL.dll
現在我創建的Windows應用程序和debug文件夾中添加此DLL並嘗試使用的DllImport
[DllImport("ImportDLL.dll")]
public static extern int fnMultiply(int a, int b);
使用此方法我嘗試在C#中調用它 int a = fnMultiply(5, 6);
//此行給出錯誤無法找到入口點
任何機構可以告訴我缺少什麼? 謝謝。
@HansPassant氏s不是一個實例方法。它是DLL中的常規公共函數。檢查標題decl。實際上,這是股票「創建一個帶導出符號的DLL」項目,由VS吐出。他不是在試圖挑戰實例方法,他正在嘗試連接一個導出的函數。 – WhozCraig
你是對的,被班級絆倒了。 –