【发布时间】:2012-02-17 05:41:16
【问题描述】:
我正在准备一个小的 C++ dll,其中的函数将从 C# 中调用。
DLLTestFile.h
#ifdef DLLFUNCTIONEXPOSETEST_EXPORTS
#define DLLFUNCTIONEXPOSETEST_API __declspec(dllexport)
#else
#define DLLFUNCTIONEXPOSETEST_API __declspec(dllimport)
#endif
extern "C" DLLFUNCTIONEXPOSETEST_API int fnSumofTwoDigits(int a, int b);
DLLTestfile.cpp
#include "stdafx.h"
#include "DLLFunctionExposeTest.h"
BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
return TRUE;
}
DLLFUNCTIONEXPOSETEST_API int fnSumofTwoDigits(int a, int b)
{
return a + b;
}
C# 项目:
static class TestImport
{
[DllImport("DLLFunctionExposeTest.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "fnSumofTwoDigits")]
public static extern int fnSumofTwoDigits(int a, int b);
}
public partial class MainWindow : Window
{
int e = 3, f = 4;
public MainWindow()
{
try
{
InitializeComponent();
int g = TestImport.fnSumofTwoDigits(e, f);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
我收到异常:“System.EntryNotFoundException:无法在 DLL 中找到入口点”
我在创建新项目时使用 Visual Studio 提供的默认模板,Visual C++ -> Win32 项目 -> DLL(已检查导出符号)。有人可以为此提出解决方案吗?找了很久也没找到问题。
【问题讨论】:
标签: c# c++ wpf visual-c++