C# 将字符串作为PChar从CSharp传递到Delphi DLL
我正在尝试将字符串从C#传递到Delphi构建的DLL。 delphidll需要PChar 这是德尔福出口C# 将字符串作为PChar从CSharp传递到Delphi DLL,c#,delphi,dll,import,C#,Delphi,Dll,Import,我正在尝试将字符串从C#传递到Delphi构建的DLL。 delphidll需要PChar 这是德尔福出口 procedure DLL_Message(Location:PChar;AIntValue :integer);stdcall; external 'DLLTest.dll'; C#导入(我上次尝试的是string,char*ref string…) 我以任何方式获取访问值 是否有任何解决方案可以在C#中将字符串值作为PChar传递?尝试使用MarshalAs属性,该属性允许您控制所使
procedure DLL_Message(Location:PChar;AIntValue :integer);stdcall;
external 'DLLTest.dll';
C#导入(我上次尝试的是string,char*ref string…)
我以任何方式获取访问值
是否有任何解决方案可以在C#中将字符串值作为PChar传递?尝试使用MarshalAs属性,该属性允许您控制所使用的本机类型 可以在MSDN中找到类型列表:
这里不需要。这是默认封送处理。对于DllImport属性的参数也是如此。只需要文件名。你确定吗?默认值不是UnmanagedType.LPWStr(UTF-16)吗?我已经再次阅读了文档,仍然得出结论,默认值是BStr。它在哪里说默认值是LPStr?它没有。但是如果您不使用marshallas指定,那么您将获得LPTStr
[DllImport(
"DLLTest.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi,
EntryPoint = "DLL_Message"
)]
public static extern void DLL_Message(IntPtr Location, int AIntValue);
DllImport(
"DLLTest.dll",
CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Ansi,
EntryPoint = "DLL_Message"
)]
public static extern void DLL_Message(
[MarshalAs(UnmanagedType.LPStr)] string Location,
int AIntValue
);