How to send NULL to a IUnknown** parameter when COM object is surrogate hosted
-
I'm developing a COM object in a dll. The object takes an IUnknown** parameter.
interface IPasser : IDispatch{
[id(1), helpstring("method Pass")]
HRESULT Pass([in]IUnknown* ptr);};When using it in-process I can send NULL as parameter, but when I instantiate the com object usign a surrogage usign CLSCTX_LOCAL_SERVER I get an error message 0x800706f4, "A null reference pointer was passed to the stub."
IPasserPtr obj;
IUnknown* ptr;hr = obj.CreateInstance (CLSID_Passer, 0, CLSCTX_LOCAL_SERVER);
hr = obj->raw_Pass (0); // Returns 0x800706f4
hr = obj->raw_Pass (&ptr); // OKThis is only a problem when I use double indirection, not when I use an ordinary IUnknown*. Can anyone tell me why this is not allowed and how to change the implementation to be able to send a NULL pointer. /Per
-
I'm developing a COM object in a dll. The object takes an IUnknown** parameter.
interface IPasser : IDispatch{
[id(1), helpstring("method Pass")]
HRESULT Pass([in]IUnknown* ptr);};When using it in-process I can send NULL as parameter, but when I instantiate the com object usign a surrogage usign CLSCTX_LOCAL_SERVER I get an error message 0x800706f4, "A null reference pointer was passed to the stub."
IPasserPtr obj;
IUnknown* ptr;hr = obj.CreateInstance (CLSID_Passer, 0, CLSCTX_LOCAL_SERVER);
hr = obj->raw_Pass (0); // Returns 0x800706f4
hr = obj->raw_Pass (&ptr); // OKThis is only a problem when I use double indirection, not when I use an ordinary IUnknown*. Can anyone tell me why this is not allowed and how to change the implementation to be able to send a NULL pointer. /Per
-
You said it yourself - the raw method expects a pointer to a pointer - that's why passing a NULL results in an invalid argument error code. You need to pass a pointer to a null for this to work (you actually have the solution in your question).
Thanks for the response. To clarify a bit. The parameter is used to return a COM pointer. If the caller don't need the value, it sends NULL. So my implementation has the following construction
if (ptr != 0) {
*ptr = something;
*ptr->AddRef ();
}This i not uncommon in C++ programming, but for some resaon its problematic in COM.
-
Thanks for the response. To clarify a bit. The parameter is used to return a COM pointer. If the caller don't need the value, it sends NULL. So my implementation has the following construction
if (ptr != 0) {
*ptr = something;
*ptr->AddRef ();
}This i not uncommon in C++ programming, but for some resaon its problematic in COM.
-
Thanks for a very interesting link. Though, I was not able to reproduce the behavior, even with the code in the article. Even if I put,
unique
orptr
as attribute to my parameter ([in, string, unique]
) I get the same error code. I can pass aIUnknow*
with 0 as value, both withunique
andref
(which should be impossible), but a wchar_t* cannot be passed, regardless of theunique
attribute or not. /Per