Re: Interop Prob w/ LPArray - COM Client throwing exception
Dumitru Sbenghe <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.general |
|---|---|
| Message-ID | <[email protected]> |
You use a smart pointer which will call Release after the call of CoUnitialize(); This can cause an access violation; Dumitru Sbenghe > -----Original Message----- > From: The DOTNET list will be retired 7/1/02 > [mailto:[email protected]]On Behalf Of Aaron Bawcom > Sent: Monday, June 17, 2002 7:16 AM > To: [email protected] > Subject: [DOTNET] Interop Prob w/ LPArray - COM Client throwing > exception > > > I would appreciate any help/insight that anyone can give on this problem. > I have a legacy app that uses the following IDL interface definition: > > interface IMyInterface2 : IUnknown > { > HRESULT doit( [in, size_is(msgLength)]UCHAR* msg, [in]ULONG > msgLength ); > }; > > When my legacy COM Client calls my .Net component that implements this > interface, an access violation (0xC0000005) exception is thrown. I've > tried everything and can not figure out why the exception is thrown in the > COM Client. > > Here is the COM Client: > #include "stdafx.h" > #include "IMyInterface2_h.h" > #include "IMyInterface2_i.c" > > int _tmain(int argc, _TCHAR* argv[]) > { > HRESULT hr = S_OK; > > hr = ::CoInitialize( NULL ); > > CLSID rcid = {0}; > rcid.Data1 = 0x5F850215; rcid.Data2 = 0x7AC2; rcid.Data3 = 0x48b8; > rcid.Data4[0] = 0xA8; rcid.Data4[1] = 0xCF; rcid.Data4[2] = 0xA0; > rcid.Data4[3] = 0x08; rcid.Data4[4] = 0xF7; rcid.Data4[5] = 0x33; > rcid.Data4[6] = 0xD6; rcid.Data4[7] = 0x61; > > CComPtr<IMyInterface2> iMyInterface2; > > hr = iMyInterface2.CoCreateInstance( rcid, NULL, > CLSCTX_INPROC_SERVER ); > > UCHAR* pBytes = (UCHAR*)::CoTaskMemAlloc( 20 ); > > ::ZeroMemory( pBytes, 20 ); > > iMyInterface2->doit( pBytes, 20 ); > > ::CoUninitialize(); > > return 0; > } > > And here is the .Net service component. The .Net component must be copied > in the same directory as the COM client. > > using System; > using System.Runtime.InteropServices; > > namespace ComSrv > { > [GuidAttribute("5F850215-7AC2-48b8-A8CF-A008F733D661")] > public class MyClass : IMyInterface2 > { > public void doit( byte[] msg, ulong msgLength ) > { > } > } > > [ComImport] > [GuidAttribute("B55AFAEB-BC7D-4ca9-8065-F9A45FE378B6")] > [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)] > public interface IMyInterface2 > { > void doit( > [In, MarshalAs( UnmanagedType.LPArray, > SizeParamIndex=1, ArraySubType=UnmanagedType.U1 )]byte[] msg, > [In]ulong msgLength ); > } > } > > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.