By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,290 Members | 1,253 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,290 IT Pros & Developers. It's quick & easy.

InvokeMember

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a

"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 discussion thread is closed

Replies have been disabled for this discussion.