I need to get a RECT from COM to C# in 64 bits, so I defined a simple method in IDL as:
[id(23), helpstring("method GetRect")] HRESULT GetRect([out,retval] RECT* pRect);
and implemented in C++ as
STDMETHODIMP CSpot::GetRect(RECT* pRect)
{
CRect rec = get_position();
*pRect = rec;
return S_OK;
}
I called in C# as:
tagRECT rec = pSpot.GetRect();
Most time is OK, but sometimes I get 0xC0000005: Access violation writing location 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:
[StructLayout(LayoutKind.Sequential, Pack = 0)]
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.