I used PInvoke to call CoInitializeSecurity and turned security off:
int ret = CoInitializeSecurity(IntPtr.Zero, -1, IntPtr.Zero, IntPtr.Zero, 1,
3, IntPtr.Zero, 0, IntPtr.Zero);
This seemed to do the trick.
I now have my object instanciated, but I don't know what to cast it to. I
have tried using tlbimp to import the type information, but that doesn't
work. I also tried to create an interface definition manually to no avail.
This COM component is all custom interfaces, I don't know if this makes a
difference.
I am thinking I may have to write an automation component to talk to this
one and call that from my managed code.
Any thoughts?
> What type of application is the C# code in? Is it a Windows Service or
> ASP.NET? It sounds like you may be running into an Access Permissions
[quoted text clipped - 7 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
David Stucki [MS] - 27 Aug 2003 21:14 GMT
If the COM object has an associated Type Library you can use TLBIMP.exe or
Add a project reference to have an interop assembly generated
automatically. Or you can define an interface manually like this:
// Here's the IDL:
// [
// odl,
// uuid(C2B41384-A3E6-4E22-9A36-8B78C8D4FCC0),
// version(1.0),
// hidden,
// dual,
// nonextensible,
// oleautomation
// ]
// interface _Test : IDispatch
// {
// [id(0x60030000)]
// HRESULT GetArray([out, retval] SAFEARRAY(BSTR)* );
// };
[
ComImport(),
Guid("C2B41384-A3E6-4E22-9A36-8B78C8D4FCC0"),
InterfaceTypeAttribute(ComInterfaceType.InterfaceIsDual),
]
interface ITest
{
[DispId(0x60030000)]
[return : MarshalAs(UnmanagedType.SafeArray,
SafeArraySubType=VarEnum.VT_BSTR)]
Array GetArray();
}
Once you have a managed definition of the interface you can cast the object
returned from the CreateInstance call to that interface and a
QueryInterface will take place under the covers.
David Stucki
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.