Call delphi DLL method from C # code

I am trying to call a Delphi function from C # ASP.NET code. The function declaration is as follows:

function SomeFunction(const someString, SomeOtherString: string): OleVariant;

From my C # code, I have this code:

[DLLImport(MyDLL.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern object SomeFunction(string someString, string SomeOtherString);

Every time I call this method and save it as an object, I get a P / Invoke error. I have never called unmanaged code from my C # before, so I'm a bit confused.

+5
source share
2 answers

DLL, string, Delphi, , Embarcadero. ( # Delphi, DLL, .)

DLL, PAnsiChar PWideChar. ( #, , PAnsiChar.) , DLL .

DLL, DLL- Delphi ++ Builder, PAnsiChar PWideChar, DLL- Delphi. DLL , , .

+9

Try

[DLLImport(MyDLL.dll, CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Ansi)]
public static extern IntPtr SomeFunction(string someString, string SomeOtherString);

Marshal.GetObjectForNativeVariant .NET.

0

All Articles