Problems with IWbemPathKeyList::GetKey

Q

QDon

I'm having trouble getting this function to work. There is an
inconsistency in the documentation for this function with respect to
the key value argument. The text of the document says that the user
needs to allocate the string buffers for the return strings before
calling the function. I have done that (using the same call with null
buffer pointers to get the buffer sizes). However, the problem I'm
having is that the first buffer for the key name is fine but the second
buffer for the key value does not take a buffer pointer as the
argument. It requires a VARIANT for this argument.

For reference, here is what the function call looks like:

HRESULT GetKey(
ULONG uKeyIx,
ULONG uFlags,
ULONG* puNameBufSize,
LPWSTR pszKeyName,
ULONG* puKeyValBufSize,
VARIANT* pKeyVal,
ULONG* puApparentCimType
);

Now normally, one does not allocate buffers in VARIANTS but rather
leaves that to the called function to do. I have tried it both ways
and have not been able to get the "GetKey" function to return anything
in the VARIANT argument.

Here is a very abbreviated section of my code:

LPWSTR nameBuffer;
BSTR valueBuffer;
VARIANT value;

nameBuffer = new WCHAR[nameBufferSize];

VariantInit ( &value );
value.vt = VT_BSTR;
value.bstrVal = SysAllocStringLen ( NULL, valueBufferSize );

hr = keyList->GetKey ( 0, 0, &nameBufferSize, nameBuffer,
&valueBufferSize, &value,
&cimType );

As you can see, in this example, I've tried allocating the return
buffer in the VARIANT as a BSTR type. I've also tried passing in an
empty VARIANT and several other permutations without success. No
matter what I do, nothing in the "value" argument is altered when I
make this call but the call returns a return code of "S_OK".

The "keyList" appears to be good in that it has the correct number of
key entries and all the rest of the information that I'm getting from
the "GetKey" call is good. The field sizes returned are correct and
the key name buffer gets filled in correctly.

What am I doing wrong?
 
Q

QDon

The problem has been resolved. The manual page for this function is
incorrect! The 6th parameter is not a "VARIANT *", it is actually
defined to be "LPVOID". However, even this is not correct since it
returns a unicode string but the declaration of "LPVOID" causes the
compiler to not generate an error if the incorrect type is passed in.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top