Click here to Skip to main content
15,888,521 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have written a large .NET class library in C++ (using old syntax). It works very well and has been in use with C++, C# and Visual Basic for a while.

Anyway, I just discovered that any method taking an argument that is a reference to a base type is not exposed to Visual Basic.

Let the C++ declaration be
C++
void mVizNET::Histogram::Range(int& Minimum, int& Maximum);

The C++ object browser shows it as
C++
System.Void Range(System.Int32 Minimum, System.Int32 Maximum)
    Member of mVizNET.Histogram
(strangely, the ref keyword is missing).

The C# object browser shows it as
C#
public static void Range(int* Minimum, int* Maximum)
    Member of mVizNET.Histogram
(strangely, the argument is passed as a pointer).

But the Visual Basic object browser does not show it at all :(

Has anyone an explanation ? Is there a special attribute I should give those reference arguments to better expose them ? Is this feature unavailable using the old syntax ? Is it supported in the new syntax ?
Posted

1 solution

I have found a workaround. References can be traded for pointers, provided you use a .NET type instead of a native one.

If you change the prototype to
void mVizNET::Histogram::Range(Int32* Minimum, Int32* Maximum);

then the method appears as
System.Void Range(System.Int32 Minimum, System.Int32 Maximum)
    Member of mVizNET.Histogram

C#
public void Range(ref int Minimum, ref int Maximum)
    Member of mVizNET.Histogram

VB
Public Sub Range(ByRef Minimum As Integer, ByRef Maximum As Integer)
     Member of: mVizNET.Histogram

which is what I need. (Actually, the C++ browser also shows a mVizNET.Histogram.Range(System.Int32@, System.Int32@) declaration, where the @ possibly stands for a C++/CLI reference).

Note that a declaration with references like
void mVizNET::Histogram::Range(Int32& Minimum, Int32& Maximum);

will also work, but is not recognized by the C# browser this time!
 
Share this answer
 
v4
Comments
phil.o 23-Sep-13 6:05am    
5'ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900