locked
pUnkOuter is not NULL in CreateInstance RRS feed

  • Question

  • In below sample CreateInstance() method is invoked multiple times. Based on what it is invoked? Also sometimes the pUnkOuter paramtere is not null. How can i avoid it? Currently it is returned as error.

    https://github.com/mganss/AsyncPluggableProtocol


    Thanks, Renjith V R



    Tuesday, April 25, 2017 5:51 PM

All replies

  • Hi Renjith V Ramachandran,

    >>I want to know how CreateInstance() method is invoked

    The following thread provide a sample about the interop for IClassFactory.

    http://stackoverflow.com/questions/9062910/invalidcastexception-when-using-iclassfactory-in-c-sharp

    >>This method is invoked multiple times some times the value of pUnkOuter is not null. I want to know why it is not null also.

    Based on the document below, it can be not null If the object is being created as part of an aggregate

    pUnkOuter [in]

    If the object is being created as part of an aggregate, specify a pointer to the controlling IUnknown interface of the aggregate. Otherwise, this parameter must be NULL.

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682215(v=vs.85).aspx

    Best regards,

    Cole Wu


    MSDN Community Support<br/> Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact <a href="mailto:MSDNFSF@microsoft.com">MSDNFSF@microsoft.com</a>.

    Thursday, April 27, 2017 5:39 AM
  • Is there any way to avoid coming pUnkOuter value not null?

    Should i specify anything for the interface to say aggregation is not supported? Like DECLARE_NOT_AGGREGATABLE() macro in C++


    Thanks, Renjith V R

    Thursday, April 27, 2017 7:37 AM
  • Hi Renjith V Ramachandran,

    If the sample object does not support aggregation, you should pass null to the method.

    Best regards,

    Cole Wu


    MSDN Community Support<br/> Please remember to click &quot;Mark as Answer&quot; the responses that resolved your issue, and to click &quot;Unmark as Answer&quot; if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact <a href="mailto:MSDNFSF@microsoft.com">MSDNFSF@microsoft.com</a>.

    Friday, April 28, 2017 7:00 AM
  • Hi Renjith V Ramachandran,

    If the sample object does not support aggregation, you should pass null to the method.

    Best regards,

    Cole Wu

    In the sample, some time the pUnkOuter value is not null and IID is IUnknown. I want to avoid that. I think this value is getting from CoCreateInstance(). But CoCreateInstance() is invoked from urlmon.dll i think.

    You are telling to set pUnkOuter as NULL? What should be the value of ppVObject in this case?

     

    Thanks, Renjith V R

    Saturday, April 29, 2017 6:10 AM