我正在处理这行代码:
var pps = new IID;
var ppv = ctypes.voidptr_t(0);
var hr = SHGetPropertyStoreForWindow(hwnd, pps.address(), ppv.address());
我正在转换的地方确实这样做了:
IPropertyStore *pps;
HRESULT hr = SHGetPropertyStoreForWindow(hwnd, IID_PPV_ARGS(&pps));
所以我只是将ppv传递给0.但是我不确定为什么hr会回来错误。
我们可以在ctypes中跳过IID_PPV_ARGS,因为我认为它只是像memset那样,它将它设置为0.这是宏代码:
/*http://msdn.microsoft.com/en-us/library/windows/desktop/ee330727%28v=vs.85%29.aspx
* void IID_PPV_ARGS(
* T **pType
* );
*/
http://blogs.msdn.com/b/yvesdolc/archive/2006/12/27/iid-ppv-args-macro.aspx
看起来它只是将我传递给它的任何内容转换为voidptr_t。
我的完整代码在这里,可以复制粘贴,并在上面的行hr行上显示错误。 https://gist.github.com/yajd/862832b07a1d46caef8b#comment-1255934
答案 0 :(得分:1)
不,你不能跳过IID。
您需要创建GUID
结构类型,填写IPropertyStore的IID("886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99"
),然后调用SHGetPropertyStoreForWindow
,
let IID = new ctypes.StructType("IID", [
{Data1: ctypes.uint32_t},
{Data2: ctypes.uint16_t},
{Data3: ctypes.uint16_t},
{Data4: ctypes.uint8_t.array(8)}
]);
// 886D8EEB-8CF2-4446-8D02-CDBA1DBDCF99
let IID_IPropertyStore = new IID();
console.log(IID_IPropertyStore);
IID_IPropertyStore.Data1 = 0x886D8EEB;
IID_IPropertyStore.Data2 = 0x8CF2;
IID_IPropertyStore.Data3 = 0x4446;
"8D;02;CD;BA;1D;BD;CF;99".split(";").forEach(function(e, i) {
IID_IPropertyStore.Data4[i] = parseInt(e, 16);
});
SHGetPropertyStore(hwnd, IID_IPropertyStore.address(), ppv.address());