473,388 Members | 1,327 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

InvokeMember

boolResult =
(bool)typeofobj.InvokeMember("ReadString",BindingF lags.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?
Nov 15 '05 #1
5 12540
Chris <jt******@comcast.net> wrote:
boolResult =
(bool)typeofobj.InvokeMember("ReadString",BindingF lags.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?


What are you invoking? What's the signature? My guess is that the last
parameter is passed by reference. strResult won't have changed, but the
contents of the array will have done. Unfortunately you're then
throwing the array away, effectively.

Try doing this instead:

object[] parameters = new object[]
{HKEY_CURRENT_USER, "Software\\Example Reg Path",
"Example String Value", strResult};

boolResult = (bool) typeofobj.InvokeMember ("ReadString",
BindingFlags.InvokeMethod, null, newobj, parameters);

strResult = (string) parameters[3];

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #2
That still returns null, strResult is suppose to be set by the object. I do
know that it's executing right etc, because boolResult is True.

E.g. in Delphi:

boolResult := AESreg.ReadString(HKEY_CURRENT_USER, 'Software\Example Reg
Path', 'Example String Value', strResult);

ShowMessage('Read result = ' + strResult)

Any ideas?

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Chris <jt******@comcast.net> wrote:
boolResult =
(bool)typeofobj.InvokeMember("ReadString",BindingF lags.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?


What are you invoking? What's the signature? My guess is that the last
parameter is passed by reference. strResult won't have changed, but the
contents of the array will have done. Unfortunately you're then
throwing the array away, effectively.

Try doing this instead:

object[] parameters = new object[]
{HKEY_CURRENT_USER, "Software\\Example Reg Path",
"Example String Value", strResult};

boolResult = (bool) typeofobj.InvokeMember ("ReadString",
BindingFlags.InvokeMethod, null, newobj, parameters);

strResult = (string) parameters[3];

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #3
Chris wrote:
boolResult =
(bool)typeofobj.InvokeMember("ReadString",BindingF lags.InvokeMethod,
null, newobj, new object[]{HKEY_CURRENT_USER, "Software\\Example Reg
Path", "Example String Value", strResult});


Why such a convoluted approach to reading registry values when that
functionality is inherent to the framework?

--
There are 10 kinds of people. Those who understand binary and those who
don't.

http://code.acadx.com
(Pull the pin to reply)
Nov 15 '05 #4
Chris <jt******@comcast.net> wrote:
Signature is:

HiveKey, Registry Path, Key, Returned Value (of the key)
No, please give us the *full signature* - with type information.
Reason why I said that is because HKEY_CURRENT_USER is used in WriteString
method, and it works fine is all.

If I use:

boolResult =
(bool)typeofobj.InvokeMember("ReadString",BindingF lags.InvokeMethod, null,
newobj, new object[]{HKEY_CURRENT_USER, "Software\\Example Reg Path",
"Example String Value", strResult})

It returns True, so I know it's reading the registry, just strResult is
null.

When I use the new method :

object[] parameters = {HKEY_CURRENT_USER, "Software\\Example Reg Path",
"Example String Value", strResult};
ParameterModifier mods = new ParameterModifier(parameters.Length);

mods[3] = true;
object retVal = typeofobj.GetType().InvokeMember ("readstring",
BindingFlags.InvokeMethod, null, newobj, parameters, new
ParameterModifier[]{ mods }, null, null);

I get the: object does not match target type.


I don't *think* that's how you're meant to use ParameterModifier, but I
can't say I've actually used it myself. I would use it by creating 4
instances of ParameterModifier - you've only got one. In particular,
the docs specify that "the args array and the modifiers array have the
same length".

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #5

"Chris" <jt******@comcast.net> wrote in message
news:EO********************@comcast.com...
Signature is:

HiveKey, Registry Path, Key, Returned Value (of the key)

Reason why I said that is because HKEY_CURRENT_USER is used in
WriteString
method, and it works fine is all.

Ok, that bring's us back to the fourth parameter. It's hard to know for
sure without you posting the signature, but I guess it's a VARIANT*.

Versions 1.0 and 1.1 of the framework don't have the possibility to marshal
Variants byref. If this is the case, your only option is to use the FCL to
read from the registry.

Willy.

Nov 15 '05 #6

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

Similar topics

0
by: Jared Hagel | last post by:
I can't use Type.InvokeMember(...) on a remote object. But when I use Type.InvokeMember(...) on a non-remote object in the exact same way, I don't have a problem. Does someone know what I'm...
0
by: Alex Zhitlenok | last post by:
Hi, On Google, one can find a lot of statements that Invoke and InvokeMemeber work alike. However, my own experience contradicts this statement. 1. Surprisingly, Invoke and InvokeMember methods...
1
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...
0
by: Pat Ireland | last post by:
I continue to investigate issues with making explicit InvokeMember calls (necessary when dynamically loading classes). My quest lets me use a simple class to invoke another class's member method...
3
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...
3
by: Pat Ireland | last post by:
The following code shows what I am trying to do. The normal invocation of the CalcByRef produces the correct results, however, using the InvokeMember fails to correctly pass the single argument by...
4
by: Howard Kaikow | last post by:
I am trying to retrive some WMI properties using Option Strict On. This requires the use of InvokeMember. I know that there are alternative ways to get the values, but I want to learn how to...
1
by: tommyk | last post by:
I am writing a small program that reads a text file filled with a large number of IP addresses and attempts to add them to IIS so that they will be blocked. For some reason, about one in every...
4
by: adiel_g | last post by:
I am trying to set a value on a structure object dynamically using InvokeMember. After I call InvokeMember, the value on the Admin flag does not get updated. Here is the following sample code to...
0
by: Cliff | last post by:
All, I'm not new to C# but I am new to the concept of calling a member using Interop. I can access 1 function and properties in an external dll no problem....but I can't understand how I'm...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
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...

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.