ctypes:传递结构作为输出参数?

时间:2015-04-13 14:26:49

标签: python ctypes

C:

VixError _lib_open(const VixDiskLibConnection connection , 
                  const char *diskPath, uint32 flags, VixDiskLibHandle srcHandle)
{
       VixError vixError = VixDiskLib_Open(connection,diskPath,flags,&srcHandle);
       return vixError;
}

// here srcHandle is output parameter assigned from function call
// call steps:
// VixDiskLibHandle  srcHandle;  //VixDiskLibHandle  srcHandle = NULL;
// VixError err = _lib_open(conn, "<diskpath>", flags, srcHandle);
// do something with   srcHandle

我想从ctypes

传递此srcHandle作为输出参数

我已声明所有结构都需要VixDiskLibHandle,VixDiskLibConnection等......

的Python(ctypes的):

class struct_VixDiskLibHandleStruct(Structure):
    pass
VixDiskLibHandle = POINTER(struct_VixDiskLibHandleStructure)


src_handle = None #is it correct?
testlib._lib_open(conn, diskpath, openFlag, src_handle)
# use this handle further
disk_info_ptr = testlib.lib_info(src_handle)

我的磁盘正常打开但是当我进一步使用sec_handle时,进一步的代码无效。

我是否正确地将src_handle作为输出参数传递? 或者是否有任何方式/需要在testlib._lib_open调用后转换src_handle?

0 个答案:

没有答案