1

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.

4
  • 1
    That's not your actual code I think. A Delphi function is meant to have a return value. But yours doesn't. And your C# code has void return. Is your Delphi code really function? Isn't it procedure. Your Delphi code in the question doesn't compile. Please use copy/paste when putting code in questions. Don't post fake code. Commented Sep 27, 2012 at 14:05
  • You're right, it was procedure but i changed it for testing purposes (i tried returning a PChar). Commented Sep 27, 2012 at 15:35
  • 1
    What Delphi version? Is PChar Unicode or not? Commented Sep 27, 2012 at 17:09
  • I'm not sure, I'm pretty new to Delphi but I'm using Embarcadero's Solution (Borland Developer Studio 2006)... Commented Sep 27, 2012 at 20:37

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, David, that was the issue. I didn't know that a 'cryptdll.dll' existed on the system. I renamed and copied the dll to the /bin/ directory and it worked (it's an ASP .Net application). Cheers, Diego.
@Diego Iturriaga: David is right. In windows, the location of a D.L.L. can be a problem, and is not related to been Delphi generated, in this case, the same error can happen to a D.L.L. compiled in other language, and wrong filesystem location.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.