[英]How to pass RECT in COM
I need to get a RECT from COM to C# in 64 bits, so I defined a simple method in IDL as: 我需要从64位获得从COM到C#的RECT,所以我在IDL中定义了一个简单的方法:
[id(23), helpstring("method GetRect")] HRESULT GetRect([out,retval] RECT* pRect);
and implemented in C++ as 并在C ++中实现
STDMETHODIMP CSpot::GetRect(RECT* pRect)
{
CRect rec = get_position();
*pRect = rec;
return S_OK;
}
I called in C# as: 我打电话给C#:
tagRECT rec = pSpot.GetRect();
Most time is OK, but sometimes I get 0xC0000005: Access violation writing location 0x0000000000000000. 大部分时间都可以,但有时我得到0xC0000005:访问冲突写入位置0x0000000000000000。
in line: 排队:
*pRect = rec;
What could cause this exception? 什么可能导致这个例外?
Not sure if this is your problem, but when using RECT from COM methods, I need to 'define' the RECT object as following: 不确定这是否是你的问题,但是当从COM方法使用RECT时,我需要“定义”RECT对象,如下所示:
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.