Please help me with this... it's a nasty problem!

I'm converting a DLL-test tool for the company I work for, originally build in VB6, to VB.NET
In the old tool the method CallByName is used to invoke a method in the DLL:

CallByName(objDLL, strFunction, VbMethod, arrParameters)

The arrParameters can be (one or more) IN parameters, OUT parameters or IN/OUT parameters
In the old VB6 tool the arrParameters array is correctly filled with the results from the DLL method but in VB.NET it is not.

I looked it up in the MSDN documentation and noticed that CallByName (in .NET) sends the paremeters ByVal so that explains why it does not work anymore. (I presume in VB6 the parameters where send ByRef )

However, I have a problem now, because I need the parameters to be send ByRef.

I also tried the .NET method InvokeMember but this has the same problem.
I even included the parameter modifier (convinced this was the solution I needed) but no cigar... :confused:

'Set parameter modifier: handle all parameters as reference

Dim p As New ParameterModifier(parameters.Count)

For i = 0 To parameters.Count - 1
    p(i) = True
Next
Dim mods() As ParameterModifier = {p}

Dim a As Object
'Call the DLL method
a = _currentApi.GetType().InvokeMember(method, BindingFlags.InvokeMethod, Nothing, _currentApi, parameters, mods, Nothing, Nothing)

Does someone know what the problem is in this case and more importantly: how to solve this?!

Thanks a lot for any help... this is a showstopper for me! :(

Sorry, I don't quite get what you mean...
Could you please be more specific?

I remember when I used JAVA, there's no passing by reference there; to overcome this problem we where create array from the object data type which we need to pass and send to the method it as array[0]

Example
public void xyz(int x)
{
}
/// I don't have 'ref' so
int[] arrayIntegers = new int[1];
arrayIntegers[0] = x;
xyz(arrayIntegers[0]);

Actually, parameters is an array with parameters!

I know the methods in the COM object I call have reference parameters (it also works in VB6).

According to the MSDN information about InvokeMethod I should use an ParameterModifier array to define the parameters as references instead of values but this does not work for me...

I'm looking for the reason why...

This article has been dead for over six months. Start a new discussion instead.