当前位置: 动力学知识库 > 问答 > 编程问答 >

Calling Delphi DLL from c# to return text

问题描述:

Dears.

I have simple Delphi DLL like this

function GetConnection: PChar; stdcall; export;

begin

Result:= 'connection name is ....';

end;

exports

GetConnection;

and I am trying from C# as the folowing>

using System.Runtime.InteropServices;

namespace ConsoleApplication2

{

class Program

{

[DllImport("C:/Program Files (x86)/Borland/Delphi7/Projects/Project2.dll",

CallingConvention = CallingConvention.StdCall,

CharSet = CharSet.Unicode)]

public static extern string

GetConnection();

static void Main(string[] args)

{

string theresult = "";

theresult = GetConnection();

Console.Write(theresult);

Console.Write(" Press Enter plese:");

Console.ReadLine();

}

}

}

but I received error (ConsoleApplication2.vshost.exe' has exited with code 1073741855 (0x4000001f))

thanks in advance

分享给朋友:
您可能感兴趣的文章:
随机阅读: