I have read through maybe 100+ posts on this over 2 weeks and have got myself totally confused. This is for a wrapper i'm writing over the BlueSoleil stack.
In c++
typedef char BTINT8;
typedef unsigned char BTUINT8;
typedef unsigned char BTUCHAR; /* extended ASII character, 0 - 255 */
typedef unsigned char BTBOOL;
typedef short BTINT16;
typedef unsigned short BTUINT16;
typedef long BTINT32;
typedef unsigned long BTUINT32;
typedef void * BTLPVOID;
typedef BTUINT32 BTDEVHDL;
typedef BTUINT32 BTSVCHDL;
typedef BTUINT32 BTCONNHDL;
typedef BTUINT32 BTSHCHDL;
typedef BTUINT32 BTSDKHANDLE;
typedef struct _BlueToothDevice
{
BTDEVHDL rmt_device_handle;
BTINT32 rmt_device_num;
BTUINT32 rmt_device_class;
BTUINT8 rmt_device_name[64];
} BLUETOOTHDEVICE;
typedef struct _BlueToothDevices
{
BTUINT32 num_rmt_devices;
BLUETOOTHDEVICE rmt_btd[100];
} BLUETOOTHDEVICES;
public ref class RemoteDeviceDiscovery
{
public:
int GetBTD(BLUETOOTHDEVICE btd);
};
In C#
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BluetoothDevice
{
[MarshalAs(UnmanagedType.SysUInt)]
public UInt32 rmt_device_handle;
[MarshalAs(UnmanagedType.SysInt)]
public Int32 rmt_device_num;
[MarshalAs(UnmanagedType.SysUInt)]
public UInt32 rmt_device_class;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 248)]
public IntPtr rmt_device_name;
}
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct BluetoothDevices
{
[MarshalAs(UnmanagedType.SysUInt)]
public UInt32 num_rmt_devices;
[MarshalAs(UnmanagedType.ByValArray)]
public List<BluetoothDevice> BluetoothDeviceInfo;
}
static void Main()
{
var rd = new RemoteDeviceDiscovery();
BluetoothDevice bluetoothDevice = new BluetoothDevice();
var i = rd.GetBTD(ref bluetoothDevice);
}
Error 3 Argument 1: cannot convert from 'ConsoleWrapperTest.Program.BluetoothDevice' to 'BlueSoleilWrapper._BlueToothDevice'
So can someone point out where I have gone wrong please.
Jim
UPDATE
Have the c++/cli wrapper compiling with the following header code
public ref class RemoteDeviceDiscovery
{
/* Remote Device Discovery */
public:
int^ GetBTD(_BlueToothDevices % btds);
};
and cpp code
array<Byte>^ MakeManagedArray(unsigned char* input, int len)
{
array<Byte>^ result = gcnew array<Byte>(len);
for (int i = 0; i < len; i++)
{
result[i] = input[i];
}
return result;
}
int^ RemoteDeviceDiscovery::GetBTD(_BlueToothDevices % btds)
{
unsigned char name[] = "Test";
_BlueToothDevice entry;
btds.num_rmt_devices = 1;
entry.rmt_device_class = 1;
entry.rmt_device_handle = 2;
entry.rmt_device_num = 3;
entry.rmt_device_name = MakeManagedArray(name, sizeof(name));
btds.rmt_btd[0] = gcnew _BlueToothDevice();
btds.rmt_btd[0] = %entry;
return 99;
}
Problem is now in the C# code
var rd = new RemoteDeviceDiscovery();
_BlueToothDevices bluetoothDevices = new _BlueToothDevices();
var i = rd.GetBTD(bluetoothDevices);
var rmt_device_handle = bluetoothDevices.rmt_btd[0].rmt_device_handle;
When compiling I get 'GetBTD' is not supported by the language and everything I have seen so far as solutions hasn't worked. Appreciate any further assistance.
Jim