Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 4.0 C++中的C代码等效代码_C# 4.0_Memory Management_Bluetooth Lowenergy - Fatal编程技术网

C# 4.0 C++中的C代码等效代码

C# 4.0 C++中的C代码等效代码,c#-4.0,memory-management,bluetooth-lowenergy,C# 4.0,Memory Management,Bluetooth Lowenergy,我是C语言的新手,所以对你们中的许多人来说可能很简单,但我需要帮助。 我必须用c语言创建一个桌面应用程序,该应用程序连接到蓝牙低能耗设备,并使用将值发送到该设备。为此,我需要使用 我有C++代码来做这个:< /P> USHORT charBufferSize = 0; HRESULT hres = BluetoothGATTGetCharacteristics( BLE_Service,NULL, 0,NULL,

我是C语言的新手,所以对你们中的许多人来说可能很简单,但我需要帮助。 我必须用c语言创建一个桌面应用程序,该应用程序连接到蓝牙低能耗设备,并使用将值发送到该设备。为此,我需要使用

<>我有C++代码来做这个:< /P>
USHORT charBufferSize  = 0;
HRESULT hres = BluetoothGATTGetCharacteristics( BLE_Service,NULL, 0,NULL,
                                                 &charBufferSize,BLUETOOTH_GATT_FLAG_NONE);

 if(hres==HRESULT_FROM_WIN32(ERROR_MORE_DATA)) 
   {
      Characteristic_Buffer = new BTH_LE_GATT_CHARACTERISTIC [charBufferSize ];                                                       
   }                                                       
USHORT val = 0;
// get characteristics after allocating required size 
hres = BluetoothGATTGetCharacteristics(BLE_Service,NULL,charBufferSize,
                                 Characteristic_Buffer,&val,BLUETOOTH_GATT_FLAG_NONE);
我必须用C做同样的事情 所以我试过这样的方法

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct BTH_LE_GATT_CHARACTERISTIC
    {
        public UInt16 ServiceHandle;
        public BTH_LE_UUID CharacteristicUuid;
        public UInt16 AttributeHandle;
        public UInt16 CharacteristicValueHandle;
        public Boolean IsBroadcastable;
        public Boolean IsReadable;
        public Boolean IsWritable;
        public Boolean IsWritableWithoutResponse;
        public Boolean IsSignedWritable;
        public Boolean IsNotifiable;
        public Boolean IsIndicatable;
        public Boolean HasExtendedProperties;
    } 

[DllImport(@"BluetoothApis.dll", SetLastError = true, CharSet = CharSet.Auto)]

public static extern Boolean BluetoothGATTGetCharacteristics(
                                                         IntPtr Device_Handle,
                                                         IntPtr Service,
                                                         UInt16 Char_Buffer_Count,
                                     ref BTH_LE_GATT_CHARACTERISTIC CharBuffer,
                                                         out UInt16 RequiredSize,
                                                         uint Flags
                                                         );
UInt16 Size_Required = 0;
UInt16 NBytes = 0;
BTH_LE_GATT_CHARACTERISTIC gattChar = new BTH_LE_GATT_CHARACTERISTIC();


Success = BluetoothGATTGetCharacteristics(Ble_Device, IntPtr.Zero, 0, IntPtr.Zero, 
                  out Size_Required, (uint)BTH_LE_FLAGS.BLUETOOTH_GATT_FLAG_NONE);
我被困在这里了。现在,为了对函数进行第二次调用,我应该像在C中那样为特征缓冲区分配内存++

有没有关于如何做到这一点的建议,或者有没有其他方法来获取C中的特征缓冲区

提前谢谢