CoCreateInstance返回E_INVALIDARG

时间:2017-10-03 09:42:10

标签: c++ winapi go cgo wpd

我一直在为Golang包装WindowsPortableDevice Api。下面的c ++代码正在运行但突然无效。

libgowpd.h:

#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;
}

libgowpd.cpp:

/*
#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
}

在Golang

pPortableDeviceManager

我想通过获取pPortableDeviceManager的地址正确地将指针传递给0x80070057,但它会返回E_INVALIDARG错误代码(▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ ▒NONE. ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ )。

我做错了什么?

0 个答案:

没有答案
相关问题