473,766 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reflection, InvokeMember, and the blasted ParameterModifi er

We have a VB6 COM component that I don't have control over. All of the
values are returned from method calls using byref parameters. They
frequently break binary compatibility, in fact, there are three different
versions of the component, one for dev, one for test, and one for
production, all of which are broken with each re-compile, which means I
can't use early binding and COM interop. Ugh.

Using InvokeMember, how do I get values from an out parameter? I saw the
documentation about ParameterModifi er, but I'm afraid that I just don't get
it. :) A code sample would be appreciated.

Here's the code I have so far (the Response.Write value returns an empty
string as the return value, which isn't valid):

Type commonLogonType =
Type.GetTypeFro mProgID("ADESec urity.CSecurity ");

object commonLogon=
Activator.Creat eInstance(commo nLogonType);

arrayInput = new Object[] {""};
commonLogonType .InvokeMember(" GetUserRightsAs XML",BindingFla gs.InvokeMethod ,
null,commonLogo n,arrayInput,mo ds,null,null);

Response.Write( "Returned XML value=" +
Convert.ToStrin g(arrayInput[arrayInput.GetL owerBound(0)]));

Response.End();

}

Here's the VB method call (the return value is a 0 or non-zero value
indicating success or failure of the call, r_szXMLResult is the actual value
that is returned):

Public Function GetUserRightsAs XML(ByRef r_szXMLResult As Variant, _
Optional ByVal p_szXMLRootName As Variant
= "adesecurityper missions", _
Optional ByVal p_lEntityID As Variant =
0, _
Optional ByVal p_bDebugDisplay As Boolean
= False _
) As Variant

Any help would be greatly appreciated.

Robert
Nov 15 '05 #1
1 5174
Figured it out--here's my post from the General newgroup:

It must be something to do with COM. For example, the documentation on
invoke memeber says the following:

ParameterModifi er is only used when calling through COM interop, and only
parameters that are passed by reference are handled.

So I need to be able to send in a parameter modifier that tells COM that
this is an out parameter, but I don't know how to use the ParameterModifi er.
All it has is an integer that tells how many parameters to modify.

Ah hah! I just figured it out, and it's not terribly intuitive. The help
states in several places that you can set the parameter modifier to pdout,
pdin, pdlcid, etc . . . However, this is in reference to what the binder
does with COM code, not to the parameter modifier itself. It can only be
set to true or false, which I'm guessing simply tells the binder that it
should check to see if a variable is passed by reference. What fun.

As to the GetLowerBounds call, I'm a vb hack, and can never keep my bounds
straight . . . :). It's been changed. Here's the invoke member code that
actually works (starting with the definition of the arguments):

arrayInput = new Object[] {""};

ParameterModifi er[] mods=new ParameterModifi er[1]{new ParameterModifi er(1)};

mods[0][0] = true;

commonLogonType .InvokeMember(" GetUserRightsAs XML",BindingFla gs.InvokeMethod ,
null,commonLogo n,arrayInput,mo ds,null,null);

Thanks for your help.
Robert

"Robert May" <ra******@donts pamhotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
We have a VB6 COM component that I don't have control over. All of the
values are returned from method calls using byref parameters. They
frequently break binary compatibility, in fact, there are three different
versions of the component, one for dev, one for test, and one for
production, all of which are broken with each re-compile, which means I
can't use early binding and COM interop. Ugh.

Using InvokeMember, how do I get values from an out parameter? I saw the
documentation about ParameterModifi er, but I'm afraid that I just don't get it. :) A code sample would be appreciated.

Here's the code I have so far (the Response.Write value returns an empty
string as the return value, which isn't valid):

Type commonLogonType =
Type.GetTypeFro mProgID("ADESec urity.CSecurity ");

object commonLogon=
Activator.Creat eInstance(commo nLogonType);

arrayInput = new Object[] {""};
commonLogonType .InvokeMember(" GetUserRightsAs XML",BindingFla gs.InvokeMethod , null,commonLogo n,arrayInput,mo ds,null,null);

Response.Write( "Returned XML value=" +
Convert.ToStrin g(arrayInput[arrayInput.GetL owerBound(0)]));

Response.End();

}

Here's the VB method call (the return value is a 0 or non-zero value
indicating success or failure of the call, r_szXMLResult is the actual value that is returned):

Public Function GetUserRightsAs XML(ByRef r_szXMLResult As Variant, _
Optional ByVal p_szXMLRootName As Variant = "adesecurityper missions", _
Optional ByVal p_lEntityID As Variant =
0, _
Optional ByVal p_bDebugDisplay As Boolean = False _
) As Variant

Any help would be greatly appreciated.

Robert

Nov 15 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
14451
by: Robert May | last post by:
We have a VB6 COM component that I don't have control over. All of the values are returned from method calls using byref parameters. They frequently break binary compatibility, in fact, there are three different versions of the component, one for dev, one for test, and one for production, all of which are broken with each re-compile, which means I can't use early binding and COM interop. Ugh. Using InvokeMember, how do I get values...
5
12559
by: Chris | last post by:
boolResult = (bool)typeofobj.InvokeMember("ReadString",BindingFlags.InvokeMethod, null, newobj, new object{HKEY_CURRENT_USER, "Software\\Example Reg Path", "Example String Value", strResult}); This returns True, which means the method was executed fine, but strResult is empty, it's suppose to be what it read. Any ideas?
1
1978
by: George Lewis | last post by:
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:
1
6138
by: Rein Petersen | last post by:
Hi All, I'm invoking Type.InvokeMember() on a COM class (via COMInterop) through a generalized interface. However, each specialized instance (of the COMInterop generic interface) requires slightly different arguments for which I dynamically create the object arguments and it all works nicely. Problem is, in some instances, I have methods which require certain arguments to be referenced (ref string x,...etc). I'm not sure how I can...
5
2929
by: Stan | last post by:
All, I am trying to access a complex COM library with nested COM classes. In order to get at a certain class you must call a method on class A and this method will return a instance of COM class B. FOr instance the VB code looks like this: Public Function GetFee(sFeeCode As String) As Test.FeeCls .... End Function
12
6998
by: Gus | last post by:
Hi, I´m triying to invoke a member using reflection, but this member requiere two parameters, the first patrameter is a string and the second is a reference to a dataset (output parameter). The parameters has to be passed in an array of objects. I´ve tried something like this: object parameters = new object; parameters ="text";
3
2323
by: Patrick Ireland | last post by:
I am dynamically loading a class. One of the methods of the class takes a short * (by reference) argument. However, the InvokeMember call used to invoke the method of the class passings arguments in and object . Since this is a pointer reference being passed it must be invoked in a unsafe {} even thought the dynamically loaded class is a .Net entity. The following is the test code that I am using to try and load a short * into an object:...
2
2174
by: Marek | last post by:
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:
6
1855
by: bill | last post by:
All, I have an unmanaged data structure that I use to pass to an umanaged DLL written in C. This works great. The structure looks sort of like this: unsafe public struct Inputs { .....
0
9404
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10008
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9837
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7381
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6651
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5279
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5423
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.