开发者

Unable to Find an Entry Point (cpp)

开发者 https://www.devze.com 2023-01-29 10:14 出处:网络
This is a similar question to this one. I want to export a simple function from C++, to be called by C# via PInvoke. This is my function definition:

This is a similar question to this one.

I want to export a simple function from C++, to be called by C# via PInvoke. This is my function definition:

 int fnValue()
{
    return 42;
}

And this is the export defini开发者_StackOverflow中文版tion in .h file:

__declspec(dllexport)  int fnValue();

This is how I PInvoke the function:

    [DllImport("WhatDll.dll")]
    public static extern int fnValue();

Simple, right? But I got a

System.EntryPointNotFoundException : Unable to find an entry 'point named 'fnValue' in DLL "WhatDll.dll'

I use dumpbin to check what's inside WhatDll, and this is what I have:

00000000 characteristics 4CFB5C95 time date stamp Sun Dec 05 17:34:13 2010 0.00 version 1 ordinal base 4 number of functions 4 number of names

ordinal hint RVA name

   1    2 00011014 ?fnValue@@YAHXZ = @ILT+15(?fnValue@@YAHXZ)

Note that there is some gibberish behind the function name fnValue.

This is pretty puzzling. Any idea?


Try to write

extern "C"__declspec(dllexport)  int fnValue();


If you compile with a c++ compiler use extern "C" to export or add a .def file to specify the export names. Additionally __stdcall might be necessary

0

精彩评论

暂无评论...
验证码 换一张
取 消