.net 为什么我的COM方法返回的值不正确?
我有一个COM方法,它返回一个MFC.net 为什么我的COM方法返回的值不正确?,.net,com,mfc,.net,Com,Mfc,我有一个COM方法,它返回一个MFCcorrect: GetMFCRect(LONG* pRect) *((CRect*)pRect) = m_currentRect; 在.NET应用程序中,我尝试以下操作: int pointer = new int(); Rectangle rc; IntPtr pIntResult; unsafe { int* p = &pointer; _COMobj.GetMFCRect(ref *p); pIntResult = n
correct
:
GetMFCRect(LONG* pRect)
*((CRect*)pRect) = m_currentRect;
在.NET应用程序中,我尝试以下操作:
int pointer = new int();
Rectangle rc;
IntPtr pIntResult;
unsafe
{
int* p = &pointer;
_COMobj.GetMFCRect(ref *p);
pIntResult = new IntPtr(p);
rc = (Rectangle)Marshal.PtrToStructure(pintResult, typeof(Rectangle));
}
但是rc
具有错误的值。这个代码有什么问题
谢谢 AFAIK,结构简单,无铸造或变形;在m_currentRect的VTable中,您所看到的值很可能是指针。作为一种可能的解决方案,我将传递一个GDI RECT结构,这更安全,或者直接传递四个坐标