我在C#上添加了一个COM对象,并且正在c++ dll中使用它。
在c++中,COM对象与#import
derective一起导入
问题是,当从C++ dll调用COM对象的任何函数时,我收到运行时检查错误:
在由c++ import指令生成的com对象包装中,所有函数都声明为__stdcall
最佳答案
好的,看来我已经找到了解决方案:
我已经为C#COM接口(interface)中的所有方法确定了In / Out / MarshalAs属性:
[Guid("EEB4C1AE-4DB2-4bdb-86D4-A429B27496A3")]
public interface IAXFarCards
{
[DispId(1)]
void InitDbConnection([In, MarshalAs(UnmanagedType.BStr)] string connectionString);
[DispId(2)]
[return: MarshalAs(UnmanagedType.I4)]
int GetCardInfo(
[In, MarshalAs(UnmanagedType.BStr)] string card,
[In, MarshalAs(UnmanagedType.VariantBool)] bool isTemplate,
[In, MarshalAs(UnmanagedType.I4)] int cashDeskId,
[Out, MarshalAs(UnmanagedType.VariantBool)] out bool isActive,
[Out, MarshalAs(UnmanagedType.I4)] out int discountNumber,
[Out, MarshalAs(UnmanagedType.I8)] out Int64 amount,
[In, Out, MarshalAs(UnmanagedType.BStr)] ref string ownerName,
[In, Out, MarshalAs(UnmanagedType.I4)] ref int clientId
);