C# Dll Cannot Affect Value of a Number Passed by Reference from a Vb6 Application

Passing an rvalue as a ByRef parameter to VB6?

What would happen if VB6Function did change the value of input when input is "an rvalue"?

Nothing. Or rather, nothing interesting.

When the called function changes the value of its argument, it makes no difference for the insides of that function whether the argument was provided byval or byref. All that matters is that there is a variable of certain type, thus, it can be acted upon.

For that matter, why doesn't this method invocation simply error out when "an rvalue" is passed?

Why would it error out? The passed argument as correct type (string), that is all that matters.

There is no notion of an rvalue in VB.

When you pass what you would call an rvalue to a method accepting something by reference, the compiler automatically passes the reference to a temporary location where the rvalue actually resides. The method gets its value byref, the caller does not care about pointers.

localString.Trim() allocates and returns a string. It has an address and can be passed around. Your code does not explicitly capture that address, but the compiler has no problem passing it to VB6Function byref. If VB6Function changes the value, it changes what that temporary location points to, which has no observable difference because it's going to be destroyed after the call either way.

As for why some people may have preferred receiving strings byref in VBA, it's specifically to avoid copying the entire string each time when calling the function. In VB.NET it's not a problem because strings there are immutable and therefore can be passed byval without copying, but in VBA that is not the case, so a byval string needs to be cloned for the purpose of the call. People avoided that by specifying byref, even though that technically gave them the power to mess with the passed variable.

not able to convert this code from vb6 to vb.net - SET string = New Application

"Set" is no longer an object assignment keyword. Instead you can do

Dim currentVersion As cApplication = New Application()

or

Dim currentVersion As cApplication
currentVersion = New Application()

assuming cApplication is a compatible type with Application. Both ways create an "Application" object and assign it to the currentVersion variable.

You would then call using

currentVersion.getLatestVersion(3, 4, 5)

VB.NET has changed a lot of syntax in this way--you may want to get a text to help you along with all the changes.

How do I pass an Array (By Reference, in VB6) to a C\C++ *.dll subroutine?

From http://msdn.microsoft.com/en-us/library/aa381230(VS.85).aspx:

Dim returnVal
Dim outArgs(1)
Dim args(1)
args(0) = 3
returnVal = service.InvokeAction("GetTrackInfo", args, outArgs)
'return Val now contains the track length
'and outArgs(0) contains the track title
Dim emptyArgs(0)
returnVal = service.InvokeAction("Play", emptyArgs, emptyArgs)
'returnVal indicates if the action was successful

Just how you get and instance of service is not clear from this example though.



Related Topics



Leave a reply



Submit