简体   繁体   中英

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

I'm having issues importing a Delphi native dll to .net. I'm getting System.EntryPointNotFoundException .

Here's my delphi dll:

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

    exports
      ProcedimientoEncriptar ;

And here's my DllImport on .Net (C#) code:

[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. So, perhaps the C# code is picking up an out of date version of the DLL. Or perhaps it's picking up a completely different DLL.

For example, my system has a DLL named cryptdll.dll in the system32 directory. Most likely that's the DLL that your C# code is finding.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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