powered by simpleCommunicator - 2.0.53     © 2025 Programmizd 02
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Портирование метода.
4 сообщений из 4, страница 1 из 1
Портирование метода.
    #39073788
jenya7
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
оригинал в С++ такой
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
HRESULT WINAPI BluetoothGATTGetServices(
  _In_      HANDLE               hDevice,
  _In_      USHORT               ServicesBufferCount,
  _Out_opt_ PBTH_LE_GATT_SERVICE ServicesBuffer,
  _Out_     USHORT               *ServicesBufferActual,
  _In_      ULONG                Flags
);

typedef struct _BTH_LE_GATT_SERVICE {
  BTH_LE_UUID ServiceUuid;
  USHORT      AttributeHandle;
} BTH_LE_GATT_SERVICE, *PBTH_LE_GATT_SERVICE;

typedef struct _BTH_LE_UUID {
  BOOLEAN IsShortUuid;
  USHORT  ShortUuid;
  GUID    LongUuid;
} BTH_LE_UUID, *PBTH_LE_UUID;



в С# получилось так
Код: c#
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
[StructLayout(LayoutKind.Sequential)]
        struct BTH_LE_UUID
        {
            public Boolean IsShortUuid;
            public ushort ShortUuid;
            public Guid LongUuid;
        };

        [StructLayout(LayoutKind.Sequential)]
        struct BTH_LE_GATT_SERVICE
        {
            public BTH_LE_UUID ServiceUuid;
            public ushort AttributeHandle;
        };


[DllImport("BluetoothApis.dll", PreserveSig = false)]
        static extern long BluetoothGATTGetServices(
            IntPtr hDevice,
            ushort ServicesBufferCount,
            out BTH_LE_GATT_SERVICE ServicesBuffer,
            ref ushort ServicesBufferActual,
            ulong Flags
        );


при вызове
Код: c#
1.
2.
3.
BTH_LE_GATT_SERVICE le_gatt_service = new BTH_LE_GATT_SERVICE();

long result = BluetoothGATTGetServices(hLEDevice, 0, out le_gatt_service, ref serviceBufferCount, BLUETOOTH_GATT_FLAG_NONE);



получаю ошибку.
Код: sql
1.
A call to PInvoke function 'BLE_Sniffer!BLE_Sniffer.BLE::BluetoothGATTGetServices' has unbalanced the stack. This is likely because the managed PInvoke signature does not match the unmanaged target signature. Check that the calling convention and parameters of the PInvoke signature match the target unmanaged signature.


в чем я ошибся?
...
Рейтинг: 0 / 0
Портирование метода.
    #39074688
felix_ff
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
jenya7,

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
[DllImport("BluetoothApis.dll", PreserveSig = false, CallingConvention = CallingConvention.Cdecl)]
        static extern long BluetoothGATTGetServices(
            IntPtr hDevice,
            ushort ServicesBufferCount,
            out BTH_LE_GATT_SERVICE ServicesBuffer,
            ref ushort ServicesBufferActual,
            ulong Flags
        );



в таком варианте пашет?
...
Рейтинг: 0 / 0
Портирование метода.
    #39075127
jenya7
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
felix_ffjenya7,

Код: sql
1.
2.
3.
4.
5.
6.
7.
8.
[DllImport("BluetoothApis.dll", PreserveSig = false, CallingConvention = CallingConvention.Cdecl)]
        static extern long BluetoothGATTGetServices(
            IntPtr hDevice,
            ushort ServicesBufferCount,
            out BTH_LE_GATT_SERVICE ServicesBuffer,
            ref ushort ServicesBufferActual,
            ulong Flags
        );



в таком варианте пашет?
нет. та же проблема.
...
Рейтинг: 0 / 0
Портирование метода.
    #39075134
jenya7
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Гость
я думаю, что пока не известен размер буфера serviceBufferCount нельзя передавать структуру в качестве аргумента.
в С++ вместо структуры le_gatt_service можно передать NULL а в шарпе как?
...
Рейтинг: 0 / 0
4 сообщений из 4, страница 1 из 1
Форумы / WinForms, .Net Framework [игнор отключен] [закрыт для гостей] / Портирование метода.
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]