Parameter Passing from VB .NET to a DLL function (in C++/CLI)

V

vijay.gandhi

Hello,

I have created a function in C++/CLI which was exported as a .DLL to
be used in VB .NET. I have been having some problems (I think it has
to do with the right syntax) with parameter passing across the
languages. Can somebody help me please. Details are given below:

The function ComputeMedian(x,y,m_x,m_y) is supposed to have two input
parameters: x, y - both are array of double; and two output
parameters: m_x, m_y - both are just double.

On my C++/CLI side, it is declared as:

double ComputeMedian(array<double>^ x, array<double>^ y, double^
median_x, double^ median_y);

where I assign the values as
*median_x = <function returning median of x[]>
*median_y = <function returning median of y[]>

On my VB.NET side, it is called as:

ComputeMedian(testNumbers, testNumbers, median_x, median_y)

where:
Dim median_x, median_y As New Double
Dim testNumbers() As Double = New Double() {5.0, 3.7, 1.2, 7.6}


The problem is I don't see the values being passed for median_x and
median_y on the VB side. I have debugged the problem and the C++/CLI
program calculates the right values.

Thanks in advance!
Vijay.
 
B

Branco Medeiros

vijay said:
I have created a function in C++/CLI which was exported as a .DLL to
be used in VB .NET. I have been having some problems (I think it has
to do with the right syntax) with parameter passing across the
languages. Can somebody help me please. Details are given below:

The function ComputeMedian(x,y,m_x,m_y) is supposed to have two input
parameters: x, y - both are array of double; and two output
parameters: m_x, m_y - both are just double.

On my C++/CLI side, it is declared as:

double ComputeMedian(array<double>^ x, array<double>^ y, double^
median_x, double^ median_y);

where I assign the values as
*median_x = <function returning median of x[]>
*median_y = <function returning median of y[]>

On my VB.NET side, it is called as:

ComputeMedian(testNumbers, testNumbers, median_x, median_y)

where:
Dim median_x, median_y As New Double
Dim testNumbers() As Double = New Double() {5.0, 3.7, 1.2, 7.6}

The problem is I don't see the values being passed for median_x and
median_y on the VB side. I have debugged the problem and the C++/CLI
program calculates the right values.

I'm not familiar with the CLR extensions to C++, but here it goes
(take it with a grain of salt):

In your C++ declaration, it seems you're just declaring boxing
reference parameters, and not actual "ByRef" parameters. I ***guess***
the function declaration should be changed to:

double ComputeMedian(array<double>^ x, array<double>^ y,
double% median_x, double% median_y);

This declares two "trackable references" (in C++ CLR lingo), which you
must access as simple variables. Therefore, no *median_x or *median_y
syntax:

median_x = <function returning median of x[]>
median_y = <function returning median of y[]>

HTH.

Regards,

Branco.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top