To get VT_EMPTY in your ATL side, simply pass null (Nothing in VB, nullptr in C++/CLI) in managed code.
Reference:
سؤال
I have an ATL COM service which exposes a method that takes in an [in, out] VARIANT pointer as a parameter.
For example, I have the following method for a COM interface, say IMyApiCom:
HRESULT Action([in, out] VARIANT* EmptyObj);
I wrote a C# client application that calls this, like so:
MyApiCom myapi = new MyApiCom();
Object emptyObj = new Object();
myapi.Action(ref emptyObj);
Now, when I debug the COM service and check how EmptyObj
is initialized, it is of type VT_DISPATCH, whereas I expected it to be VT_EMPTY. This causes an issue for me, although it can easily be worked around (by setting it as VT_EMPTY).
Reasons for why I'd prefer it to be VT_EMPTY aside, I'd just like to know why it's initialized as VT_DISPATCH and not VT_EMPTY.
Also, is it possible to pass an object of type VT_EMPTY?
المحلول
To get VT_EMPTY in your ATL side, simply pass null (Nothing in VB, nullptr in C++/CLI) in managed code.
Reference: