简体   繁体   English

C# EntryPointNotFoundException

[英]C# EntryPointNotFoundException

In my C# program, I'm making a call to the AT91Boot_Scan function in sam-ba.dll .在我的 C# 程序中,我正在调用sam-ba.dllAT91Boot_Scan函数。 In the documentation for this DLL, the signature for this function is void AT91Boot_Scan(char *pDevList)在此 DLL 的文档中,此函数的签名为void AT91Boot_Scan(char *pDevList)

Unfortunately, no matter what I try I keep getting EntryPointNotFoundException and ArgumentNullException errors:不幸的是,无论我尝试什么,我都会不断收到EntryPointNotFoundExceptionArgumentNullException错误:

Exception thrown at 0x75E3C54F in MyApp.exe: Microsoft C++ exception: EEMessageException at memory location 0x0038E304.
Exception thrown: 'System.EntryPointNotFoundException' in MyApp.exe
Unable to find an entry point named 'AT91Boot_Scan' in DLL 'sam-ba.dll'.
Exception thrown: 'System.ArgumentNullException' in System.Windows.Forms.dll

My code is as follows, what am I doing wrong?我的代码如下,我做错了什么?

[DllImport("sam-ba.dll")]
unsafe public static extern void AT91Boot_Scan(char* pDevList);

unsafe private string[] LoadDeviceList()
    {
        const int MAX_NUM_DEVICES = 10;
        const int BYTES_PER_DEVICE_NAME = 100;

        string[] deviceNames = new string[MAX_NUM_DEVICES];

        try
        {
            unsafe
            {
                // A pointer to an array of pointers of size MAX_NUM_DEVICES
                byte** deviceList = stackalloc byte*[MAX_NUM_DEVICES];

                for (int n = 0; n < MAX_NUM_DEVICES; n++)
                {
                    // A pointer to a buffer of size 100
                    byte* deviceNameBuffer = stackalloc byte[100];
                    deviceList[n] = deviceNameBuffer;
                }

                // Is casting byte** to char* even legal?
                AT91Boot_Scan((char*)deviceList); 

                // Read back out the names by converting the bytes to strings
                for (int n = 0; n < MAX_NUM_DEVICES; n++)
                {
                    byte[] nameAsBytes = new byte[BYTES_PER_DEVICE_NAME];
                    Marshal.Copy((IntPtr)deviceList[n], nameAsBytes, 0, BYTES_PER_DEVICE_NAME);

                    string nameAsString = System.Text.Encoding.UTF8.GetString(nameAsBytes);
                    deviceNames[n] = nameAsString;
                }
            }
        }
        catch (Exception e)
        {
            Console.WriteLine(e.Message);
        }
        return deviceNames;
    }

Following David Tansey's solution in the comments, the way I should've gone about doing this was adding sam-ba.dll as a COM reference (Solution Explorer > References > Add References > Browse). 在评论中评论了David Tansey的解决方案之后,我应该做的方法是添加sam-ba.dll作为COM参考(解决方案资源管理器>参考>添加参考>浏览)。 Then just instantiating a ISAMBADLL class object and calling the methods through that class. 然后只需实例化一个ISAMBADLL类对象并通过该类调用方法。

如果在 Unity 中运行时控制台窗口中弹出异常,构建并运行项目,它应该可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在C#中使用TaskDialog时的EntryPointNotFoundException - EntryPointNotFoundException when using TaskDialog in C# 用C#编写的本机插件EntryPointNotFoundException - Native Plugin written in C# EntryPointNotFoundException 在C#中绑定C ++ DLL时的EntryPointNotFoundException - EntryPointNotFoundException when binding C++ dll in C# C#调用C ++ dll获取EntryPointNotFoundException - C# call a C++ dll get EntryPointNotFoundException C# WPF 插入记录时出现异常 EntryPointNotFoundException - C# WPF Exception when inserting a record EntryPointNotFoundException 如何在C#项目中调用WIN32 DLL-EntryPointNotFoundException - How to call WIN32 DLL in C# project - EntryPointNotFoundException 尝试将 C/C++ DLL 导入 C# 时出现 DLL EntryPointNotFoundException - DLL EntryPointNotFoundException when trying to import C/C++ DLL into C# 从C#调用C ++代码时出现System.EntryPointNotFoundException - System.EntryPointNotFoundException when calling C++ code from C# C#EntryPointNotFoundException无法在DLL&#39;kernel32.dll&#39;中找到名为&#39;SetDllDirectory&#39;的入口点 - C# EntryPointNotFoundException Unable to find an entry point named 'SetDllDirectory' in DLL 'kernel32.dll' 尝试从C#调用非托管函数时出现&#39;System.EntryPointNotFoundException&#39; - 'System.EntryPointNotFoundException' when trying to call unmanaged function from C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM