Can create object using C++ CoCreateInstance, but not using C# Activator.CreateInstance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Abhijeet Dev

    #16
    Re: Can create object using C++ CoCreateInstanc e, but not using C# Activator.Creat eInstance

    Try applying ComImportAttrib ute to this type.

    "Õíϼ¾ÉÓÑ" <xu0577@21cn.co m> wrote in message
    news:u0z55CR0DH A.1660@TK2MSFTN GP09.phx.gbl...[color=blue]
    >
    > "Brian Rogers" <none@none.co m> дÈëÏûÏ¢ÐÂÎÅ
    > :#wfupbBuDHA.20 60@TK2MSFTNGP10 .phx.gbl...[color=green]
    > > Hello everyone,
    > >
    > > I apologize for the cross and re-post, but I am still searching for an
    > > answer.
    > >
    > > Why can C++ can create this object, but C# can't?
    > >
    > > I am trying to create an instance of the default FTP asynchronous[/color]
    > pluggable[color=green]
    > > protocol adaptor, so I can analyse the traffic between urlmon.dll (IE)[/color][/color]
    and[color=blue][color=green]
    > > the FTP server. The language I am attempting to use is C#.
    > >
    > > The CLSID for the adaptor (as referenced in the protocol registry key)[/color][/color]
    is[color=blue][color=green]
    > > {79eac9e3-baf9-11ce-8c82-00aa004ba90b} and is stored as[/color][/color]
    CLSID_FtpProtoc ol.[color=blue][color=green]
    > >
    > > If I use the following unmanaged C++ code, I can create an instance of[/color][/color]
    the[color=blue][color=green]
    > > filter.
    > >
    > > HRESULT result;
    > > LPUNKNOWN _pUnk = NULL;
    > > CoInitialize( NULL);
    > > result = CoCreateInstanc e( CLSID_FtpProtoc ol,
    > > NULL,
    > > CLSCTX_INPROC_S ERVER,
    > > IID_IInternetPr otocol,
    > > (LPVOID*)&_pUnk );
    > >
    > > If I use the following C# code, I receive an error.[/color][/color]
    (OutOfMemoryExc eption)[color=blue][color=green]
    > >
    > > Guid IID_IInternetPr otocolInfo = new
    > > Guid("{79eac9e3-baf9-11ce-8c82-00aa004ba90b}") ;
    > > objType = Type.GetTypeFro mCLSID(IID_IInt ernetProtocolIn fo);
    > > Activator.Creat eInstance(objTy pe);
    > >
    > > Any thoughts would be greatly appreciated.
    > >
    > > Thanks,
    > > Brian.
    > >
    > >
    > >
    > >[/color]
    >
    >[/color]


    Comment

    Working...