我想知道如何将字符串类型编组为BSTR *类型。 简单来说,C ++结构如下:
struct MyStruct
{
BSTR* string;
int a;
}
我需要在C#端定义一个新的sturct,我尝试了string []和IntPtr []但是没有取得成功。
感谢您的帮助!
编辑: c ++结构:
struct HTTPTEXTRENDERERFILTERINFO {
enum { UTC, GMT } eTimestamp;
BOOL bEnableCCIngest;
LONG lQueueSizeTreshold;
LONG lSendTimeTreshold;
BYTE btBroadcastUrlCount;
BSTR* pbstrBroadcastUrls;
LONG lInputPinsNum;
};
和函数的原型:
HRESULT HTTPTextRendererFilter::SetConfig(IN const HTTPTEXTRENDERERFILTERINFO& Config)
c#结构:
[StructLayout(LayoutKind.Sequential,CharSet = CharSet.Unicode)] public struct HttpTextRenderFilterInfo { public enum TimestampType:int {UTC,GMT};
public TimestampType Timestamp; public int EnableCCIngest; public int QueueSizeTreshold; public int SendTimeTreshold; public byte BroadcastUrlCount; [MarshalAs(UnmanagedType.BStr)] public string pbstrBroadcastUrls; public int lInputPinsNum; };
原型:
[PreserveSig]
int SetConfig([In] ref HttpTextRenderFilterInfo config);
答案 0 :(得分:1)
试试这个:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct MyStruct
{
[MarshalAs(UnmanagedType.BStr)] public String myString;
public int a;
}