将指针从c#传递到c++;以意外的结果结束 我试图把一个指针从C→传递到C++,这在C++中总是意外的结果,即使当我从C ^中发送空指针时,也总是收到相同的地址。
一些细节 注意:这是另一类问题。 c++: c部分: 以及实际工作的代码:将指针从c#传递到c++;以意外的结果结束 我试图把一个指针从C→传递到C++,这在C++中总是意外的结果,即使当我从C ^中发送空指针时,也总是收到相同的地址。,c#,c++,.net,com-interop,C#,C++,.net,Com Interop,一些细节 注意:这是另一类问题。 c++: c部分: 以及实际工作的代码: int structSize = Marshal.SizeOf(cc708Config); IntPtr structPtr = Marshal.AllocHGlobal(structSize); Marshal.StructureToPtr(cc708Config, structPtr, false); if (0 != (hr = CC708DecoderConfig.Set
int structSize = Marshal.SizeOf(cc708Config);
IntPtr structPtr = Marshal.AllocHGlobal(structSize);
Marshal.StructureToPtr(cc708Config, structPtr, false);
if (0 != (hr = CC708DecoderConfig.SetConfig(/*structPtr*/IntPtr.Zero)))
{
throw new ApplicationException("Couldn't SetConfig() because: " + DirectShowLib.DsError.GetErrorText(hr));
}
正如你所看到的,我甚至尝试发送ItpTr.0,它结尾的地址在C++部分:0x0BB0058. 我猜DS寄存器有问题,但不确定
< P> <强>编辑:每当我进入StCub(MichaelGraczyk)的C++部分时,我就可以看到“这个”地址是0x00 03,它怎么可能?< /强> < /> >你可以尝试改变<代码> C CONTIGIG/<代码>的C *定义,以获得<代码> Value*/Cuff>,看看是否通过<代码>(空隙*)0 < /COD>给你相同的结果?@:这也没用,仍在接收相同的指针:0x0acc0058
[StructLayout(LayoutKind.Sequential, Pack = 4)]
public unsafe struct CEA708CONFIG
{
public byte is608Service;
public byte isCompactStream;
public fixed byte activeServices[63];
public int activeServiceCount;
public Point alignmentPosition;
};
[ComVisible(true), ComImport, Guid("F1FAC4B6-5DAA-4875-B76B-8C10A0C0B22E"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ICEA708Decoder
{
[PreserveSig]
int SetConfig([In] IntPtr config);
[PreserveSig]
int GetConfig([Out] out CEA708CONFIG config);
}
int structSize = Marshal.SizeOf(cc708Config);
IntPtr structPtr = Marshal.AllocHGlobal(structSize);
Marshal.StructureToPtr(cc708Config, structPtr, false);
if (0 != (hr = CC708DecoderConfig.SetConfig(/*structPtr*/IntPtr.Zero)))
{
throw new ApplicationException("Couldn't SetConfig() because: " + DirectShowLib.DsError.GetErrorText(hr));
}