Crear una función que llame a una función de una DLL.
#1
Escrito 17 junio 2011 - 08:42
Desde ya muchas gracias.
#2
Escrito 17 junio 2011 - 08:45
#3
Escrito 17 junio 2011 - 09:45
#4
Escrito 17 junio 2011 - 10:56
procedure HolaMundo; external 'archivoDLL.dll'
Así llamas la función contenida dentro de una DLL, claro, con previo conocimiento de su estructura.
Saludos.
#5
Escrito 17 junio 2011 - 08:31
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:
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) Button1: TButton; CheckBox1: TCheckBox; procedure Button1Click(Sender: TObject); private { private declarations } public function BT_InitializeLibrary() : Boolean; stdcall; end; var Form1: TForm1; implementation { TForm1 } procedure TForm1.Button1Click(Sender: TObject); begin CheckBox1.Checked:= BT_InitializeLibrary(); end; //external 'btfunc.dll' name 'BT_InitializeLibrary'; function TForm1.BT_InitializeLibrary() : Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; {$R *.lfm} end.
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.
#6
Escrito 17 junio 2011 - 09:35
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.
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.
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TForm1 } TForm1 = class(TForm) BTN_BT_InitializeLibrary: TButton; btn_BT_UninitializeLibrary: TButton; BTN_BT_IsBlueSoleilStarted: TButton; CB_BT_InitializeLibrary: TCheckBox; CB_BT_IsBlueSoleilStarted: TCheckBox; E_BT_IsBlueSoleilStarted: TEdit; Label1: TLabel; procedure BTN_BT_InitializeLibraryClick(Sender: TObject); procedure BTN_BT_IsBlueSoleilStartedClick(Sender: TObject); procedure btn_BT_UninitializeLibraryClick(Sender: TObject); private { private declarations } public function BT_InitializeLibrary() : Boolean; stdcall; procedure BT_UninitializeLibrary() ; cdecl; function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; end; var Form1: TForm1; implementation { TForm1 } procedure TForm1.BTN_BT_InitializeLibraryClick(Sender: TObject); begin CB_BT_InitializeLibrary.Checked:= BT_InitializeLibrary(); end; procedure TForm1.BTN_BT_IsBlueSoleilStartedClick(Sender: TObject); var secons: DWord; begin // Como paso de str a Dword o de Float a Dword o de lo que sea a DWord // secons:= strtoDWORD (E_BT_IsBlueSoleilStarted.text) // CB_BT_IsBlueSoleilStarted.Checked:= BT_IsBlueSoleilStarted(secons); end; procedure TForm1.btn_BT_UninitializeLibraryClick(Sender: TObject); begin BT_UninitializeLibrary(); end; //external 'btfunc.dll' name 'BT_InitializeLibrary'; function TForm1.BT_InitializeLibrary() : Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; procedure TForm1.BT_UninitializeLibrary(); cdecl; external 'btfunc.dll' name 'BT_UninitializeLibrary'; function TForm1.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; {$R *.lfm} end.
#7
Escrito 17 junio 2011 - 09:38
Salud OS
#8
Escrito 19 junio 2011 - 03:58
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.
unit UBluetooth; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type T_BLUETOOTH_DEVICE_INFO = Record dwSize :DWORD ; address : BYTE; classOfDevice : Byte; szName : char; bPaired: boolean; end; T_BLUETOOTH_DEVICE_INFO_EX = Record dwSize : DWORD; address: BYTE ; classOfDevice : BYTE ; szName :CHAR ; bPaired: Boolean; // ucLmpVersion: UCHAR ; wManuName: WORD ; wLmpSubversion: WORD ; // reserved[16] : BYTE ; wClockOffset: WORD ; bConnected :Boolean ; dwDataRecvBytes: DWORD ; dwDataSentBytes: DWORD ; cSignalStrength : CHAR ; end; T_SPP_CLIENT_PARAM = Record dwSize: DWORD ; // ucComIndex: UCHAR ; end; T_DUN_CLIENT_PARAM = Record dwSize: DWORD; wShortcutFlags: Boolean; bAutoDial: Boolean ; szUserName: CHAR; password: CHAR; dialNumber: CHAR; end; T_OPP_CLIENT_PARAM =Record dwSize: DWORD ; wCmdFlags: WORD ; szObjectPath: CHAR; end; T_SYNC_CLIENT_PARAM = Record dwSize: DWORD ; bShowSyncDlg: Boolean ; // ucSyncType: UCHAR ; end; T_GENERAL_SERVICE_INFO = Record dwSize: DWORD ; dwServiceHandle: DWORD ; wServiceClassUuid16: WORD ; szServiceName: CHAR; end; T_SPPEX_SERVICE_INFO = Record dwSize: DWORD ; dwSDAPRecordHanlde: DWORD ; // serviceClassUuid128: UUID ; szServiceName: CHAR; // ucServiceChannel: UCHAR ; // ucComIndex: UCHAR ; end; T_GENERAL_CONNECT_INFO = Record dwHandle: DWORD ; bIsOutgoing: Boolean ; wServiceClasss: WORD ; remoteBdAddr: BYTE; end; TBluetooth = class(TComponent) private { private declarations } public function BT_InitializeLibrary() : Boolean; stdcall; procedure BT_UninitializeLibrary() ; cdecl; function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; end; implementation //external 'btfunc.dll' name 'BT_InitializeLibrary'; function TBluetooth.BT_InitializeLibrary() : Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; procedure TBluetooth.BT_UninitializeLibrary(); cdecl; external 'btfunc.dll' name 'BT_UninitializeLibrary'; function TBluetooth.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; end.
El código del formulario de prueba, el mismo que antes es el siguiente.
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, UBluetooth; type { TForm1 } TForm1 = class(TForm) BTN_BT_InitializeLibrary: TButton; btn_BT_UninitializeLibrary: TButton; BTN_BT_IsBlueSoleilStarted: TButton; CB_BT_InitializeLibrary: TCheckBox; CB_BT_IsBlueSoleilStarted: TCheckBox; E_BT_IsBlueSoleilStarted: TEdit; Label1: TLabel; procedure BTN_BT_InitializeLibraryClick(Sender: TObject); procedure BTN_BT_IsBlueSoleilStartedClick(Sender: TObject); procedure btn_BT_UninitializeLibraryClick(Sender: TObject); private { private declarations } public bl : TBluetooth; end; var Form1: TForm1; implementation { TForm1 } procedure TForm1.BTN_BT_InitializeLibraryClick(Sender: TObject); begin CB_BT_InitializeLibrary.Checked:= bl.BT_InitializeLibrary(); end; procedure TForm1.BTN_BT_IsBlueSoleilStartedClick(Sender: TObject); var secons: DWord; begin // Como paso de str a Dword o de Float a Dword o de lo que sea a DWord // secons:= strtoDWORD (E_BT_IsBlueSoleilStarted.text) // CB_BT_IsBlueSoleilStarted.Checked:= BT_IsBlueSoleilStarted(secons); end; procedure TForm1.btn_BT_UninitializeLibraryClick(Sender: TObject); begin bl.BT_UninitializeLibrary(); end; {$R *.lfm} end.
Hasta el momento solo funcionan esas 3 funciones.
Ya seguiré mañana ahora voy a festejar mi primer día del padre.
#9
Escrito 20 junio 2011 - 01:52
unit UBluetooth; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type //Recor 1 T_BLUETOOTH_DEVICE_INFO = Record dwSize :DWORD ; address : TByteArray; classOfDevice : TByteArray; szName : Array[0..100] of char; bPaired: boolean; end; //Recor 2 T_BLUETOOTH_DEVICE_INFO_EX = Record dwSize : DWORD; address: TByteArray ; classOfDevice : TByteArray ; szName : Array[0..100] of char; bPaired: Boolean; ucLmpVersion: Byte; //UCHAR ; wManuName: WORD ; wLmpSubversion: WORD ; reserved : Array[0..15] of BYTE ; wClockOffset: WORD ; bConnected :Boolean ; dwDataRecvBytes: DWORD ; dwDataSentBytes: DWORD ; cSignalStrength : CHAR ; end; //Recor 3 T_SPP_CLIENT_PARAM = Record dwSize: DWORD ; ucComIndex: Byte; //UCHAR ; end; //Recor 4 T_DUN_CLIENT_PARAM = Record dwSize: DWORD; wShortcutFlags: Boolean; bAutoDial: Boolean ; szUserName: Array[0..100] of Char; password: Array[0..100] of Char; dialNumber: Array[0..100] of Char; end; //Recor 5 T_OPP_CLIENT_PARAM =Record dwSize: DWORD ; wCmdFlags: WORD ; szObjectPath: Array[0..100] of Char; end; //Recor 6 T_SYNC_CLIENT_PARAM = Record dwSize: DWORD ; bShowSyncDlg: Boolean ; ucSyncType: Byte; //UCHAR ; end; //Recor 7 T_GENERAL_SERVICE_INFO = Record dwSize: DWORD ; dwServiceHandle: DWORD ; wServiceClassUuid16: WORD ; szServiceName: Array[0..100] of Char; end; //Recor 8 T_SPPEX_SERVICE_INFO = Record dwSize: DWORD ; dwSDAPRecordHanlde: DWORD ; serviceClassUuid128: TGuid; //UUID ; szServiceName: Array[0..100] of Char; ucServiceChannel: Byte ; //uchar ucComIndex: Byte ; //uchar end; //Recor 9 T_GENERAL_CONNECT_INFO = Record dwHandle: DWORD ; bIsOutgoing: Boolean ; wServiceClasss: WORD ; remoteBdAddr: TByteArray; end; TBluetooth = class(TComponent) private { private declarations } public // Declaraciones de las funciones function BT_InitializeLibrary() : Boolean; stdcall; //1 procedure BT_UninitializeLibrary() ; cdecl; function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; //(in) function BT_IsBluetoothReady(dwSeconds: DWORD): Boolean ; stdcall; //(in) function BT_StartBluetooth() : DWord; stdcall; //5 function BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall; //(in) function BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) function BT_SetLocalDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) function BT_GetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall;//(in, (in,out)) //10 // (in, [in o out) function BT_SetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // En c++ esta como BYTE* lpPinCode [corregir eso] function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO; wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean; bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in) // En c++ esta como BYTE* lpBdAddr [corregir eso] function BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; // (in) //[corregir eso] // En c++ esta como BYTE* lpParam y además DWORD* lpConnectionHandle // (in, in, (in, out), out) function BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE; lpConnectionHandle : DWORD) : DWORD; stdcall; // (in) function BT_DisconnectService (dwConnectionHandle: DWORD): DWORD ; stdcall; // Func nº 15 [corregir eso] DWORD* lpDevsListLength, // ( in, in, (in, out), out) function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte; lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO) :DWORD; stdcall; function BT_CancelInquiry () :DWORD; stdcall; end; implementation //external 'btfunc.dll' name 'BT_InitializeLibrary'; function TBluetooth.BT_InitializeLibrary() : Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; //1 procedure TBluetooth.BT_UninitializeLibrary(); cdecl; external 'btfunc.dll' name 'BT_UninitializeLibrary'; function TBluetooth.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; function TBluetooth.BT_IsBluetoothReady(dwSeconds: DWORD) : Boolean; stdcall; external 'btfunc.dll' name 'BT_IsBluetoothReady'; function TBluetooth.BT_StartBluetooth() : DWord; stdcall; external 'btfunc.dll' name 'BT_StartBluetooth'; //5 function TBluetooth.BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall; external 'btfunc.dll' name 'BT_StopBluetooth'; function TBluetooth.BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetLocalDeviceInfo'; function TBluetooth.BT_SetLocalDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_SetLocalDeviceInfo'; function TBluetooth.BT_GetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo'; function TBluetooth.BT_SetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo'; //10 function TBluetooth.BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO; wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean; bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in) external 'btfunc.dll' name 'BT_PairDevice'; function TBluetooth.BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; external 'btfunc.dll' name 'BT_PairDevice'; function TBluetooth.BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE; lpConnectionHandle : DWORD) : DWORD; stdcall; external 'btfunc.dll' name 'BT_ConnectService'; function TBluetooth.BT_DisconnectService (dwConnectionHandle: DWORD): DWORD; stdcall; external 'btfunc.dll' name 'BT_DisconnectService'; function TBluetooth.BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte; lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO) :DWORD; stdcall; external 'btfunc.dll' name 'BT_InquireDevices'; //15 function TBluetooth.BT_CancelInquiry () :DWORD; stdcall; stdcall; external 'btfunc.dll' name 'BT_CancelInquiry'; end.
Bueno, si alguien me puede dar una mano con los puntero, estaría bueno.
#10
Escrito 20 junio 2011 - 02:58
delphi
// En c++ esta como BYTE* lpPinCode [corregir eso] function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO; wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean; bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in) // En c++ esta como BYTE* lpBdAddr [corregir eso] function BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; // (in) //[corregir eso] // En c++ esta como BYTE* lpParam y además DWORD* lpConnectionHandle // (in, in, (in, out), out) function BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE; lpConnectionHandle : DWORD) : DWORD; stdcall;
Simplemente cambia BYTE* por PBYTE. Ejemplo:
function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO; wPinCodeLen: WORD; lpPinCode: PByte; bKeepOldkeyOnFail:Boolean; bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in)
delphi
// Func nº 15 [corregir eso] DWORD* lpDevsListLength, // ( in, in, (in, out), out) function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte; lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO) :DWORD; stdcall;
Simplemente cambia DWORD* por PDWORD. Ejemplo:
function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte; lpDevsListLength: PDWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO) :DWORD; stdcall;
Saludos.
#11
Escrito 20 junio 2011 - 07:22
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.
#12
Escrito 20 junio 2011 - 07:35
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.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.
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.
#13
Escrito 20 junio 2011 - 03:43
Código de las 27 instrucciónes.
unit UBluetooth; {$mode objfpc}{$H+} interface uses Classes, SysUtils; type //Recor 1 T_BLUETOOTH_DEVICE_INFO = Record dwSize :DWORD ; address : TByteArray; classOfDevice : TByteArray; szName : Array[0..100] of char; bPaired: boolean; end; //Recor 2 T_BLUETOOTH_DEVICE_INFO_EX = Record dwSize : DWORD; address: TByteArray ; classOfDevice : TByteArray ; szName : Array[0..100] of char; bPaired: Boolean; ucLmpVersion: Byte; //UCHAR ; wManuName: WORD ; wLmpSubversion: WORD ; reserved : Array[0..15] of BYTE ; wClockOffset: WORD ; bConnected :Boolean ; dwDataRecvBytes: DWORD ; dwDataSentBytes: DWORD ; cSignalStrength : CHAR ; end; //Recor 3 T_SPP_CLIENT_PARAM = Record dwSize: DWORD ; ucComIndex: Byte; //UCHAR ; end; //Recor 4 T_DUN_CLIENT_PARAM = Record dwSize: DWORD; wShortcutFlags: Boolean; bAutoDial: Boolean ; szUserName: Array[0..100] of Char; password: Array[0..100] of Char; dialNumber: Array[0..100] of Char; end; //Recor 5 T_OPP_CLIENT_PARAM =Record dwSize: DWORD ; wCmdFlags: WORD ; szObjectPath: Array[0..100] of Char; end; //Recor 6 T_SYNC_CLIENT_PARAM = Record dwSize: DWORD ; bShowSyncDlg: Boolean ; ucSyncType: Byte; //UCHAR ; end; //Recor 7 T_GENERAL_SERVICE_INFO = Record dwSize: DWORD ; dwServiceHandle: DWORD ; wServiceClassUuid16: WORD ; szServiceName: Array[0..100] of Char; end; //Recor 8 T_SPPEX_SERVICE_INFO = Record dwSize: DWORD ; dwSDAPRecordHanlde: DWORD ; serviceClassUuid128: TGuid; //UUID ; szServiceName: Array[0..100] of Char; ucServiceChannel: Byte ; //uchar ucComIndex: Byte ; //uchar end; //Recor 9 T_GENERAL_CONNECT_INFO = Record dwHandle: DWORD ; bIsOutgoing: Boolean ; wServiceClasss: WORD ; remoteBdAddr: TByteArray; end; //// Estructuras de la funcion numero 24 TBluetooth = class(TComponent) private { private declarations } public // Declaraciones de las funciones function BT_InitializeLibrary() : Boolean; stdcall; //1 procedure BT_UninitializeLibrary() ; cdecl; function BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; //(in) function BT_IsBluetoothReady(dwSeconds: DWORD): Boolean ; stdcall; //(in) function BT_StartBluetooth() : DWord; stdcall; //5 function BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall; //(in) function BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) function BT_SetLocalDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) function BT_GetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall;//(in, (in,out)) //10 // (in, [in o out) function BT_SetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // En c++ esta como BYTE* lpPinCode [corregir eso] function BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO; wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean; bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in) // En c++ esta como BYTE* lpBdAddr [corregir eso] function BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; // (in) //[corregir eso] // En c++ esta como BYTE* lpParam y además DWORD* lpConnectionHandle // (in, in, (in, out), out) function BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE; lpConnectionHandle : DWORD) : DWORD; stdcall; // (in) function BT_DisconnectService (dwConnectionHandle: DWORD): DWORD ; stdcall; // Func nº 15 [corregir eso] DWORD* lpDevsListLength, // ( in, in, (in, out), out) function BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte; lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO) :DWORD; stdcall; function BT_CancelInquiry () :DWORD; stdcall; // ( in, in, (in, out), (in, out)) function BT_BrowseServices(pDevInfo: T_BLUETOOTH_DEVICE_INFO; bBrowseAllServices: Boolean; lpServiceClassListLength :DWORD; pSeriveClassList : T_GENERAL_SERVICE_INFO) :DWORD; stdcall; // en la documentacion que poseo no aclara de que tipo son // lpConnInfoLen; lpConnInfo (in, out, out, out, (in, out), out) function BT_GetConnectInfo(dwHandle : Dword; lpIsOutgoing: Boolean; lpServiceClasss: Word; lpRemoteBdAddr: BYTE; lpConnInfoLen: integer; lpConnInfo: Byte):DWORD; stdcall; function BT_StartSPPExService (pServiceInfo: T_SPPEX_SERVICE_INFO; lpServerHandle : DWORD):DWORD; stdcall; // ((in, out), out) function BT_StopSPPExService(dwServerHandle: DWORD):DWORD; stdcall;//(in) 20 // (in, (in,out), (in, out)) function BT_SearchSPPExServices (pDevInfo: T_BLUETOOTH_DEVICE_INFO; lpServiceClassListLength : DWORD; pSeriveClassList: T_SPPEX_SERVICE_INFO) :DWORD; stdcall; // (in, (in, out), out) function BT_ConnectSPPExService (pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_SPPEX_SERVICE_INFO; lpConnectionHandle: DWORD) :DWORD; stdcall; function BT_DisconnectSPPExService(dwConnectionHandle: DWord): DWORD; stdcall; // (in) { function BT_RegisterCallback(ucEvent : Byte; pfnCbkFun /* [in] */ UCHAR ucEvent, /* [in] */ LPVOID pfnCbkFun ): DWORD ; stdcall; // (in) } function BT_UnregisterCallback (ucEvent: Byte):DWORD; stdcall; // (in) 25 function BT_GetVersion():DWORD; stdcall; function BT_GetBtSpecVersion (lpBtSpecVersion: DWORD):DWORD; stdcall;//(in) function BT_EnumConnection(lpBufferLen: DWord; lpBuffer: T_GENERAL_CONNECT_INFO):DWORD; stdcall;//((in, out), out) end; implementation //external 'btfunc.dll' name 'BT_InitializeLibrary'; function TBluetooth.BT_InitializeLibrary() : Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; //1 procedure TBluetooth.BT_UninitializeLibrary(); cdecl; external 'btfunc.dll' name 'BT_UninitializeLibrary'; function TBluetooth.BT_IsBlueSoleilStarted (dwSeconds :DWord) :Boolean; stdcall; external 'btfunc.dll' name 'BT_InitializeLibrary'; function TBluetooth.BT_IsBluetoothReady(dwSeconds: DWORD) : Boolean; stdcall; external 'btfunc.dll' name 'BT_IsBluetoothReady'; function TBluetooth.BT_StartBluetooth() : DWord; stdcall; external 'btfunc.dll' name 'BT_StartBluetooth'; //5 function TBluetooth.BT_StopBluetooth(bSwitch2HidMode: Boolean) : DWord; stdcall; external 'btfunc.dll' name 'BT_StopBluetooth'; function TBluetooth.BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetLocalDeviceInfo'; function TBluetooth.BT_SetLocalDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_SetLocalDeviceInfo'; function TBluetooth.BT_GetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo'; function TBluetooth.BT_SetRemoteDeviceInfo(dwMask: DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetRemoteDeviceInfo'; //10 function TBluetooth.BT_PairDevice(pDevInfo: T_BLUETOOTH_DEVICE_INFO; wPinCodeLen: WORD; lpPinCode: Byte; bKeepOldkeyOnFail:Boolean; bShowPincode: Boolean) : DWORD; stdcall; // (in, in, in, in, in) external 'btfunc.dll' name 'BT_PairDevice'; function TBluetooth.BT_UnpairDevice( lpBdAddr: Byte) : DWORD; stdcall; external 'btfunc.dll' name 'BT_PairDevice'; function TBluetooth.BT_ConnectService(pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_GENERAL_SERVICE_INFO; lpParam: BYTE; lpConnectionHandle : DWORD) : DWORD; stdcall; external 'btfunc.dll' name 'BT_ConnectService'; function TBluetooth.BT_DisconnectService (dwConnectionHandle: DWORD): DWORD; stdcall; external 'btfunc.dll' name 'BT_DisconnectService'; function TBluetooth.BT_InquireDevices(ucInqMode : Byte; ucInqTimeLen: Byte; lpDevsListLength: DWORD; pDevsList: T_BLUETOOTH_DEVICE_INFO) :DWORD; stdcall; external 'btfunc.dll' name 'BT_InquireDevices'; //15 function TBluetooth.BT_CancelInquiry () :DWORD; stdcall; external 'btfunc.dll' name 'BT_CancelInquiry'; function TBluetooth.BT_BrowseServices(pDevInfo: T_BLUETOOTH_DEVICE_INFO; bBrowseAllServices: Boolean; lpServiceClassListLength :DWORD; pSeriveClassList : T_GENERAL_SERVICE_INFO) :DWORD; stdcall; external 'btfunc.dll' name 'BT_BrowseServices'; function TBluetooth.BT_GetConnectInfo(dwHandle : Dword; lpIsOutgoing: Boolean; lpServiceClasss: Word; lpRemoteBdAddr: BYTE; lpConnInfoLen: integer; lpConnInfo: Byte):DWORD; stdcall; external 'btfunc.dll' name 'BT_GetConnectInfo'; function TBluetooth.BT_StartSPPExService (pServiceInfo: T_SPPEX_SERVICE_INFO; lpServerHandle : DWORD):DWORD; stdcall; external 'btfunc.dll' name 'BT_StartSPPExService'; function TBluetooth.BT_StopSPPExService(dwServerHandle: DWORD):DWORD; stdcall; external 'btfunc.dll' name 'BT_StopSPPExService'; //20 function TBluetooth.BT_SearchSPPExServices (pDevInfo: T_BLUETOOTH_DEVICE_INFO; lpServiceClassListLength : DWORD; pSeriveClassList: T_SPPEX_SERVICE_INFO) :DWORD; stdcall; external 'btfunc.dll' name 'BT_SearchSPPExServices'; function TBluetooth.BT_ConnectSPPExService (pDevInfo: T_BLUETOOTH_DEVICE_INFO; pServiceInfo: T_SPPEX_SERVICE_INFO; lpConnectionHandle: DWORD) :DWORD; stdcall; external 'btfunc.dll' name 'BT_ConnectSPPExService'; function TBluetooth.BT_DisconnectSPPExService(dwConnectionHandle: DWord): DWORD; stdcall; external 'btfunc.dll' name 'BT_DisconnectSPPExService'; // falta 24 function TBluetooth.BT_UnregisterCallback (ucEvent: Byte):DWORD; stdcall; external 'btfunc.dll' name 'BT_UnregisterCallback'; function TBluetooth.BT_GetVersion():DWORD; stdcall; external 'btfunc.dll' name 'BT_GetVersion'; function TBluetooth.BT_GetBtSpecVersion (lpBtSpecVersion: DWORD):DWORD; stdcall; external 'btfunc.dll' name 'BT_GetBtSpecVersion'; function TBluetooth.BT_EnumConnection(lpBufferLen: DWord; lpBuffer: T_GENERAL_CONNECT_INFO):DWORD; stdcall;//((in, out), out) external 'btfunc.dll' name 'BT_EnumConnection'; 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.
#14
Escrito 20 junio 2011 - 04:36
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.
var s: String; u: PBYTE; begin s := 'hola'; u := PBYTE(@s[1]); u := PBYTE(PCHAR(s)); 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:
uses Math; var dw: DWORD; begin dw:= Floor(1.2); // dw = 1 end;
Puedes usar Trunc y Ceil pero esta última redondea por arriba.
Saludos.
#15
Escrito 22 junio 2011 - 01:07
#16
Escrito 26 junio 2011 - 12:54
La 6º funcion es la siguiente
function BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out)
Trato de llamarla de la siguiente manera.
procedure TForm1.BTN_BT_GetLocalDeviceInfoClick(Sender: TObject); var secons: DWord; BdI: T_BLUETOOTH_DEVICE_INFO_EX; begin secons:= StrToDword(e_BT_GetLocalDeviceInfo.text); // bl.BT_GetLocalDeviceInfo(secons, BDI); //no anda // DBI:= bl.BT_GetLocalDeviceInfo(secons, BDI); //no anda // DBI:= bl.BT_GetLocalDeviceInfo(secons, ^BDI); //no anda // DBI:= bl.BT_GetLocalDeviceInfo(secons, &BDI); //no anda // DBI:= bl.BT_GetLocalDeviceInfo(secons, *BDI); //no anda cargar_Bluetooth_Device_info_ex(secons, BdI); end; 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 [code=delphi:0] procedure TForm1.cargar_Bluetooth_Device_info_ex(BdeviceInfo: T_BLUETOOTH_DEVICE_INFO_EX); begin e_DI_dwsize.Text:= IntToStr(BdeviceInfo.dwSize); // e_DI_address.Text:= BdeviceInfo.address; //no se como addres es un TByteArray // e_DI_classofdevice.Text:= BdeviceInfo.classOfDevice; // no se como cllasofdevie es un TByteArray e_DI_szname.Text:= BdeviceInfo.szName; e_DI_bparied.Text:= BoolToStr(BdeviceInfo.bPaired); e_DI_uclmpversion.Text:= inttostr(BdeviceInfo.ucLmpVersion); e_DI_wmanuname.Text:= inttostr(BdeviceInfo.wManuName); e_DI_wlmpsubversion.Text:= inttostr(BdeviceInfo.wLmpSubversion); // e_DI_reserved.Text:= BdeviceInfo.reserved; // no se como reserved es un array of byte[0..15] e_DI_wclockoffset.Text:= inttostr(BdeviceInfo.wClockOffset); e_DI_bconnected.Text:= BoolToStr(BdeviceInfo.bConnected); e_DI_dwdatarecbbytes.Text:= inttostr(BdeviceInfo.dwDataRecvBytes); e_DI_dwdatasentbytes.Text:= inttostr(BdeviceInfo.dwDataSentBytes); // e_DI_csignalstrength.Text:= inttostr(BdeviceInfo.cSignalStrength); // no se como, es un char 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.
#17
Escrito 26 junio 2011 - 07:39
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.
function BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) procedure BT_GetLocalDeviceInfo2(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO); cdecl;// (in, out)
Luego.
function TBluetooth.BT_GetLocalDeviceInfo(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO): DWORD; stdcall; // (in, out) external 'btfunc.dll' name 'BT_GetLocalDeviceInfo'; procedure TBluetooth.BT_GetLocalDeviceInfo2(dsMask : DWORD; pDevInfo: T_BLUETOOTH_DEVICE_INFO); cdecl; external 'btfunc.dll' name 'BT_GetLocalDeviceInfo';
y la llamo al apretar un boton con:
procedure TForm1.BTN_BT_GetLocalDeviceInfoClick(Sender: TObject); var secons: DWord; result: DWord; BdI: T_BLUETOOTH_DEVICE_INFO; begin secons:= StrToDword(e_BT_GetLocalDeviceInfo.text); result := bl.BT_GetLocalDeviceInfo(secons, BDI); bl.BT_GetLocalDeviceInfo2(secons, BdI); e_BT_GetLocalDeviceInfoOut.Text:= IntToStr(result); cargar_Bluetooth_Device_info(BdI); 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.