一段奇怪的dllcall,寻求高手帮助!
本帖最后由 cbao123 于 2011-4-24 11:38 编辑这是一段调取蓝牙(btfunc.dll)BT_InquireDevices函数的代码,可返回的数组总显示不对,恳请高手指点,谢谢!#Include <File.au3>
#Include <Array.au3>
Local $dllCallError =
Global const $DEVICE_ADDRESS_LENGTH = 6
Global const $DEVICE_CLASS_LENGTH = 3
Global const $MAX_DEVICE_NAME_LENGTH = 64
$handle = DllOpen("btfunc.dll")
$str = "DWORD;byte[" & $DEVICE_ADDRESS_LENGTH & "];byte[" & $DEVICE_CLASS_LENGTH & "];byte[" & $MAX_DEVICE_NAME_LENGTH & "];INT"
$struct_BLUETOOTH_DEVICE_INFO = DllStructCreate($str)
$lpDevsListLength = DllStructCreate("DWORD")
$dll = DllCall($handle,"dword:cdecl","BT_InquireDevices","byte","INQUIRY_GENERAL","byte",0x30,"long*",DllStructGetPtr($lpDevsListLength),"long*",DllStructGetPtr($struct_BLUETOOTH_DEVICE_INFO))
If @error then
Msgbox(0,"Error in Dll call", $dllCallError[@error])
Else
_arrayDisplay($dll,"BT_InquireDevices")
EndIf下面是函数的API说明:
This function inquires nearby Bluetooth devices or gets paired devices from BlueSoleil’s history records.
DWORD BT_InquireDevices(
/* */ UCHAR ucInqMode,
/* */ UCHAR ucInqTimeLen,
/* */ DWORD* lpDevsListLength,
/* */ PBLUETOOTH_DEVICE_INFO pDevsList,
);
返回的数组:
typedef struct _BLUETOOTH_DEVICE_INFO {
DWORD dwSize;
BYTE address;
BYTE classOfDevice;
CHAR szName;
BOOL bPaired;
} BLUETOOTH_DEVICE_INFO, *PBLUETOOTH_DEVICE_INFO;
代码执行后的返回结果如下:
请各路高人多多帮忙,十分感谢!这段代码已经折腾两个星期了。 也许是周末的缘故,目前没有人肯给予帮助。
作为一个AU3的新手,我特别渴望能得到老师们的提携!!! 返回的应该是结构吧. 本帖最后由 cbao123 于 2011-4-24 00:25 编辑
谢谢!返回的是数组,查阅了很多资料,似乎可行,现在就是不知问题出在那里,请高人详细指点一下,谢谢!
Const $INQUIRY_GENERAL = ?
Const $DEVICE_ADDRESS_LENGTH = 6
Const $DEVICE_CLASS_LENGTH = 3
Const $MAX_DEVICE_NAME_LENGTH = 64
Const $tagBLUETOOTH_DEVICE_INFO = _
"dword Size;" & _
"byte Address[" & $DEVICE_ADDRESS_LENGTH & "];" & _
"byte ClassofDevice[" & $DEVICE_CLASS_LENGTH & "];" & _
"char szName[" & $MAX_DEVICE_NAME_LENGTH & "];" & _
"bool Paired"
$hBTDll = DllOpen("Btfunc.dll")
$tDeviceInfo = DllStructCreate($tagBLUETOOTH_DEVICE_INFO)
$pDeviceInfo = DllStructGetPtr($tDeviceInfo)
DllStructSetData($tDeviceInfo, "Size", DllStructGetSize($tDeviceInfo))
$iResult = DllCall($hBTDll, "long:cdecl", "BT_InquireDevices", _
"ubyte", $INQUIRY_GENERAL, _
"ubyte", 0x30, _
"long*", 0, _
"ptr", $pDeviceInfo)
_ArrayDisplay($iResult)
函数的第一个参数 INQUIRY_GENERAL 是个数字常量,而非字符串,Google了一下,没有找到它的值,在调用前,应该确保INQUIRY_GENERAL有正确的值。另外3个常量的值,估计也不正确。这个函数给出的调用信息太少,另外也没设备来测试,上面的代码全是猜着写的。 非常感谢大佬的赐教!附上dll的工程文件的截图,麻烦您再帮我看看。 本帖最后由 cbao123 于 2011-4-27 23:16 编辑
,。INQUIRY_GENERAL 的值可选,0x00、0x01、0x02和0x03,通常选0x00。
这些参数均来自这个dll的工程文件,应该可信。您的代码运行后显示如下: 下面是c语言关于引用这个函数的代码,本人对c更是一窍不通,请高手帮忙看看是否可以改写成au3,谢谢!void SDK_BtInquiry()
{
UCHAR ucInqMode = INQUIRY_GENERAL_MODE,
ucInqLen = 15;
BLUETOOTH_DEVICE_INFO lpDevsList = {0};
DWORD DevsListLen = sizeof(BLUETOOTH_DEVICE_INFO) * MAX_SERVICE_COUNT;
char temp={0};
if(GetPrivateProfileString("BT_INQUIRY_DEVICE", "Inquiry Mode", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Inquiry Mode Failed!\n");
return;
}
ucInqMode = atoi(temp);
//Get Inquiry Length 0x00-0xFF
if(GetPrivateProfileString("BT_INQUIRY_DEVICE", "Inquiry Length", NULL, temp, MAX_PATH, g_szIniPath)==0){
printf("Get Inquiry Mode Failed!\n");
return;
}
ucInqLen = atoi(temp);
if(ucInqLen=0){
printf("Get Inquiry Mode Failed!\n");
return;
}
BOOL bAsynchronous = GetPrivateProfileInt("BT_INQUIRY_DEVICE", "bAsynchronous",1, g_szIniPath);
DWORD dwResult;
if(bAsynchronous)
DevsListLen = 0;
dwResult = BT_InquireDevices(ucInqMode, ucInqLen,&DevsListLen, lpDevsList);
PrintError("BT_InquireDevices",dwResult);
if(!bAsynchronous && dwResult == BTSTATUS_SUCCESS){
printf("Devices List\n");
DWORD i, offset;
offset = sizeof(BLUETOOTH_DEVICE_INFO);
BLUETOOTH_DEVICE_INFO *pDevice;
for(i=0; i<((DevsListLen)/sizeof(BLUETOOTH_DEVICE_INFO)); i++){
pDevice=(BLUETOOTH_DEVICE_INFO*)((UCHAR*)lpDevsList+i*offset);
printf("Device No.%d\n Device Address: %02X:%02X:%02X:%02X:%02X:%02X\n",
i,
pDevice->address,
pDevice->address,
pDevice->address,
pDevice->address,
pDevice->address,
pDevice->address);
DWORD dwMask = 0;
BLUETOOTH_DEVICE_INFO_EX devInfo = {0};
memcpy(&devInfo.address, pDevice->address, DEVICE_ADDRESS_LENGTH);
devInfo.dwSize = sizeof(BLUETOOTH_DEVICE_INFO_EX);
devInfo.szName='\0';
dwMask = MASK_DEVICE_NAME;
DWORD dwResult;
dwResult = BT_SetRemoteDeviceInfo(dwMask, &devInfo);
PrintError("BT_SetRemoteDeviceInfo",dwResult);
dwResult = BT_GetRemoteDeviceInfo(dwMask, &devInfo);
PrintError("BT_GetRemoteDeviceInfo",dwResult);
printf(" Device Name: %s\n", devInfo.szName);
PrintDeviceClassInfo(pDevice->classOfDevice);
if(pDevice->bPaired)
printf(" Device Is Paired: Yes\n");
else
printf(" Device Is Paired: No\n");
}
}
} 粗略看了一下你上面的代码肯定运行不正确的 使用查询函数时至少需要做一些初始化操作 感谢您的提点!能不能麻烦您帮我修改一下,我对编程也就是AU3的入门阶段,其他的更不懂了。就此我在这里发了求购贴,金额虽不足挂齿,仅略表诚意吧!http://autoitx.com/thread-24300-1-1.html 看不懂。有时间了再研究吧!
页:
[1]