0
votes

i was wondering how to marshall string types to BSTR* types. just to elaborate, the C++ structure is as follows:

struct MyStruct
{
     BSTR* string;
     int a;
}

i need to define a new sturct in C# side, i tried both string[] and IntPtr[] but that didn't come up with a success.

Thanks for your help!

edit: c++ structure:

    struct HTTPTEXTRENDERERFILTERINFO {
        enum { UTC, GMT } eTimestamp;
        BOOL    bEnableCCIngest;
        LONG    lQueueSizeTreshold; 
        LONG    lSendTimeTreshold;  
        BYTE    btBroadcastUrlCount;
        BSTR*   pbstrBroadcastUrls;                                
        LONG    lInputPinsNum;      
    };

and the function's prototype:

HRESULT HTTPTextRendererFilter::SetConfig(IN const HTTPTEXTRENDERERFILTERINFO& Config)

c# structure:

[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;     
};

prototype:

    [PreserveSig]
    int SetConfig([In] ref HttpTextRenderFilterInfo config);
1

1 Answers

1
votes

Try this:

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]
struct MyStruct
{
   [MarshalAs(UnmanagedType.BStr)] public String myString;
   public int a;
}