I'm working on someone else's code, which currently works, but I need to add some functionality.
It uses CoCreateInstance to instantiate some COM objects which seem to implement the IUnknown interface, but QueryInterface is not accessible. I'm not as familiar with C# as other languages, so maybe there's something obvious I'm missing. I'll try to keep this brief and only post what I think are the relevant snippets of code...
It tells me that the INetCfg interface does not have a QueryInterface method. Iv'e tried to manually add that method to the INetCfg definition, as such:
With that added I get a value outside of expected range exception when it tries to call QueryInterface. But I shouldn't have to manually add that method if it's part of the base interface, should I?
It uses CoCreateInstance to instantiate some COM objects which seem to implement the IUnknown interface, but QueryInterface is not accessible. I'm not as familiar with C# as other languages, so maybe there's something obvious I'm missing. I'll try to keep this brief and only post what I think are the relevant snippets of code...
Code:
[COLOR=#4E9A06]//the DllImport:[/color]
[DllImport("ole32.Dll")]
static public extern int CoCreateInstance(ref Guid clsid,
[MarshalAs(UnmanagedType.IUnknown)] object inner,
uint context,
ref Guid uuid,
[Out, MarshalAs(UnmanagedType.IUnknown)] out object rReturnedComObject);
[COLOR=#4E9A06]//an example of one of the interface definitions:[/color]
[Guid("C0E8AE93-306E-11D1-AACF-00805FC1270E"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[ComVisible(true)]
public interface INetCfg
{
int Initialize(IntPtr pvReserved);
int Uninitialize();
int Apply();
int Cancel();
int EnumComponents([In]ref Guid pguidClass, [Out, MarshalAs(UnmanagedType.IUnknown)] out object ppenumComponent);
int FindComponent([In, MarshalAs(UnmanagedType.LPWStr)] string pszwInfId,
[Out, MarshalAs(UnmanagedType.IUnknown)] out object pComponent);
int QueryNetCfgClass([In]ref Guid pguidClass,
ref Guid riid,
[Out, MarshalAs(UnmanagedType.IUnknown)] out object ppvObject);
};
[COLOR=#4E9A06]// what I need to be able to do:[/color]
int hReturn = 0;
object tempObj1 = null;
hResult = CoCreateInstance(ref CLSID_CNetCfg, null, CLSCTX_INPROC_SERVER, ref IID_INetCfg, out tempObj1);
INetCfg InetCfgObj = tempObj1 as INetCfg;
object tempObj2 = null;
[b]hResult = InetCfgObj.QueryInterface(IID_INetCfgLock, tempObj2);[/b]
INetCfgLock LockObj = tempObj2 as INetCfgLock
It tells me that the INetCfg interface does not have a QueryInterface method. Iv'e tried to manually add that method to the INetCfg definition, as such:
Code:
int QueryInterface([In]ref Guid pguidClass, [Out, MarshalAs(UnmanagedType.IUnknown)] out object ppvObject);
With that added I get a value outside of expected range exception when it tries to call QueryInterface. But I shouldn't have to manually add that method if it's part of the base interface, should I?