douzhantao2857 2017-10-03 09:42
浏览 107

CoCreateInstance返回E_INVALIDARG

I have been working on wrapping WindowsPortableDevice Api for Golang. The c++ code below was working but suddenly is not working.

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

In Golang

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

I think I pass pointer to pPortableDeviceManager correctly via getting address of pPortableDeviceManager but it returns 0x80070057 error code(E_INVALIDARG).

What have I done wrong?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭