How to pass RECT to COM

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 # like:

 tagRECT rec = pSpot.GetRect(); 

Most of the time is fine, but sometimes I get 0xC0000005: the location of the access violation record is 0x0000000000000000.

in line:

 *pRect = rec; 

What can cause this exception?

+4
source share
1 answer

Not sure if this is your problem, but when using the RECT methods from COM, I need to β€œdefine” the RECT object as follows:

 [StructLayout(LayoutKind.Sequential, Pack = 0)] public struct RECT { public int left; public int top; public int right; public int bottom; } 
0
source

Source: https://habr.com/ru/post/1480609/


All Articles