I tried to call a dll that is coded in delphi in C#. (delphi 11 64bit) I believe there will be some problems. Therefore, I tried some example in these website: Calling a Delphi method in a dll from c# Calling a Delphi DLL from a C# .NET application
But there is no response, and the applicaiton closes.
These are my codes:
example 1
delphi
function DBConnect1(inputStr,connStr:PWideChar):PWideChar;stdcall;
begin
try
result:=PWideChar('Hello from Delphi!');
except
result:=PWideChar('Exception');
end;
end;
C#
[DllImport("Project1.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static extern string DBConnect1(string inputString, string connectionString);
string inputString = "Parker";
string connectionString = "MyComputer";
string dbStrObj1 = DBConnect1(inputString, connectionString);
MessageBox.Show(dbStrObj1);
example 2
delphi
function Test1(sFD,sVD,sINI,sCh,sSD: string): PWideChar;stdcall;
var
tempStr:string;
str:WideString;
begin
tempStr:=sFD+sVD+sINI+sCh+sSD;
try
result:= PWideChar(tempStr);
except
str:='Error';
result:=PWideChar(str);
end;
result:=PWideChar(str);
end;
C#
[DllImport("Project1.dll", EntryPoint = "LoginLic", CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
[return: MarshalAs(UnmanagedType.LPWStr)]
public static extern string LoginLic(string s1, string s2, string s3, string s4, string s5);
string strId = "PCMS";
string strVersion = "AD19";
string strIni = @"";
string strCheck = "0";
string strSubDate = null;
string aa;
aa = UseDll.LoginLic(strId, strVersion, strIni, strCheck, strSubDate);