EntryPointNotFoundException在VB.net中加载C DLL

时间:2011-08-02 19:58:22

标签: c vb.net visual-studio-2010 dll

我花了好几个小时试图让这个简单的测试用例工作,并在互联网上寻找线索。

我有一个包含我的VB.net项目和VC ++ DLL项目的VS 10解决方案。

在我的DLL项目中,我有:

json_main.cpp:

#include <Windows.h>

extern "C"
{
    void testMethod(int* inVal )
    {
        *inVal += 5;
    }
}

JSON.def:

LIBRARY JSON
    DESCRIPTION 'Simple JSON encoder/decoder'
    EXPORTS
        testMethod

我的VB.net代码:

<DllImport("C:/inetpub/wwwroot/facebook/AlumniFinder/Debug/JSON.dll", CallingConvention:=CallingConvention.Cdecl)> _
Private Shared Sub testMethod(ByRef inVal As Integer)

End Sub
...

Dim var As Integer = 7
testMethod(var)
oLabel.Text = var.ToString

然而,当我尝试跑步时,我得到EntryPointNotFoundException

任何人都知道我在这里做错了什么?我尝试在我的DLL上使用dumpbin.exe,但是我没有从中获取任何函数名来确定它正在使用的修改方案

2 个答案:

答案 0 :(得分:3)

使用dumpbin /exports或Dependency Walker检查您是否正在导出该函数,因为它似乎不是。

我的猜测是你没有配置构建以将.def文件传递给链接器。在此屏幕截图中执行此操作:

enter image description here

答案 1 :(得分:0)

尝试此操作(不带路径,使用External):

<DllImport("JSON.dll", CallingConvention:=CallingConvention.Cdecl)> _
Private Shared External Sub testMethod(ByRef inVal As Integer)

确保JSON.dll位于输出目录(运行程序的位置)。