locked
Marshall problem from c++ RRS feed

  • Question

  • Hi Guys,

     

    I have a c++ dll which provides support for the Widcomm bluetooth stack.  Everything works ok, except that the device name is always null.  Here is the c++ structure:

     

    typedef struct _BLUETOOTH_DEVICE_INFO

    {

    DWORD dwSize;

    BLUETOOTH_ADDRESS Address;

    ULONG ulClassofDevice;

    BOOL fConnected;

    BOOL fRemembered;

    BOOL fAuthenticated;

    WCHAR szName[BLUETOOTH_MAX_NAME_SIZE];

    } BLUETOOTH_DEVICE_INFO;

     

    (I do not need the last seen times)

     

    and the C# structure:

     

    [StructLayout(LayoutKind.Sequential)]

    public class BLUETOOTH_DEVICE_INF0

    {

    public int dwSize;

    public long bAddress;

    public int ulClassOfDevice;

    public int fConnected;th

    public int fRemembered;

    public int fAuthenticated;

    [MarshalAs(UnmanagedType.LPWStr)]

    public string szName;

    }

     

    The c++ fills the name with:

    MultiByteToWideChar(CP_ACP, 0, (const char*)bdName, BD_NAME_LEN, btDevInfo.szName, BD_NAME_LEN);

     

    The dll returns an IntPtr to the structure and I read it by:

     

    BLUETOOTH_DEVICE_INF0 info = new BLUETOOTH_DEVICE_INF0();

    IntPtr ptr = GetBTInfo();

    Marshal.PtrToStructure(ptr, info);

     

    All of the fields are filled, except the szName field, which is always null.  Any ideas what I am doing wrong?

     

    Many thanks,

    Millie.

    Tuesday, September 16, 2008 1:28 PM

Answers

  •  

    Hi Millie

    Have a look to this: Marshaling string from C++ DLL   

     

    Regards

    Hammadi  

    Tuesday, September 16, 2008 4:50 PM

All replies

  •  

    Hi Millie

    Have a look to this: Marshaling string from C++ DLL   

     

    Regards

    Hammadi  

    Tuesday, September 16, 2008 4:50 PM
  • Thanks Hammadi!

     

    Millie.

    Thursday, September 18, 2008 1:07 PM