简体   繁体   English

在C#中使用Delphi本机dll(DllImport问题)

[英]Using a Delphi native dll in C# (DllImport issue)

I'm having issues importing a Delphi native dll to .net. 我在将Delphi本机dll导入.net时遇到问题。 I'm getting System.EntryPointNotFoundException . 我收到System.EntryPointNotFoundException

Here's my delphi dll: 这是我的delphi dll:

procedure ProcedimientoEncriptar(texto,clave,resultado:PChar); export stdcall;
    var ...
    begin
    ....
    ....
    end;

    exports
      ProcedimientoEncriptar ;

And here's my DllImport on .Net (C#) code: 这是我在.Net(C#)代码上的DllImport:

[DllImport("CryptoDLL.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Auto)]
        public static extern void ProcedimientoEncriptar([MarshalAs(UnmanagedType.LPStr)]string texto, [MarshalAs(UnmanagedType.LPStr)]string clave, [MarshalAs(UnmanagedType.LPStr)] StringBuilder resultado);

Any help would be appreciated, Diego. 迭戈,任何帮助将不胜感激。

The only explanation for System.EntryPointNotFoundException is that the DLL that the C# code is finding is not the DLL produced from the Delphi code that you show. System.EntryPointNotFoundException的唯一解释是C#代码找到的DLL不是从您显示的Delphi代码生成的DLL。 So, perhaps the C# code is picking up an out of date version of the DLL. 所以,也许C#代码正在挑选DLL的过时版本。 Or perhaps it's picking up a completely different DLL. 或许它正在挑选一个完全不同的DLL。

For example, my system has a DLL named cryptdll.dll in the system32 directory. 例如,我的系统在system32目录中有一个名为cryptdll.dll的DLL。 Most likely that's the DLL that your C# code is finding. 很可能是你的C#代码找到的DLL。

In order to make sure that the right DLL is found, you need to place a copy of the Delphi DLL in the same directory as the C# executable file. 为了确保找到正确的DLL,您需要将Delphi DLL的副本放在与C#可执行文件相同的目录中。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM