python呼叫C動態庫匯出函式的返回值為指標型別時,在64位python環境下被截斷解決方法
阿新 • • 發佈:2019-01-29
class my_void_p(c_void_p):
pass
def sslog_create_instance():
#直接指定 restype=c_void_p在64位上還是會發生地址截斷,而讓其為一個c_void_p的子型別時可以避免向int的轉換,最終達到目的。
#參見:http://cache.baiducontent.com/c?m=9d78d513d9810ae902b0c8690d679731584381137a9c924268d4e24c95701c011969b9fd61600705a0d8612647fc1805b7b46132635d7df28cc8ff1b80e48f6b68df66722b41da000fd01ca5cd4426c7268d1fb3e40ee7cca66fc4efc5d3a915048c155e26d5e78b2c5152812da75526e3d0cf164b4810ccb97739ae1f2c74c33440c007aea1742545d6e1dd2a1dd42aa6254cccf922b04850a213d25f4c6203e010a60827786dbc1a&p=8371c54ad5c145ec11be9b7c4b509c&newp=882a9647d29a1ff90be2962f1c5d94231610db2151d4d310268ac5&user=baidu&fm=sc&query=python+restype+64&qid=b444bb0400000679&p1=2
func_sslog_create_instance = anylog_dll.sslog_create_instance
func_sslog_create_instance.restype = my_void_p
handle = func_sslog_create_instance()
# if sys.platform == "win32":
# handle = anylog_dll.sslog_create_instance()
# else:
# #64位python上會出現sslog_create_instance()返回的void*=被解析成int的問題,這是我自己增加一個函式
# handle = c_void_p()
# phandle = pointer(handle)
# anylog_dll.sslog_create_instance_ex(phandle)
# #print "sslog_create_instance:", handle.value
return handle
pass
def sslog_create_instance():
#直接指定 restype=c_void_p在64位上還是會發生地址截斷,而讓其為一個c_void_p的子型別時可以避免向int的轉換,最終達到目的。
#參見:http://cache.baiducontent.com/c?m=9d78d513d9810ae902b0c8690d679731584381137a9c924268d4e24c95701c011969b9fd61600705a0d8612647fc1805b7b46132635d7df28cc8ff1b80e48f6b68df66722b41da000fd01ca5cd4426c7268d1fb3e40ee7cca66fc4efc5d3a915048c155e26d5e78b2c5152812da75526e3d0cf164b4810ccb97739ae1f2c74c33440c007aea1742545d6e1dd2a1dd42aa6254cccf922b04850a213d25f4c6203e010a60827786dbc1a&p=8371c54ad5c145ec11be9b7c4b509c&newp=882a9647d29a1ff90be2962f1c5d94231610db2151d4d310268ac5&user=baidu&fm=sc&query=python+restype+64&qid=b444bb0400000679&p1=2
func_sslog_create_instance = anylog_dll.sslog_create_instance
func_sslog_create_instance.restype = my_void_p
handle = func_sslog_create_instance()
# if sys.platform == "win32":
# handle = anylog_dll.sslog_create_instance()
# else:
# #64位python上會出現sslog_create_instance()返回的void*=被解析成int的問題,這是我自己增加一個函式
# handle = c_void_p()
# phandle = pointer(handle)
# anylog_dll.sslog_create_instance_ex(phandle)
# #print "sslog_create_instance:", handle.value
return handle