我一直致力于为 Golang 包装 WindowsPortableDevice Api。下面的 c++ 代码可以正常工作,但突然无法正常工作。
libgowpd.h:
#include <Windows.h>
typedef struct IPortableDeviceManager IPortableDeviceManager;
HRESULT createPortableDeviceManager(IPortableDeviceManager **pPortableDeviceManager);
libgowpd.cpp:
#include <libgowpd.h>
HRESULT createPortableDeviceManager(IPortableDeviceManager **pPortableDeviceManager) {
HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
if (SUCCEEDED(hr)) {
hr = CoCreateInstance(CLSID_PortableDeviceManager,
NULL,
CLSCTX_INPROC_SERVER,
IID_PPV_ARGS(pPortableDeviceManager));
}
return hr;
}
在戈朗
/*
#cgo CFLAGS: -blahblah
#cgo LDFLAGS: -llibgowpd -Ole32
include "libgowpd.h"
*/
import "C"
type HRESULT uint64
type IPortableDeviceManager C.IPortableDeviceManager
func CreatePortableDeviceManager() (*IPortableDeviceManager, error) {
var pPortableDeviceManager *C.struct_IPortableDeviceManager// No matter whether C.IPortableDeviceManager or C.struct_IPortableDeviceManager
hr := C.createPortableDeviceManager(&pPortableDeviceManager)
if hr < 0 {
return nil, HRESULT(hr)
}
if pPortableDeviceManager == nil {
return nil, E_POINTER
}
log.Println("CreatePortableDeviceManager(): Create portable device manager instance.")
return (*IPortableDeviceManager)(pPortableDeviceManager), nil
}
我想我pPortableDeviceManager
通过获取地址正确传递了指针,pPortableDeviceManager
但它返回0x80070057
错误代码(E_INVALIDARG
)。
我做错了什么?