I love using dynamic
variables for accessing COM objects. However I have a problem with one object. See the following code working in VBS:
WScript.Echo "Nazwa firmy: " & itg.FirmaInfo.Nazwa
itg
is a specific object that works basically equally well in vbscript and in c# using dynamic variables. Until I try to use the member FirmaInfo
. Seems like it is a very special member which requires QueryInterface
call. When I was accessing it through Jacob it was in this way:
static final String sIFirmaInfo = "{3F707848-DC7D-4B37-A4C8-7270644020F7}";
ActiveXComponent fi0 = itg.getPropertyAsComponent("firmainfo");
fi = new ActiveXComponent(fi0.QueryInterface(sIFirmaInfo));
fi0.safeRelease();
// now I am able access Nazwa member of fi
I can't find a way to do this in c#. When I do a simple approach:
Console.WriteLine(itg.FirmaInfo.Nazwa)
I get an error:
Unhandled Exception: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'System.__ComObject' does not contain a definition for 'Nazwa'
at CallSite.Target(Closure , CallSite , ComObject )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)
at Itg.open(String sKatFirmy, String sUser, String sPass) in w:\introl\prozapbi\Itg.cs:line 100
I know I could try a static client to COM object, but I am not familiar with this technique. Maybe I can stay with my dynamic approach, but need just a 3 suitable lines of code? Something that would turn my FirmaInfo object to one that exposes the IFirmaInfo
interface.