c#からc ++にポインターを渡そうとすると、c#からNULLポインターを送信した場合でも、常に同じアドレスを受け取ると、c++側で予期しない結果が発生します。
いくつかの詳細。
注:これは別の種類の質問です。
c ++:
#pragma pack(push, 4)
struct CEA708CONFIG
{
BYTE b608Service;
BYTE bCompactStream;
BYTE pActiveServices[63];
LONG lActiveServiceCount; //
POINT ptAlignmentPosition; /
};
#pragma pack(pop)
interface
__declspec(uuid("{F1FAC4B6-5DAA-4875-B76B-8C10A0C0B22E}"))
ICEA708Decoder : IUnknown {
virtual HRESULT SetConfig(IN const CEA708CONFIG* pConfig) = 0;
virtual HRESULT GetConfig(OUT CEA708CONFIG* pConfig) = 0;
};
とc#の部分:
[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));
}
ご覧のとおり、私はIntPtr.Zeroを送信しようとしましたが、これはc++部分の次のアドレスで終了しました:0x0bb00058。
私の推測では、DSレジスタに何か問題があると思いますが、確かではありません。
編集:SetConfig()のc ++部分にステップインするたびに、「この」アドレスが0x0003であることがわかりますが、どうすれば可能ですか?