sending object to a com object instead of variant

P

pini_soos

Hi there,
i writing a c# application which call to a com object written in vb.
the function in this object which i call gets as parameter: a variant
array and a variant dsnstring.
i tried to cast my array into object before sending it to the function
but i steel get an exception....
any ideas?
 
M

Mattias Sjögren

i tried to cast my array into object before sending it to the function
but i steel get an exception....
any ideas?

And what exception is that? Can you post your code?



Mattias
 
P

pini_soos

Hi there and thanks for the reply,
first of all i also tried to cast the array into a object and it didnt
work,
second i tried to use Memeber.Invoke and send her as parameter the
ParameterModifier wich tells the calling function how to treat the
arguments( as ref or as val).
i got the exception:
An unhandled exception of type 'System.Exception' occurred in
IvrToIntraTransferrer.exe

Additional information: at
System.RuntimeType.InvokeDispMethod(String name, BindingFlags
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers,
Int32 culture, String[] namedParameters)
at System.RuntimeType.InvokeMember(String name, BindingFlags
invokeAttr, Binder binder, Object target, Object[] args,
ParameterModifier[] modifiers, CultureInfo culture, String[]
namedParameters)
at IvrToIntraTransferrer.IvrToIntraTransferrer.ExtractAndInsert(String
sInterceptionsXml) in e:\inetpub\win
applications\ivrtointratransferrer\ivrtointratransferrer.cs:line 204

here is the code i tried: //an array to be sent to the invoke function
object[] MainArray = new object[2];
//an array to fill the first cell in the MainArray
string[] Array = new string[11];
Array[0] = "IVR Client";
Array[1] = " ";
Array[2] = sPhoneNumber;
Array[3] = "";
Array[4] = sSubjectNum;
Array[5] = "";
Array[6] = "1";
Array[7] = "20";
Array[8] = "System";
Array[9] = "22:30";
Array[10] = "System";

//the dsn string will be in the second place in the array
MainArray[1] = "user id=**;password=****;data
source=someserver;initial catalog=some DB";

//first cell in the array(index 0 will be with the Array.
MainArray[0] = Array;

//get the type of the outgoingcallsSystems object
Type ComObjType;
object ComObj;

//creating an instance of type
OutgoingCallsSystem.InterceptionClass
ComObjType = Type.GetTypeFromProgID("OutgoingCallsSystem.InterceptionClass");
ComObj = Activator.CreateInstance(ComObjType);

ParameterModifier[] ParamMods = new ParameterModifier [2];
ParamMods[0] = new ParameterModifier(11); // inititialize with
number of method parameters

//to tell the invoke function that thearray has to to be sent by
ref
ParamMods[0][0] = true; // set the 1st param to be an byRef
param
ParamMods[0][1] = true; // set the 2nd param to be an byRef
param

try
{
ComObjType.InvokeMember(
"InsertDataToDB", // method name
BindingFlags.Default | BindingFlags.InvokeMethod,
null,
ComObj, // obj being called
MainArray, // argument list
ParamMods, // ParameterModifier array specifying out params
null,
null) ;
}
catch(Exception e)
{
throw new Exception(e.StackTrace);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top