Hello Friends.

My saga with COM-Interop continues. Just as a short reminder - I am in
the process of creating some COM bojects (MFC based) out of managed C++
and want to return them up to a C# application from a factory method.

I managed to create the object (oh wonder - now THAT is simple), but now
I do get totally funny errors trying to wrap them up. Basically, due to
the organisation o the project, I can not use a Type Library or define
classes using COMINPORT to use. The specs asks for classes that are
creatable ONLY from within the factory method - as such, there is no
CreateInstance Method for them.

Here is the source of the factory.

Object* Factory::CreateDataSink () {
        HRESULT *phr = 0;
        umIDataSink* Source = new DataSink (NULL, phr);
        System::IntPtr ptr = __nogc new System::IntPtr (Source);
        Object* o =
System::Runtime::InteropServices::Marshal::GetObjectForIUnknown (ptr);
        return o;
}

Everything goes ok UNTIL I try to actually try to create the Wrapper for
the object (which DOES (!) implement IUNKNOWN).

System.NullReferenceException: Object reference not set to an instance
of an object.
   at System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(IntPtr
pUnk)
        ...

Can it be that this is the wrong method call? Now have this COM object,
and need to have an RCW created around it. IMHO that is the correct
call.

Anyone willing to pick this up?

Regards

Thomas Tomiczek
THONA Consulting Ltd.
(Microsoft MVP C#/.NET)

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to