Ir al contenido


Foto

Crear una función que llame a una función de una DLL.


  • Por favor identifícate para responder
16 respuestas en este tema

#1 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 17 junio 2011 - 08:42

Hola querido foro, no se si sabrán que estoy con esto del bluetooth ahora, cuando llegue a mi casa o cuando pueda (normalmente entre las 12:00 am y 7:00 am) voy a intentar usar una dll llamada btconf.dll, no hice esto nunca, ni con delphi y mucho menos con lazarus (ya que soy muy novato en este  :embarrassed:). Si alguien me puede pasar un tuto o darme una mano, toda ayuda o comentario seria bienvenida.

Desde ya muchas gracias.




  • 0

#2 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 17 junio 2011 - 08:45

A ver, amigo Martín (Ese es tu nombre?), lo que necesitas es llamar una función contenida en una .DLL?
  • 0

#3 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 17 junio 2011 - 09:45

Si ese es mi nombre, y lo que necesito es precisamente eso, quiero saber que hay hacer, bien llegue a mi casa, me pongo a ver que debo hacer.

  • 0

#4 enecumene

enecumene

    Webmaster

  • Administrador
  • 7.419 mensajes
  • LocationRepública Dominicana

Escrito 17 junio 2011 - 10:56

Pues suponiendo que tienes la lista de las funciones de esa DLL, puedes hacer lo siguiente, en Delphi sería colocarlo antes del implementation, no sé cómo sería en Lazarus:



delphi
  1. procedure HolaMundo; external 'archivoDLL.dll'



Así llamas la función contenida dentro de una DLL, claro, con previo conocimiento de su estructura.

Saludos.
  • 0

#5 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 17 junio 2011 - 08:31

Eh logrado usar una funcion de la dll.
Eh creado un proyecto nuevo con un boton y un checkbock, lo guarde en una carpeta y en esa carpeta tiro el archivo btfunc.dll

El código del proyecto es el siguiente:



delphi
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     CheckBox1: TCheckBox;
  17.     procedure Button1Click(Sender: TObject);
  18.   private
  19.     { private declarations }
  20.   public
  21.     function BT_InitializeLibrary() : Boolean; stdcall;
  22.   end;
  23.  
  24. var
  25.   Form1: TForm1;
  26.  
  27. implementation
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.Button1Click(Sender: TObject);
  32. begin
  33.   CheckBox1.Checked:= BT_InitializeLibrary();
  34. end;
  35.  
  36.  
  37. //external 'btfunc.dll' name 'BT_InitializeLibrary';
  38. function TForm1.BT_InitializeLibrary() : Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary';
  39.  
  40. {$R *.lfm}
  41.  
  42. end.
  43.    




Es cuestion de ir viendo que hace las distintas funciones del la dll que está documentada en http://read.pudn.com...uetooth API.doc

Bueno, voy a ir posteando acá mi avances, hoy no me puedo quedar hasta muy tarde, pero con esto ya me siento de más realizado.

:cool:
  • 0

#6 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 17 junio 2011 - 09:35

Problemas para pasar de cualquier tipo de dato a Dword.
Sigo traduciendo de a poco está libreria creo que una vez terminada, se podra acceder desde lazarus a dispositivos bluetooth.
Eh creado un simple formulario, que llamas a las funciones de la dll que estoy tratando de traducir.

Imagen Enviada
Y ya logre pasar 3 funciones, para pasar las demás funciones debo crear un nuevo tipo de datos, por eso me trabo acá, creo que abandono por hoy.



delphi
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     BTN_BT_InitializeLibrary: TButton;
  16.     btn_BT_UninitializeLibrary: TButton;
  17.     BTN_BT_IsBlueSoleilStarted: TButton;
  18.     CB_BT_InitializeLibrary: TCheckBox;
  19.     CB_BT_IsBlueSoleilStarted: TCheckBox;
  20.     E_BT_IsBlueSoleilStarted: TEdit;
  21.     Label1: TLabel;
  22.     procedure BTN_BT_InitializeLibraryClick(Sender: TObject);
  23.     procedure BTN_BT_IsBlueSoleilStartedClick(Sender: TObject);
  24.     procedure btn_BT_UninitializeLibraryClick(Sender: TObject);
  25.   private
  26.     { private declarations }
  27.   public
  28.     function BT_InitializeLibrary() : Boolean; stdcall;
  29.     procedure BT_UninitializeLibrary() ; cdecl;
  30.     function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall;
  31.   end;
  32.  
  33. var
  34.   Form1: TForm1;
  35.  
  36. implementation
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.BTN_BT_InitializeLibraryClick(Sender: TObject);
  41. begin
  42.   CB_BT_InitializeLibrary.Checked:= BT_InitializeLibrary();
  43. end;
  44.  
  45. procedure TForm1.BTN_BT_IsBlueSoleilStartedClick(Sender: TObject);
  46. var
  47.   secons: DWord;
  48. begin
  49.   // Como paso de str a Dword o de Float a Dword o de lo que sea a DWord
  50. // secons:= strtoDWORD (E_BT_IsBlueSoleilStarted.text)
  51. //  CB_BT_IsBlueSoleilStarted.Checked:= BT_IsBlueSoleilStarted(secons);
  52. end;
  53.  
  54. procedure TForm1.btn_BT_UninitializeLibraryClick(Sender: TObject);
  55. begin
  56.     BT_UninitializeLibrary();
  57. end;
  58.  
  59.  
  60. //external 'btfunc.dll' name 'BT_InitializeLibrary';
  61. function TForm1.BT_InitializeLibrary() : Boolean; stdcall;
  62.         external 'btfunc.dll' name 'BT_InitializeLibrary';
  63. procedure TForm1.BT_UninitializeLibrary(); cdecl;
  64.         external 'btfunc.dll' name 'BT_UninitializeLibrary';
  65.  
  66. function TForm1.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall;
  67.         external 'btfunc.dll' name 'BT_InitializeLibrary';
  68.  
  69. {$R *.lfm}
  70.  
  71. end.


  • 0

#7 egostar

egostar

    missing my father, I love my mother.

  • Administrador
  • 14.448 mensajes
  • LocationMéxico

Escrito 17 junio 2011 - 09:38

Caray amigo, vas muy bien, felicidades, (y)

Salud OS
  • 0

#8 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 19 junio 2011 - 03:58

Eh cambiado de esquema, decidí poner todo en una unidad aparte, además cree una clase que agrupa todas las funciones que voy pasando.

Eh creado las estructuras que utiliza en C++, la Pase a Lazarus, todavía no está completo, debo pasar algunos UCHAR y otros tipos de datos que no encuentro equivalentes, además cometí el error de pasar muchas Char[tamano] a char en vez de pasarlo a string (ya lo corrigiere).

El código de la unidad UBluetooth, que tiene la definición de las estructuras (record en pascal) y de la clase  TBluetooth es el siguiente.



delphi
  1. unit UBluetooth;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils;
  9.  
  10. type
  11.  
  12.     T_BLUETOOTH_DEVICE_INFO = Record
  13.       dwSize :DWORD ;
  14.       address : BYTE;
  15.       classOfDevice : Byte;
  16.       szName : char;
  17.       bPaired: boolean;
  18.     end;
  19.  
  20.  
  21.     T_BLUETOOTH_DEVICE_INFO_EX = Record
  22.     dwSize : DWORD;
  23.     address: BYTE ;
  24.     classOfDevice : BYTE ;
  25.     szName :CHAR ;
  26.     bPaired: Boolean;
  27. //    ucLmpVersion: UCHAR ;
  28.     wManuName: WORD ;
  29.     wLmpSubversion: WORD ;
  30. //    reserved[16] : BYTE ;
  31.     wClockOffset: WORD ;
  32.     bConnected :Boolean ;
  33.     dwDataRecvBytes: DWORD ;
  34.     dwDataSentBytes: DWORD ;
  35.     cSignalStrength : CHAR ;
  36.     end;
  37.  
  38.     T_SPP_CLIENT_PARAM = Record
  39.     dwSize: DWORD ;
  40. //    ucComIndex: UCHAR ;
  41.     end;
  42.  
  43.     T_DUN_CLIENT_PARAM = Record
  44.     dwSize: DWORD;
  45.     wShortcutFlags: Boolean;
  46.     bAutoDial: Boolean ;
  47.     szUserName: CHAR;
  48.     password: CHAR;
  49.     dialNumber: CHAR;
  50.     end;
  51.  
  52.     T_OPP_CLIENT_PARAM =Record
  53.     dwSize: DWORD ;
  54.     wCmdFlags: WORD ;
  55.     szObjectPath: CHAR;
  56.     end;
  57.  
  58.     T_SYNC_CLIENT_PARAM = Record
  59.     dwSize: DWORD ;
  60.     bShowSyncDlg: Boolean ;
  61. //    ucSyncType: UCHAR ;
  62.     end;
  63.  
  64.     T_GENERAL_SERVICE_INFO = Record
  65.     dwSize: DWORD ;
  66.     dwServiceHandle: DWORD ;
  67.     wServiceClassUuid16: WORD ;
  68.     szServiceName: CHAR;
  69.     end;
  70.  
  71.     T_SPPEX_SERVICE_INFO = Record
  72.     dwSize: DWORD ;
  73.     dwSDAPRecordHanlde: DWORD ;
  74. //    serviceClassUuid128: UUID ;
  75.     szServiceName: CHAR;
  76. //    ucServiceChannel: UCHAR ;
  77. //    ucComIndex: UCHAR ;
  78.       end;
  79.  
  80.  
  81.     T_GENERAL_CONNECT_INFO = Record
  82.     dwHandle: DWORD ;
  83.     bIsOutgoing: Boolean ;
  84.     wServiceClasss: WORD ;
  85.     remoteBdAddr: BYTE;
  86.     end;
  87.  
  88.  
  89.   TBluetooth = class(TComponent)
  90.   private
  91.     { private declarations }
  92.   public
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.     function BT_InitializeLibrary() : Boolean; stdcall;
  102.     procedure BT_UninitializeLibrary() ; cdecl;
  103.     function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall;
  104.   end;
  105.  
  106.  
  107. implementation
  108.  
  109.  
  110. //external 'btfunc.dll' name 'BT_InitializeLibrary';
  111. function TBluetooth.BT_InitializeLibrary() : Boolean; stdcall;
  112.         external 'btfunc.dll' name 'BT_InitializeLibrary';
  113. procedure TBluetooth.BT_UninitializeLibrary(); cdecl;
  114.         external 'btfunc.dll' name 'BT_UninitializeLibrary';
  115.  
  116. function TBluetooth.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall;
  117.         external 'btfunc.dll' name 'BT_InitializeLibrary';
  118.  
  119.  
  120. end.



El código del formulario de prueba, el mismo que antes es el siguiente.



delphi
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  9.   UBluetooth;
  10.  
  11. type
  12.  
  13.   { TForm1 }
  14.  
  15.   TForm1 = class(TForm)
  16.     BTN_BT_InitializeLibrary: TButton;
  17.     btn_BT_UninitializeLibrary: TButton;
  18.     BTN_BT_IsBlueSoleilStarted: TButton;
  19.     CB_BT_InitializeLibrary: TCheckBox;
  20.     CB_BT_IsBlueSoleilStarted: TCheckBox;
  21.     E_BT_IsBlueSoleilStarted: TEdit;
  22.     Label1: TLabel;
  23.     procedure BTN_BT_InitializeLibraryClick(Sender: TObject);
  24.     procedure BTN_BT_IsBlueSoleilStartedClick(Sender: TObject);
  25.     procedure btn_BT_UninitializeLibraryClick(Sender: TObject);
  26.   private
  27.     { private declarations }
  28.   public
  29.     bl : TBluetooth;
  30.   end;
  31.  
  32. var
  33.   Form1: TForm1;
  34.  
  35. implementation
  36.  
  37.  
  38. { TForm1 }
  39.  
  40. procedure TForm1.BTN_BT_InitializeLibraryClick(Sender: TObject);
  41. begin
  42.   CB_BT_InitializeLibrary.Checked:= bl.BT_InitializeLibrary();
  43. end;
  44.  
  45. procedure TForm1.BTN_BT_IsBlueSoleilStartedClick(Sender: TObject);
  46. var
  47.   secons: DWord;
  48. begin
  49.   // Como paso de str a Dword o de Float a Dword o de lo que sea a DWord
  50. // secons:= strtoDWORD (E_BT_IsBlueSoleilStarted.text)
  51. //  CB_BT_IsBlueSoleilStarted.Checked:= BT_IsBlueSoleilStarted(secons);
  52. end;
  53.  
  54. procedure TForm1.btn_BT_UninitializeLibraryClick(Sender: TObject);
  55. begin
  56.     bl.BT_UninitializeLibrary();
  57. end;
  58.  
  59.  
  60.  
  61. {$R *.lfm}
  62.  
  63. end.



Hasta el momento solo funcionan esas 3 funciones.

Ya seguiré mañana ahora voy a festejar mi primer día del padre.

  • 0

#9 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 20 junio 2011 - 01:52

Bueno la traducion ya va al 51%, pase 16 funciones de las 30, pero me queda corregir algunos punteros que aparecieron por ahí. Él código es el siguiente:



delphi
  1. unit UBluetooth;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils;
  9.  
  10. type
  11.  
  12.     //Recor 1
  13.     T_BLUETOOTH_DEVICE_INFO = Record
  14.       dwSize :DWORD ;
  15.       address : TByteArray;
  16.       classOfDevice : TByteArray;
  17.       szName : Array[0..100] of char;
  18.       bPaired: boolean;
  19.     end;
  20.  
  21.     //Recor 2
  22.     T_BLUETOOTH_DEVICE_INFO_EX = Record
  23.     dwSize : DWORD;
  24.     address: TByteArray ;
  25.     classOfDevice : TByteArray ;
  26.     szName : Array[0..100] of char;
  27.     bPaired: Boolean;
  28.     ucLmpVersion: Byte; //UCHAR ;
  29.     wManuName: WORD ;
  30.     wLmpSubversion: WORD ;
  31.     reserved : Array[0..15] of BYTE ;
  32.     wClockOffset: WORD ;
  33.     bConnected :Boolean ;
  34.     dwDataRecvBytes: DWORD ;
  35.     dwDataSentBytes: DWORD ;
  36.     cSignalStrength : CHAR ;
  37.     end;
  38.  
  39.     //Recor 3
  40.     T_SPP_CLIENT_PARAM = Record
  41.     dwSize: DWORD ;
  42.     ucComIndex: Byte; //UCHAR ;
  43.     end;
  44.  
  45.     //Recor 4
  46.     T_DUN_CLIENT_PARAM = Record
  47.     dwSize: DWORD;
  48.     wShortcutFlags: Boolean;
  49.     bAutoDial: Boolean ;
  50.     szUserName: Array[0..100] of Char;
  51.     password: Array[0..100] of Char;
  52.     dialNumber: Array[0..100] of Char;
  53.     end;
  54.  
  55.     //Recor 5
  56.     T_OPP_CLIENT_PARAM =Record
  57.     dwSize: DWORD ;
  58.     wCmdFlags: WORD ;
  59.     szObjectPath: Array[0..100] of Char;
  60.     end;
  61.  
  62.     //Recor 6
  63.     T_SYNC_CLIENT_PARAM = Record
  64.     dwSize: DWORD ;
  65.     bShowSyncDlg: Boolean ;
  66.     ucSyncType: Byte; //UCHAR ;
  67.     end;
  68.  
  69.     //Recor 7
  70.     T_GENERAL_SERVICE_INFO = Record
  71.     dwSize: DWORD ;
  72.     dwServiceHandle: DWORD ;
  73.     wServiceClassUuid16: WORD ;
  74.     szServiceName: Array[0..100] of Char;
  75.     end;
  76.  
  77.     //Recor 8
  78.     T_SPPEX_SERVICE_INFO = Record
  79.     dwSize: DWORD ;
  80.     dwSDAPRecordHanlde: DWORD ;
  81.     serviceClassUuid128:  TGuid; //UUID ;
  82.     szServiceName: Array[0..100] of Char;
  83.     ucServiceChannel: Byte ; //uchar
  84.     ucComIndex: Byte ;    //uchar
  85.       end;
  86.  
  87.  
  88.     //Recor 9
  89.     T_GENERAL_CONNECT_INFO = Record
  90.     dwHandle: DWORD ;
  91.     bIsOutgoing: Boolean ;
  92.     wServiceClasss: WORD ;
  93.     remoteBdAddr: TByteArray;
  94.     end;
  95.  
  96.  
  97.  
  98.   TBluetooth = class(TComponent)
  99.   private
  100.     { private declarations }
  101.   public
  102.  
  103.     // Declaraciones de las funciones
  104.  
  105.     function BT_InitializeLibrary() : Boolean; stdcall;        //1
  106.     procedure BT_UninitializeLibrary() ; cdecl;
  107.     function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; //(in)
  108.     function BT_IsBluetoothReady(dwSeconds: DWORD): Boolean  ; stdcall;  //(in)
  109.     function BT_StartBluetooth() : DWord; stdcall;            //5
  110.     function BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall; //(in)
  111.     function BT_GetLocalDeviceInfo(dsMask : DWORD;
  112.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  113.     function BT_SetLocalDeviceInfo(dwMask: DWORD;
  114.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  115.     function BT_GetRemoteDeviceInfo(dwMask: DWORD;
  116.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall;//(in, (in,out))
  117.     //10    // (in, [in o out)
  118.     function BT_SetRemoteDeviceInfo(dwMask: DWORD;
  119.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall;
  120.  
  121.     // En c++ esta como BYTE* lpPinCode    [corregir eso]
  122.     function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  123.             wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean;
  124.             bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)
  125.     // En c++ esta como BYTE* lpBdAddr    [corregir eso]
  126.     function BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; // (in)
  127.  
  128.     //[corregir eso]
  129.     // En c++ esta como BYTE* lpParam y además DWORD* lpConnectionHandle
  130.   // (in, in, (in, out), out)
  131.     function BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  132.             pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE;
  133.             lpConnectionHandle : DWORD) : DWORD; stdcall;
  134.  
  135.     // (in)
  136.     function BT_DisconnectService (dwConnectionHandle: DWORD): DWORD ; stdcall;
  137.  
  138.     // Func nº 15 [corregir eso] DWORD* lpDevsListLength,
  139.     // ( in, in, (in, out), out)
  140.     function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte;
  141.             lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO)
  142.             :DWORD; stdcall;
  143.     function BT_CancelInquiry () :DWORD; stdcall;
  144.  
  145.   end;
  146.  
  147.  
  148. implementation
  149.  
  150.  
  151. //external 'btfunc.dll' name 'BT_InitializeLibrary';
  152. function TBluetooth.BT_InitializeLibrary() : Boolean; stdcall;
  153.         external 'btfunc.dll' name 'BT_InitializeLibrary';      //1
  154. procedure TBluetooth.BT_UninitializeLibrary(); cdecl;
  155.         external 'btfunc.dll' name 'BT_UninitializeLibrary';
  156. function TBluetooth.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall;
  157.         external 'btfunc.dll' name 'BT_InitializeLibrary';
  158. function TBluetooth.BT_IsBluetoothReady(dwSeconds: DWORD) : Boolean; stdcall;
  159.         external 'btfunc.dll' name 'BT_IsBluetoothReady';
  160. function TBluetooth.BT_StartBluetooth() : DWord; stdcall;
  161.         external 'btfunc.dll' name 'BT_StartBluetooth';        //5
  162. function TBluetooth.BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall;
  163.         external 'btfunc.dll' name 'BT_StopBluetooth';
  164. function TBluetooth.BT_GetLocalDeviceInfo(dsMask : DWORD;
  165.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  166.         external 'btfunc.dll' name 'BT_GetLocalDeviceInfo';
  167. function TBluetooth.BT_SetLocalDeviceInfo(dwMask: DWORD;
  168.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  169.         external 'btfunc.dll' name 'BT_SetLocalDeviceInfo';
  170. function TBluetooth.BT_GetRemoteDeviceInfo(dwMask: DWORD;
  171.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  172.         external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo';
  173. function TBluetooth.BT_SetRemoteDeviceInfo(dwMask: DWORD;
  174.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  175.         external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo'; //10
  176. function TBluetooth.BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  177.         wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean;
  178.         bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)
  179.         external 'btfunc.dll' name 'BT_PairDevice';
  180. function TBluetooth.BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall;
  181.         external 'btfunc.dll' name 'BT_PairDevice';
  182. function TBluetooth.BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  183.         pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE;
  184.         lpConnectionHandle : DWORD) : DWORD; stdcall;
  185.         external 'btfunc.dll' name 'BT_ConnectService';
  186. function TBluetooth.BT_DisconnectService (dwConnectionHandle: DWORD): DWORD;
  187.         stdcall; external 'btfunc.dll' name 'BT_DisconnectService';
  188. function TBluetooth.BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte;
  189.         lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO)
  190.         :DWORD; stdcall; external 'btfunc.dll' name 'BT_InquireDevices'; //15
  191. function TBluetooth.BT_CancelInquiry () :DWORD; stdcall;
  192.         stdcall; external 'btfunc.dll' name 'BT_CancelInquiry';
  193.  
  194.  
  195. end.



Bueno, si alguien me puede dar una mano con los puntero, estaría bueno.
  • 0

#10 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 20 junio 2011 - 02:58



delphi
  1. // En c++ esta como BYTE* lpPinCode    [corregir eso]
  2.     function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  3.             wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean;
  4.             bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)
  5.     // En c++ esta como BYTE* lpBdAddr    [corregir eso]
  6.     function BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; // (in)
  7.  
  8.     //[corregir eso]
  9.     // En c++ esta como BYTE* lpParam y además DWORD* lpConnectionHandle
  10.   // (in, in, (in, out), out)
  11.     function BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  12.             pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE;
  13.             lpConnectionHandle : DWORD) : DWORD; stdcall;



Simplemente cambia BYTE* por PBYTE. Ejemplo:


delphi
  1. function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  2.               wPinCodeLen: WORD; lpPinCode: PByte; bKeepOldkeyOnFail:Boolean;
  3.               bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)





delphi
  1. // Func nº 15 [corregir eso] DWORD* lpDevsListLength,
  2.     // ( in, in, (in, out), out)
  3.     function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte;
  4.             lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO)
  5.             :DWORD; stdcall;


 
  Simplemente cambia DWORD* por PDWORD. Ejemplo:


delphi
  1.     function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte;
  2.               lpDevsListLength: PDWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO)
  3.               :DWORD; stdcall;



Saludos.
  • 0

#11 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 20 junio 2011 - 07:22

Muchas gracias escafandra, por tus observaciones.
Como veras en el código ya está como me decís, entonces entiendo que está bien, sigo pasando los punteros como lo venia pasando.
Voy tratar de hoy o mañana terminar de traducir la dll, me quedan 14 funciones y después debo ver como realizar un ejemplo con cada una de las funciones.

  • 0

#12 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 20 junio 2011 - 07:35

Voy tratar de hoy o mañana terminar de traducir la dll, me quedan 14 funciones y después debo ver como realizar un ejemplo con cada una de las funciones.

En realidad no estás traduciendo la dll sino mas bien estás realizando una interfaz de uso, o traduciendo el archivo de definiciones (.h)  del C al delphi.

Si, es importante que hagas un ejemplo de prueba, será la única forma de saber cómo funciona y si metiste la "gamba" en tu código.


Saludos.
  • 0

#13 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 20 junio 2011 - 03:43

De donde habre sacado que son 30 funciones, son 28; de las 28 pase 27 hay una la numero 24, que usa sus propias estructuras, dentro de la función llama a otra función void, tengo que estudiarla con un poquito de detalle, creo que por hoy ya está.
Código de las 27 instrucciónes.



delphi
  1. unit UBluetooth;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils;
  9.  
  10. type
  11.  
  12.     //Recor 1
  13.     T_BLUETOOTH_DEVICE_INFO = Record
  14.       dwSize :DWORD ;
  15.       address : TByteArray;
  16.       classOfDevice : TByteArray;
  17.       szName : Array[0..100] of char;
  18.       bPaired: boolean;
  19.     end;
  20.  
  21.     //Recor 2
  22.     T_BLUETOOTH_DEVICE_INFO_EX = Record
  23.     dwSize : DWORD;
  24.     address: TByteArray ;
  25.     classOfDevice : TByteArray ;
  26.     szName : Array[0..100] of char;
  27.     bPaired: Boolean;
  28.     ucLmpVersion: Byte; //UCHAR ;
  29.     wManuName: WORD ;
  30.     wLmpSubversion: WORD ;
  31.     reserved : Array[0..15] of BYTE ;
  32.     wClockOffset: WORD ;
  33.     bConnected :Boolean ;
  34.     dwDataRecvBytes: DWORD ;
  35.     dwDataSentBytes: DWORD ;
  36.     cSignalStrength : CHAR ;
  37.     end;
  38.  
  39.     //Recor 3
  40.     T_SPP_CLIENT_PARAM = Record
  41.     dwSize: DWORD ;
  42.     ucComIndex: Byte; //UCHAR ;
  43.     end;
  44.  
  45.     //Recor 4
  46.     T_DUN_CLIENT_PARAM = Record
  47.     dwSize: DWORD;
  48.     wShortcutFlags: Boolean;
  49.     bAutoDial: Boolean ;
  50.     szUserName: Array[0..100] of Char;
  51.     password: Array[0..100] of Char;
  52.     dialNumber: Array[0..100] of Char;
  53.     end;
  54.  
  55.     //Recor 5
  56.     T_OPP_CLIENT_PARAM =Record
  57.     dwSize: DWORD ;
  58.     wCmdFlags: WORD ;
  59.     szObjectPath: Array[0..100] of Char;
  60.     end;
  61.  
  62.     //Recor 6
  63.     T_SYNC_CLIENT_PARAM = Record
  64.     dwSize: DWORD ;
  65.     bShowSyncDlg: Boolean ;
  66.     ucSyncType: Byte; //UCHAR ;
  67.     end;
  68.  
  69.     //Recor 7
  70.     T_GENERAL_SERVICE_INFO = Record
  71.     dwSize: DWORD ;
  72.     dwServiceHandle: DWORD ;
  73.     wServiceClassUuid16: WORD ;
  74.     szServiceName: Array[0..100] of Char;
  75.     end;
  76.  
  77.     //Recor 8
  78.     T_SPPEX_SERVICE_INFO = Record
  79.     dwSize: DWORD ;
  80.     dwSDAPRecordHanlde: DWORD ;
  81.     serviceClassUuid128:  TGuid; //UUID ;
  82.     szServiceName: Array[0..100] of Char;
  83.     ucServiceChannel: Byte ; //uchar
  84.     ucComIndex: Byte ;    //uchar
  85.       end;
  86.  
  87.  
  88.     //Recor 9
  89.     T_GENERAL_CONNECT_INFO = Record
  90.     dwHandle: DWORD ;
  91.     bIsOutgoing: Boolean ;
  92.     wServiceClasss: WORD ;
  93.     remoteBdAddr: TByteArray;
  94.     end;
  95.  
  96.     //// Estructuras de la funcion numero 24
  97.  
  98.  
  99.  
  100.   TBluetooth = class(TComponent)
  101.   private
  102.     { private declarations }
  103.   public
  104.  
  105.     // Declaraciones de las funciones
  106.  
  107.     function BT_InitializeLibrary() : Boolean; stdcall;        //1
  108.     procedure BT_UninitializeLibrary() ; cdecl;
  109.     function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; //(in)
  110.     function BT_IsBluetoothReady(dwSeconds: DWORD): Boolean  ; stdcall;  //(in)
  111.     function BT_StartBluetooth() : DWord; stdcall;            //5
  112.     function BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall; //(in)
  113.     function BT_GetLocalDeviceInfo(dsMask : DWORD;
  114.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  115.     function BT_SetLocalDeviceInfo(dwMask: DWORD;
  116.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  117.     function BT_GetRemoteDeviceInfo(dwMask: DWORD;
  118.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall;//(in, (in,out))
  119.     //10    // (in, [in o out)
  120.     function BT_SetRemoteDeviceInfo(dwMask: DWORD;
  121.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall;
  122.  
  123.     // En c++ esta como BYTE* lpPinCode    [corregir eso]
  124.     function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  125.             wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean;
  126.             bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)
  127.     // En c++ esta como BYTE* lpBdAddr    [corregir eso]
  128.     function BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; // (in)
  129.  
  130.     //[corregir eso]
  131.     // En c++ esta como BYTE* lpParam y además DWORD* lpConnectionHandle
  132.   // (in, in, (in, out), out)
  133.     function BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  134.             pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE;
  135.             lpConnectionHandle : DWORD) : DWORD; stdcall;
  136.  
  137.     // (in)
  138.     function BT_DisconnectService (dwConnectionHandle: DWORD): DWORD ; stdcall;
  139.  
  140.     // Func nº 15 [corregir eso] DWORD* lpDevsListLength,
  141.     // ( in, in, (in, out), out)
  142.     function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte;
  143.             lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO)
  144.             :DWORD; stdcall;
  145.     function BT_CancelInquiry () :DWORD; stdcall;
  146.  
  147.     // ( in, in, (in, out), (in, out))
  148.     function BT_BrowseServices(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  149.             bBrowseAllServices: Boolean; lpServiceClassListLength :DWORD;
  150.             pSeriveClassList : T_GENERAL_SERVICE_INFO) :DWORD; stdcall;
  151.  
  152.     // en la documentacion que poseo no aclara de que tipo son
  153.     // lpConnInfoLen; lpConnInfo  (in, out, out, out, (in, out), out)
  154.     function BT_GetConnectInfo(dwHandle : Dword; lpIsOutgoing: Boolean;
  155.             lpServiceClasss: Word; lpRemoteBdAddr: BYTE;
  156.             lpConnInfoLen: integer; lpConnInfo: Byte):DWORD; stdcall;
  157.  
  158.     function BT_StartSPPExService (pServiceInfo: T_SPPEX_SERVICE_INFO;
  159.             lpServerHandle : DWORD):DWORD; stdcall;  // ((in, out), out)
  160.  
  161.     function BT_StopSPPExService(dwServerHandle: DWORD):DWORD; stdcall;//(in) 20
  162.  
  163.     // (in, (in,out), (in, out))
  164.     function BT_SearchSPPExServices (pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  165.             lpServiceClassListLength : DWORD;
  166.             pSeriveClassList: T_SPPEX_SERVICE_INFO) :DWORD; stdcall;
  167.  
  168.     // (in, (in, out), out)
  169.     function BT_ConnectSPPExService (pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  170.             pServiceInfo: T_SPPEX_SERVICE_INFO; lpConnectionHandle: DWORD)
  171.             :DWORD; stdcall;
  172.  
  173.     function BT_DisconnectSPPExService(dwConnectionHandle: DWord):
  174.             DWORD; stdcall; // (in)
  175.  
  176. {
  177.     function BT_RegisterCallback(ucEvent : Byte; pfnCbkFun
  178.             /* [in] */ UCHAR ucEvent,
  179.             /* [in] */ LPVOID pfnCbkFun
  180.             ): DWORD ; stdcall; // (in)
  181. }
  182.  
  183.     function BT_UnregisterCallback (ucEvent: Byte):DWORD; stdcall; // (in) 25
  184.  
  185.     function BT_GetVersion():DWORD; stdcall;
  186.  
  187.     function BT_GetBtSpecVersion (lpBtSpecVersion: DWORD):DWORD; stdcall;//(in)
  188.  
  189.     function BT_EnumConnection(lpBufferLen: DWord;
  190.             lpBuffer: T_GENERAL_CONNECT_INFO):DWORD; stdcall;//((in, out), out)
  191.  
  192.  
  193.   end;
  194.  
  195.  
  196. implementation
  197.  
  198.  
  199. //external 'btfunc.dll' name 'BT_InitializeLibrary';
  200. function TBluetooth.BT_InitializeLibrary() : Boolean; stdcall;
  201.         external 'btfunc.dll' name 'BT_InitializeLibrary';      //1
  202. procedure TBluetooth.BT_UninitializeLibrary(); cdecl;
  203.         external 'btfunc.dll' name 'BT_UninitializeLibrary';
  204. function TBluetooth.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall;
  205.         external 'btfunc.dll' name 'BT_InitializeLibrary';
  206. function TBluetooth.BT_IsBluetoothReady(dwSeconds: DWORD) : Boolean; stdcall;
  207.         external 'btfunc.dll' name 'BT_IsBluetoothReady';
  208. function TBluetooth.BT_StartBluetooth() : DWord; stdcall;
  209.         external 'btfunc.dll' name 'BT_StartBluetooth';        //5
  210. function TBluetooth.BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall;
  211.         external 'btfunc.dll' name 'BT_StopBluetooth';
  212. function TBluetooth.BT_GetLocalDeviceInfo(dsMask : DWORD;
  213.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  214.         external 'btfunc.dll' name 'BT_GetLocalDeviceInfo';
  215. function TBluetooth.BT_SetLocalDeviceInfo(dwMask: DWORD;
  216.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  217.         external 'btfunc.dll' name 'BT_SetLocalDeviceInfo';
  218. function TBluetooth.BT_GetRemoteDeviceInfo(dwMask: DWORD;
  219.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  220.         external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo';
  221. function TBluetooth.BT_SetRemoteDeviceInfo(dwMask: DWORD;
  222.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  223.         external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo'; //10
  224. function TBluetooth.BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  225.         wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean;
  226.         bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)
  227.         external 'btfunc.dll' name 'BT_PairDevice';
  228. function TBluetooth.BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall;
  229.         external 'btfunc.dll' name 'BT_PairDevice';
  230. function TBluetooth.BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  231.         pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE;
  232.         lpConnectionHandle : DWORD) : DWORD; stdcall;
  233.         external 'btfunc.dll' name 'BT_ConnectService';
  234. function TBluetooth.BT_DisconnectService (dwConnectionHandle: DWORD): DWORD;
  235.         stdcall; external 'btfunc.dll' name 'BT_DisconnectService';
  236. function TBluetooth.BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte;
  237.         lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO)
  238.         :DWORD; stdcall; external 'btfunc.dll' name 'BT_InquireDevices'; //15
  239. function TBluetooth.BT_CancelInquiry () :DWORD; stdcall;
  240.         external 'btfunc.dll' name 'BT_CancelInquiry';
  241. function TBluetooth.BT_BrowseServices(pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  242.         bBrowseAllServices: Boolean; lpServiceClassListLength :DWORD;
  243.         pSeriveClassList : T_GENERAL_SERVICE_INFO) :DWORD; stdcall;
  244.         external 'btfunc.dll' name 'BT_BrowseServices';
  245. function TBluetooth.BT_GetConnectInfo(dwHandle : Dword; lpIsOutgoing: Boolean;
  246.         lpServiceClasss: Word; lpRemoteBdAddr: BYTE;
  247.         lpConnInfoLen: integer; lpConnInfo: Byte):DWORD; stdcall;
  248.         external 'btfunc.dll' name 'BT_GetConnectInfo';
  249. function TBluetooth.BT_StartSPPExService (pServiceInfo: T_SPPEX_SERVICE_INFO;
  250.         lpServerHandle : DWORD):DWORD; stdcall;
  251.         external 'btfunc.dll' name 'BT_StartSPPExService';
  252. function TBluetooth.BT_StopSPPExService(dwServerHandle: DWORD):DWORD; stdcall;
  253.         external 'btfunc.dll' name 'BT_StopSPPExService'; //20
  254. function TBluetooth.BT_SearchSPPExServices (pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  255.         lpServiceClassListLength : DWORD;
  256.         pSeriveClassList: T_SPPEX_SERVICE_INFO) :DWORD; stdcall;
  257.         external 'btfunc.dll' name 'BT_SearchSPPExServices';
  258. function TBluetooth.BT_ConnectSPPExService (pDevInfo: T_BLUETOOTH_DEVICE_INFO;
  259.         pServiceInfo: T_SPPEX_SERVICE_INFO; lpConnectionHandle: DWORD)
  260.         :DWORD; stdcall;
  261.         external 'btfunc.dll' name 'BT_ConnectSPPExService';
  262. function TBluetooth.BT_DisconnectSPPExService(dwConnectionHandle: DWord):
  263.         DWORD; stdcall;
  264.         external 'btfunc.dll' name 'BT_DisconnectSPPExService';
  265. // falta 24
  266.  
  267. function TBluetooth.BT_UnregisterCallback (ucEvent: Byte):DWORD; stdcall;
  268.         external 'btfunc.dll' name 'BT_UnregisterCallback';
  269. function TBluetooth.BT_GetVersion():DWORD; stdcall;
  270.         external 'btfunc.dll' name 'BT_GetVersion';
  271. function TBluetooth.BT_GetBtSpecVersion (lpBtSpecVersion: DWORD):DWORD; stdcall;
  272.         external 'btfunc.dll' name 'BT_GetBtSpecVersion';
  273.  
  274. function TBluetooth.BT_EnumConnection(lpBufferLen: DWord;
  275.         lpBuffer: T_GENERAL_CONNECT_INFO):DWORD; stdcall;//((in, out), out)
  276.         external 'btfunc.dll' name 'BT_EnumConnection';
  277. end.




En el archivo de documentación, sobre la función numero 24 dice lo siguiente:

5.24 BT_RegisterCallback
This function registers an application-defined callback function for a Bluetooth event.

DWORD BT_RegisterCallback(
/* [in] */ UCHAR ucEvent,
/* [in] */ LPVOID pfnCbkFun
);

Parameters
ucEvent
[in] Specifies which event applications want to be notified. ucEvent can be one of the following value.
Value Meaning
EVENT_CONNECTION_STATUS General connection status is changed.
EVENT_DUN_RAS_CALLBACK RAS connection error occurs.
EVENT_ERROR An error occurs.
EVENT_INQUIRY_DEVICE_REPORT A remote Bluetooth device is found during Bluetooth inquiry.
EVENT_SPPEX_CONNECTION_STATUS Specific SPP connection status is changed.
EVENT_BLUETOOTH_STATUS Bluetooth is started or stopped

pfnCbkFun
[in] Pointer to the callback function that will be called when the event occurs. Prototypes of the callback functions are:


EVENT_CONNECTION_STATUS:
typedef void (*PCALLBACK_CONNECTION_STATE_CHANGED)
(WORD wServiceClass, BYTE* lpBdAddr, UCHAR ucStatus, DWROD dwConnetionHandle);
Parameters:
wServiceClass
[in] Specifies the class of the service associated with the connection.
lpBdAddr
[in] Pointer to a 6-bytes buffer containing the address of the remote device associated with the connection.
ucStatus
[in] Indicates the current connection status:
Value Meaning
STATUS_INCOMING_CONNECT An incoming connection is established.
STATUS_INCOMING_DISCONNECT An incoming connection is released.
STATUS_OUTCOMING_CONNECT An outgoing connection is established.
STATUS_OUTCOMING_DISCONNECT An outgoing connection is released.

dwConnetionHandle
[in] Handle to the connection.

EVENT_DUN_RAS_CALLBACK:
typedef void (*PCALLBACK_RAS_CONNECTION_STATE)
(UCHAR ucStrLen, CHAR* szErrorString, DWORD dwError);

EVENT_ERROR
typedef void (*PCALLBACK_ERROR) (DWORD dwErrorCode);
Parameters:
dwErrorCode:
[in] Error code. Values 0x01-0xff have the same meaning corresponding to HCI error values defined in Bluetooth Specification.

EVENT_INQUIRY_DEVICE_REPORT:
typedef void (*PCALLBACK_INQUIRY_DEVICE) (PBLUETOOTH_DEVICE_INFO pDevInfo);
Parameters:
pDevInfo
[in] Pointer to a structure of type BLUETOOTH_DEVICE_INFO containing the record of the device. Content of member szName is from BlueSoleil’s history database.  If member address and classOfDevice contain all zeros, it indicates that the inquiry completes, though BlueSoleil may continue to query device names.
Remarks
A device with the same device address may be reported more than one 1 time, client applications are expected to filter duplicated devices.

EVENT_SPPEX_CONNECTION_STATUS:
typedef void (*PCALLBACK_SPPEX_CONNECTION_STATUS) (DWORD dwServerHandle, BYTE* lpBdAddr, UCHAR ucStatus, DWORD dwConnetionHandle);

Parameters:
dwServerHandle
[in] The handle to the specific SPP service. By comparing to the handle returned by BT_StartSPPExService, dwServerHandle can be used to retrieve related service information, e.g. COM port associated to the service.
lpBdAddr
[in] Pointer to a 6-bytes buffer containing the address of the remote device associated with the connection. The address is invalid if ucStatus is STATUS_INCOMING_DISCONNECT.
ucStatus
[in] Connection status:
Value Meaning
STATUS_INCOMING_CONNECT An incoming connection is established.
STATUS_INCOMING_DISCONNECT An incoming connection is released.

dwConnetionHandle
[in] Reserved.
EVENT_BLUETOOTH_STATUS:
typedef void (*PCALLBACK_BLUETOOTH_STATUS) (UCHAR ucStatus);
Parameters:
ucStatus
[in] Indicates  the current status of Bluetooth, this parameter is one of the following value:
Value Meaning
STATUS_BLUETOOTH_STARTED Bluetooth is started.
STATUS_BLUETOOTH_STOPED Bluetooth is stoped.


Return Values
BTSTATUS_SUCCESS if the function succeeds.
BTSTATUS_PARAMETER_ERROR if parameter(s) is (/are) not correct
BTSTATUS_BT_NOT_READY if Bluetooth is not started.
BTSTATUS_SYSTEM_ERROR if system error(s) occurs.
BTSTATUS_FAIL if the function fails for other reasons.

Remarks
If BlueSoleil exits, all registered events will be discarded, the associated callbacks will not work after BlueSoleil is restarted. To keep callbacks working, an application must call BT_UninitializeLibrary when it detects BlueSoleil exits, and call BT_InitializeLibrary and BT_RegisterCallback again after BlueSoleil is restarted.

It is recommended that, the Bluetooth APIs defined in this document should not be called in the users’ callback functions registered by BT_RegisterCallback to prevent any potential deadlock in codes.



Por otro, si alguien me puede dar una mano con una función que pase de float a DWORD y de string a Byte; seria de gran ayuda, ya que le voy a dedicar a descifrar está función. Eh visto mucho código al respecto pero no se cual elegir, así que si me dan uno que uds. hallan probado.

Desde ya muchas gracias.

  • 0

#14 escafandra

escafandra

    Advanced Member

  • Administrador
  • 4.107 mensajes
  • LocationMadrid - España

Escrito 20 junio 2011 - 04:36

Esa función  BT_RegisterCallback recibe como parámetro un puntero a una función CALLBACK esa función CallBack será llamada por la dll en un momento dado, y la escribe el usuario o le asigna un nulo.

Pasar de String a Byte no se puede, pero si a PBYTE. Sería como pasar de un String a carácter... Puedes manejar los caracteres sueltos pero no conviertes nada.

Te presento dos formas de hacerlo, pero quizás sea la segunda la mas adecuada cuando lo que haces es usarlo para pasar parámetros a una función escrita en C.

delphi
  1. var
  2.   s: String;
  3.   u: PBYTE;
  4. begin
  5.   s := 'hola';
  6.   u := PBYTE(@s[1]);
  7.   u := PBYTE(PCHAR(s));
  8. end;                     



En C una cadena de caracteres siempre termina en nulo. en delphi y Lazarus no es así. En C el elemento 0 es el primer carácter, en delphi sería la longitud. En C no se guarda la longitud, se calcula sabiendo que siempre habrá un nulo al final.

Pasar de float a DWORD es fácil usando:


delphi
  1. uses
  2.   Math;
  3.  
  4. var
  5.   dw: DWORD;
  6. begin
  7.     dw:= Floor(1.2);  // dw = 1
  8. end;     

     
Puedes usar Trunc y Ceil pero esta última redondea por arriba.



Saludos.                                                                 
  • 0

#15 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 22 junio 2011 - 01:07

Muchas gracias escafandra, recién puedo responderte, me llenaron de trabajo. Voy a tener en cuentas las funciones para convertir que me diste.
  • 0

#16 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 26 junio 2011 - 12:54

Estoy trabado con la primera funcion que devuelve una estructura.

La 6º funcion es la siguiente



delphi
  1.     function BT_GetLocalDeviceInfo(dsMask : DWORD;
  2.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)



Trato de llamarla de la siguiente manera.




delphi
  1. procedure TForm1.BTN_BT_GetLocalDeviceInfoClick(Sender: TObject);
  2. var
  3.   secons: DWord;
  4.   BdI: T_BLUETOOTH_DEVICE_INFO_EX;
  5. begin
  6.   secons:= StrToDword(e_BT_GetLocalDeviceInfo.text);
  7.  
  8. //  bl.BT_GetLocalDeviceInfo(secons, BDI);    //no anda
  9. //  DBI:= bl.BT_GetLocalDeviceInfo(secons, BDI);    //no anda
  10. //  DBI:= bl.BT_GetLocalDeviceInfo(secons, ^BDI);  //no anda
  11. //  DBI:= bl.BT_GetLocalDeviceInfo(secons, &BDI);  //no anda
  12. //  DBI:= bl.BT_GetLocalDeviceInfo(secons, *BDI);  //no anda
  13.  
  14.   cargar_Bluetooth_Device_info_ex(secons, BdI);
  15. end;     
  16.  
  17. La funciones cargar_bluetooth_device_info_ex sirve para pasar los datos del registro del tipo T_Bluetooth_device_info_ex a distintas cajas de texto para poder ver lo que devuelve
  18.  
  19. [code=delphi:0]
  20. procedure TForm1.cargar_Bluetooth_Device_info_ex(BdeviceInfo: T_BLUETOOTH_DEVICE_INFO_EX);
  21. begin
  22.   e_DI_dwsize.Text:= IntToStr(BdeviceInfo.dwSize);
  23. //  e_DI_address.Text:= BdeviceInfo.address;    //no se como addres es un TByteArray
  24. //  e_DI_classofdevice.Text:= BdeviceInfo.classOfDevice;  // no se como cllasofdevie es un TByteArray
  25.   e_DI_szname.Text:= BdeviceInfo.szName;
  26.   e_DI_bparied.Text:= BoolToStr(BdeviceInfo.bPaired);
  27.   e_DI_uclmpversion.Text:= inttostr(BdeviceInfo.ucLmpVersion);
  28.   e_DI_wmanuname.Text:= inttostr(BdeviceInfo.wManuName);
  29.   e_DI_wlmpsubversion.Text:= inttostr(BdeviceInfo.wLmpSubversion);
  30. //  e_DI_reserved.Text:= BdeviceInfo.reserved;  // no se como  reserved es un array of byte[0..15]
  31.   e_DI_wclockoffset.Text:= inttostr(BdeviceInfo.wClockOffset);
  32.   e_DI_bconnected.Text:= BoolToStr(BdeviceInfo.bConnected);
  33.   e_DI_dwdatarecbbytes.Text:= inttostr(BdeviceInfo.dwDataRecvBytes);
  34.   e_DI_dwdatasentbytes.Text:= inttostr(BdeviceInfo.dwDataSentBytes);
  35. //  e_DI_csignalstrength.Text:= inttostr(BdeviceInfo.cSignalStrength);  // no se como, es un char
  36. end;




Bueno así estoy si no puedo recibir datos de la funcion, no como voy a capturar las informaciones que me tira la funcion, lo que estoy seguro es que podre enviar datos de tipo estructura, pero todabia no se como recibirlo.
  • 0

#17 martinartaza

martinartaza

    Advanced Member

  • Miembros
  • PipPipPip
  • 159 mensajes
  • LocationArgentina, Tucuman

Escrito 26 junio 2011 - 07:39

Yá se como pasarle estructuras a las funciones, después de probar como loco, todo tipo de alternativa, me ilumine y se me ocurrió lo siguiente:
Una funcion de c++ que sus parametros cambian y que además devuelve un resultado como es el caso de la siguiente funcion.


Dword BT_GetLocalDeviceInfo(dsMask : DWORD; &pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD;
el & es que también devuelve, en conclución Pdevinfo, entra con un valor y sale con otro y además está función devuelve un Dword, la traduje de la siguiente manera, usando una función y un procedure en pascal.



delphi
  1.     function BT_GetLocalDeviceInfo(dsMask : DWORD;
  2.             pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  3.     procedure BT_GetLocalDeviceInfo2(dsMask : DWORD;
  4.             pDevInfo: T_BLUETOOTH_DEVICE_INFO); cdecl;// (in, out)



Luego.


delphi
  1. function TBluetooth.BT_GetLocalDeviceInfo(dsMask : DWORD;
  2.         pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
  3.         external 'btfunc.dll' name 'BT_GetLocalDeviceInfo';
  4.  
  5. procedure TBluetooth.BT_GetLocalDeviceInfo2(dsMask : DWORD;
  6.         pDevInfo: T_BLUETOOTH_DEVICE_INFO); cdecl;
  7.         external 'btfunc.dll' name 'BT_GetLocalDeviceInfo';



y la llamo al apretar un boton con:



delphi
  1. procedure TForm1.BTN_BT_GetLocalDeviceInfoClick(Sender: TObject);
  2. var
  3.   secons: DWord;
  4.   result: DWord;
  5.   BdI: T_BLUETOOTH_DEVICE_INFO;
  6. begin
  7.   secons:= StrToDword(e_BT_GetLocalDeviceInfo.text);
  8.   result := bl.BT_GetLocalDeviceInfo(secons, BDI);
  9.  
  10.   bl.BT_GetLocalDeviceInfo2(secons, BdI);
  11.  
  12.   e_BT_GetLocalDeviceInfoOut.Text:= IntToStr(result);
  13.   cargar_Bluetooth_Device_info(BdI);
  14. end;



Ahora es cuestion de probar todas las 27 funciones que traduje hay una, casi imposible, pero usar el 99% de está libreria creo que sirve para algo.

PD: Necesito mucha ayuda para convertir los datos, en realidad todo se resume en tiempo, el tiempo que pierdo en buscar las conversiones, es tiempo que podria estar haciendo el ejemplo y estoy extremadamente corto de tiempo entre el trabajo, la tesis, mi hijo (pobre ya es una escusa) y las cosas diarias de todo los días. Si alguien me da una mano con las conversiones de datos, la posteo en otro hilo, pero practicamente es pasar todo a string y viceversa los tipos de datos:
tbyte, tbytearray, byte [0..15], dword, word, dword [0...15] en conclución, ya pondre a ver, pero si alguien me tira una soga avanzo más rápido.

Desde ya muchas gracias.








  • 0




IP.Board spam blocked by CleanTalk.