この関数を正しくP /呼び出しするにはどうすればよいですか?この関数を正しくP /呼び出しするには?
const char * GetReplyTo(const char * pszInText, char * pszOutText, int len)
私はこのようにそれを実行しようとしましたし、アクセス違反の例外を持っている:
[DllImport("SmartBot.dll", EntryPoint = "GetReplyTo")]
public static extern IntPtr GetReplyTo([In] [MarshalAs(UnmanagedType.LPStr)] string pszInText, IntPtr pszOutText, int len);
// somewhere below:
IntPtr pbuf = GCHandle.Alloc(new byte[1000], GCHandleType.Pinned).AddrOfPinnedObject();
GetReplyTo("hi", pbuf, 2);
UPDATEはここ は、このファイルのパスカルヘッダーです:
{***************************************************************************
* SmartBot Engine - Boltun source code,
* SmartBot Engine Dynamic Link Library
*
* Copyright (c) 2003 ProVirus,
* Created Alexander Kiselev Voronezh, Russia
***************************************************************************
SmartBot.pas : Header Pascal for SmartBot Engine.
}
unit SmartBot;
interface
{
function GetReplyTo(const InText: PChar; OutText: PChar; Len: integer): PChar;stdcall;export;
function LoadMind(MindFile: PChar): integer;stdcall;export;
function SaveMind(MindFile: PChar): integer;stdcall;export;
}
function GetReplyTo(const InText: PChar; OutText: PChar; Len: integer): PChar;stdcall;external 'smartbot.dll' name 'GetReplyTo';
function LoadMind(MindFile: PChar): integer;stdcall;external 'smartbot.dll' name 'LoadMind';
function SaveMind(MindFile: PChar): integer;stdcall;external 'smartbot.dll' name 'SaveMind';
implementation
end.
UPDATE 2それは動作します。私は初期化関数を使いこなすように見えます。成功すると1を返し、失敗した場合は0を返します。奇妙な。
ご質問には情報が不十分です。特に、戻り値が指すデータの所有権について何も述べていません。 – CodesInChaos
どちらか分かりません。私はちょうどdllをインポートしようとすると、デバッガを使用して正しく使用するfugure方法 – Poma
戻り値は 'アウト'値と同じですか? – leppie