473,385 Members | 1,838 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,385 software developers and data experts.

Issue of reference parameter

Tom
Hello all,

I have a problem to consult you and hope your help.

My work case like this:
---------------------
a VB6 COM DLL has a method ,Which has a Byref parameter
for return the changed value of the parameter;
calling the method above in .NET environment,such as c# ;
Using reflection rather than direct calling.
-------------------------------------
the class ProgID of VB6 is: MySimpleTest.TestClass,
the method code is:
-------------
Public Function mymethod(ByVal a As Integer, ByVal b As
Integer, ByRef c As Integer) As Integer
mymethod = a + b
c = a - b
End Function
----------------------------------------
----------------------------------------
the calling code in c# is:
------------
{
int i1 = 15;
int i2 = 6;
int i3 = 3;
object[] args ={i1,i2,i3};

MessageBox.Show(args[2].ToString(), "value of args[2]",
MessageBoxButtons.OK, MessageBoxIcon.None); //show "3"

Type T=Type.GetTypeFromProgID("MySimpleTest.TestClass") ;
object obj = Activator.CreateInstance(T);

string methodName = "mymethod";
bool [] byRef ={false,false,true};

ParameterModifier[] mods = new ParameterModifier[3];
for (int i = 0; i < 3; i++)
{
// create exactly one modifier
ParameterModifier m = new ParameterModifier(1);
m[0] = byRef[i]; // true? call by ref.
mods[i] = m;
}
object retVal = obj.GetType().InvokeMember(methodName,
BindingFlags.InvokeMethod, null, obj , args, mods, null,
null);

MessageBox.Show(retVal.ToString(), "result",
MessageBoxButtons.OK, MessageBoxIcon.None);//show "21"

MessageBox.Show(args[2].ToString(), "value of args[2]",
MessageBoxButtons.OK, MessageBoxIcon.None); //show "3"
//but the expected value of args[2] is "9"!

}
----------------------------------------------------
------------------------------------------------
Excuting the calling,the value of args[2] is still "3"!
Why? This problem bother me badly.

Would you please create the DLL in VB6 and test it ?

An early reply is appreciated.

Best regards.

Tom.

Nov 22 '05 #1
0 677

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

Similar topics

2
by: Mark Stafford | last post by:
I want to use a pop-up dialog for my intranet, but I'm missing something that keeps me from getting along with NS's browsers right now. I get an error to the effect of "opener.formName has no...
9
by: Stuart Carnie | last post by:
Due to the tightening of the VC++ compiler in 2005, I have run into a compiler error (from code that previously worked in 2003) using a CComPtr<ITypeLib> as an element of a std::list, as follows...
2
by: ChrisB | last post by:
Hello, I was wondering what options are available for resolving the following (simplified) scenario. Two project exist and each contains a class: ProjectA - Class1 ProjectB - Class2 ...
1
by: klaul | last post by:
Hi there. I'm having an issue with autopostback, in that it doesn't seem to be working! The webform I am using pulls the data from an AccessDataSource to populate the gridview, which has Edit and...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.