我有一个用Delphi(未知版本)编写的第三方"神秘dll",在delphi(2009年)中的工作示例,急需在我的C#代码中使用所述dll,并且几乎没有关于如何执行它的相关知识.
以下是使用此dll的Delpi示例:
type
TD_Query = function(host: WideString; port : Word;pud,query : WideString):WideString; stdcall;
procedure TForm11.Button6Click(Sender: TObject);
var
Handle : LongWord;
D_Query : TD_Query;
sss : WideString;
begin
Handle := LoadLibrary('kobrasdk.dll');
sss:='';
if Handle <> 0 then
begin
@D_Query := GetProcAddress(Handle, 'D_Query');
sss:=D_Query('host',8201,'pud','query');
FreeLibrary(Handle);
end;
end;
Run Code Online (Sandbox Code Playgroud)
这是我尝试用C#解释它:
class Program
{
[DllImport("C:\\Games\\kobrasdk.dll", CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi)]
[return: MarshalAs(UnmanagedType.LPStr)]
public static extern string D_Query(string host, ushort port, string pud, string query);
static void Main(string[] args)
{
D_Query("test", 8201, "test", "test");
} …Run Code Online (Sandbox Code Playgroud)