“无法在 dll 中找到名为 [function] 的入口点"(c++ 到 c# 类型转换) [英] "Unable to find an entry point named [function] in dll" (c++ to c# type conversion)

查看:45
本文介绍了“无法在 dll 中找到名为 [function] 的入口点"(c++ 到 c# 类型转换)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个来自第三方的 dll,它是用 C++ 编写的.以下是来自 dll 文档的一些信息:

I have a dll which comes from a third party, which was written in C++. Here is some information that comes from the dll documentation:

//start documentation

RECO_DATA{
wchar_t Surname[200];
wchar_t Firstname[200];
}

说明:用于接收函数结果的数据结构.所有函数结果将是存储为 Unicode (UTF-8).

Description: Data structure for receiving the function result. All function result will be stored as Unicode (UTF-8).

方法:

bool recoCHN_P_Name(char *imgPath,RECO_DATA *o_data);

输入:

char * imgPath

此图像位置的完整路径功能识别

the full path of the image location for this function to recognize

RECO_DATA * o_data

接收函数的数据对象结果.函数返回:成功则返回真,否则返回假.

data object for receiving the function result. Function return: True if Success, otherwise false will return.

//end documentation

我正在尝试从我的 C# 应用程序中调用 recoCHN_P_Name.为此,我想出了这个代码:

I am trying to call the recoCHN_P_Name from my C# application. To this end, I came up with this code:

导入dll的代码:

    public class cnOCRsdk
{
    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
    public struct RECO_DATA{
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst=200)]
        public string FirstName;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 200)]
        public string Surname;
        }

    [DllImport(@"cnOCRsdk.dll", EntryPoint="recoCHN_P_Name")]
    public static extern bool recoCHN_P_Name(byte[] imgPath, RECO_DATA o_data);
}

调用函数的代码:

            cnOCRsdk.RECO_DATA recoData = new cnOCRsdk.RECO_DATA();

        string path = @"C:WINDOWS	wain_32	wainrgb.bmp";

        System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
        byte[] bytes = encoding.GetBytes(path);

        bool res = cnOCRsdk.recoCHN_P_Name(bytes, recoData);

我得到的错误是""无法在 DLL 'cnOCRsdk.dll' 中找到名为 'recoCHN_P_Name' 的入口点."我怀疑在将类型从 C++ 转换为 C# 时出错.但究竟在哪里......?

And the error I'm getting is ""Unable to find an entry point named 'recoCHN_P_Name' in DLL 'cnOCRsdk.dll'." I'm suspecting that I'm having an error in converting a type from C++ to C#. But where exactly ... ?

推荐答案

首先确保函数确实被导出:

First make sure the function is actually exported:

在 Visual Studio 命令提示符中,使用 dumpbin/exportswhatever.dll

In the Visual Studio Command Prompt, use dumpbin /exports whatever.dll

这篇关于“无法在 dll 中找到名为 [function] 的入口点"(c++ 到 c# 类型转换)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆