InvokeMember and byte[] parameter

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: George Lewis (ge_lw_at_junia.com)
Date: 03/03/04


Date: Tue, 02 Mar 2004 16:48:57 -0800


Hi,

I am trying to invoke a method from a COM dll using InvokeMember which
has the following signature:

int GetStatus(ref byte[] scannedBytes, System.Int32 length);

However when I try and call this method using a byte[] parameter, I get
a type mismatch error.
The code that I am using here is:

byte[] scannedBytes = GetData(); // Internally returns a byte array

Type type = Assembly.LoadFrom("Interop.Scanner.dll").GetType();
object obj = Activator.CreateInstance(type);
object[] args = new object[]{scannedBytes,scannedBytes.length);

ParameterModifier[] mods = new ParameterModifier[2];
bool[] byref = {true,false};
for (int i = 0; i < 2; i++)
 {
   ParameterModifier m = new ParameterModifier(1);
   m[0] = byRef[i];
   mods[i] = m;
 }

This is the line I am getting "type mismatch" exception.
int result =
type.InvokeMember("GetStatus",BindingFlags.InvokeMethod,null,obj,args,mo
ds,null,new string[]{"scannedBytes","length"});

Can some one please tell me what am I doing wrong.

Thanks,
George

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: Critique
    ... I invoke the program with an int ... > representing a site code and a long representing a date and my ... > with the int and the long I pass in. ... Since you already have a template file, ...
    (comp.lang.c)
  • Re: [MSDOS] Trouble with mouse programming
    ... >> which not only consume a lot of stack but probably also invoke ... All that int 29h does is to invoke the int 10h ... and forgetting a declaration when calling it. ...
    (comp.programming)
  • Re: Random Numbers
    ... but that gave me a type mismatch though everything is an int. ... All I'm trying to get is a 4 digit random number that's random enough ... that it has a low probability of duplicating out of 30 consectutive ...
    (microsoft.public.access.formscoding)
  • Sheet.columns(aa:zz) ,COMException (0x80020005) VSTO Formatting is
    ... system.Runtime.InteropServices.COMException: Type mismatch. ... /// Set individual cell in a workspace into the value ... void SetValue(int r, int c, string s, bool bBold) ...
    (microsoft.public.excel.misc)
  • fails tospecify max Columns size in 2007, InteropServices.COMExcep
    ... system.Runtime.InteropServices.COMException: Type mismatch. ... /// Set individual cell in a workspace into the value ... void SetValue(int r, int c, string s, bool bBold) ...
    (microsoft.public.excel.programming)