簡體   English   中英

如何在COM中傳遞RECT

[英]How to pass RECT in COM

我需要從64位獲得從COM到C#的RECT,所以我在IDL中定義了一個簡單的方法:

[id(23), helpstring("method GetRect")] HRESULT GetRect([out,retval] RECT* pRect);

並在C ++中實現

STDMETHODIMP CSpot::GetRect(RECT* pRect)
{
CRect rec = get_position(); 
*pRect = rec;
return S_OK;
}

我打電話給C#:

tagRECT rec = pSpot.GetRect();

大部分時間都可以,但有時我得到0xC0000005:訪問沖突寫入位置0x0000000000000000。

排隊:

*pRect = rec;

什么可能導致這個例外?

不確定這是否是你的問題,但是當從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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM