在尝试了一些简单的操作系统BT功能之后,我怀疑我BT_ADDR
的def是不对的。它如下。我是ctypes的新手,有人能给我一些暗示吗?我的defs是否正确?我在python2.5(depricated,yes,硬件约束)
UCHAR = c_ubyte
ULONGLONG = c_ulonglong
# typedef ULONGLONG bt_addr, *pbt_addr, BT_ADDR, *PBT_ADDR;
BT_ADDR = ULONGLONG
# int BthGetCurrentMode( BT_ADDR* pba, unsigned char* pmode);
BthGetCurrentMode = windll.btdrt.BthGetCurrentMode
BthGetCurrentMode.argtypes = [ POINTER( w.BT_ADDR ), POINTER(w.UCHAR) ]
# bt address: dc:1d:30:42:8b:19
bta = c_ulonglong( int('dc1d30428b19', 16) )
print(bta)
#> c_ulonglong(242017921829657L)
pba = pointer( bta )
pmode = pointer(c_ubyte())
rt = BthGetCurrentMode( pba, pmode )
ec = GetLastError()
print( rt, ec )
#> 1168, 1168
# ERROR_NOT_FOUND = 1168 # Element not found.
更新:我按照建议更新了代码,但我仍然在上面的函数中得到错误1168。我在另一个函数上尝试了它,如下所示,它工作正常。
# int BthRemoteNameQuery( BT_ADDR* pba, unsigned int cBuffer, unsigned int* pcRequired, WCHAR* szString);
BthRemoteNameQuery = btdrt.BthRemoteNameQuery
BthRemoteNameQuery.argtypes = [ POINTER(w.BT_ADDR), w.UINT , POINTER(w.UINT), POINTER(w.WCHAR) ]
cBuffer = 256
pcRequired = pointer( c_uint() )
szString = ctypes.create_unicode_buffer( 256 )
rt = BthRemoteNameQuery( pba, cBuffer, pcRequired ,szString )
ec = GetLastError()
if rt != 0 :
print( "Rt%s, Err%s" % (rt,ec) )
else:
print( 'returned length=', pcRequired.contents )
print( 'string=', szString.value )
#>13
#>u'QR-386A-8B19'