tags:

views:

78

answers:

2

I have the following problem: I have a project in C# where I use a third party COM component.

So the problem is that the above component has a method, which takes a string and a number of key-value pairs as arguments. I already managed to call that method through JavaScript like that:

 var srcName
 srcName = top.cadView.addSource( 'Database', { driver : 'Oracle', host : '10.10.1.123', port : 1234, database : 'someSID', user : 'someuser', password : 'somepass' } )
 if ( srcName != '' )
 {
  ...
 }

... and it worked perfectly well. However I have no idea how to do the same using C#. I tried passing the pairs as Dictionary and Struct/Class but it throws me a "Specified cast is not valid." exception. I also tried using Hashtable like that:

Hashtable args = new Hashtable();
args.Add("driver", "Oracle");
args.Add("host", "10.10.1.123");
args.Add("port", 1234);
args.Add("database", "someSID");
args.Add("user", "someUser");
args.Add("password", "samePass");

String srcName = axCVCanvas.addSource("Database", args);

and although it doesn't throw an exception it still won't do the job, writing me in a log file

[ Error] [14:38:33.281] Cad::SourceDB::SourceDB(): missing parameter 'driver'

A: 

Could you pass in a list of delimited strings? Something like

List args = new List()

args.Add("key:value);

e.g. args.Add("driver:Oracle);

JC
I tried that already, does'n work - throws Specified cast is not valid." exception
Sinnerman
A: 

The ACtiveX component is probably using IDispatch or IDispatchEx methods to convert the dynamic type into a list of property names, and then accessing them.

Either find a different type to pass (which will also work) via the vendor or documentation, or you are going to need to implement one of those interfaces yourself (System.Collections.Dictionary doesn't).

Another thing to try is the scripting Dictionary type (you will need to import the correct typelib to get to that type).

Richard
Scripting.Dictionary was a very good idea, I never thought of that, unfortunately no success there. I'll try playing with IDispatchEx and let you know if a I think of something. Thanks for the help Anyway.
Sinnerman