Returning good old string parameters with Type.InvokeMember

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi
I need to be able to return a string from a VB6 method:

Public Sub GetMessageAsParameter(ByRef message As String)
message = "GetMessageAsParameter worked!"
End Sub

which is implemented inside an ActiveX DLL. I need to do this using late
binding so I am trying to do it with code like this:

object[] parameters = new object[1];
ParameterModifier parameterModifiers = new ParameterModifier(1);

// Allocate some space for the parameter
parameters[0] = new string(' ', 100);

parameterModifiers[0] = true;
ParameterModifier[] parameterModifier = { parameterModifiers };

comType.InvokeMember("GetMessageAsParameter",
BindingFlags.InvokeMethod, null, comObject, parameters, parameterModifier,
null, null);

Console.WriteLine(String.Format("\nGetMessageAsParameter:
Message={0}", parameters[0].ToString()));

The problem is that I never get anything coming back. I don't get any
TargetInvocationExceptions either. I've tried all the different options of
ByVal and ByRef without success.

Please could anyone advise.

Thanks

Marek
 
Not sure what happened with the previous reply (appears blank), but the fix
for my problem was:

parameters[0] = new StringBuilder(100).ToString();
 

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

Back
Top