V
vijay.gandhi
Hi,
I am trying to convert a set of classes written in VC++ 6.0 to a .DLL
file using VC++ .NET (Visual Studio 2005) and C++/CLI.
I made one of the classes (one at the root level) to be a 'ref' class.
This class used pointer to a function. Since CLR does not support a
ref class to have a pointer to a function directly, I changed it to a
'delegate'.
Now the problem is - a function of one of the other classes (and not a
ref class) expects an argument which is supposed to be a pointer to a
function. This argument is returned from a function in the root class.
Now that I have changed the pointer variable to a delegate, the
compiler complains that it cannot convert from one type (delegate,
which the root class function returns) to another (pointer to
function, which the function of the other class expects).
Here is the snippet:
typedef double (* DISTANCE_FUNC) (double x1, double y1, double x2,
double y2);
delegate double delDistanceFunction(double x1, double y1, double x2,
double y2);
public ref class root_class {
delDistanceFunction^ pDistanceFunction;
delDistanceFunction^ getDistanceFunction() {
return pDistanceFunction;
}
}
public class not_a_ref_class {
not_a_ref_class(DISTANCE_FUNC func);
}
This statement used in root_class gives error:
not_a_ref_class narc = new not_a_ref_class(getDistanceFunction());
It will be great if somebody can help me solve this problem.
Thanks in advance for your time,
Vijay.
I am trying to convert a set of classes written in VC++ 6.0 to a .DLL
file using VC++ .NET (Visual Studio 2005) and C++/CLI.
I made one of the classes (one at the root level) to be a 'ref' class.
This class used pointer to a function. Since CLR does not support a
ref class to have a pointer to a function directly, I changed it to a
'delegate'.
Now the problem is - a function of one of the other classes (and not a
ref class) expects an argument which is supposed to be a pointer to a
function. This argument is returned from a function in the root class.
Now that I have changed the pointer variable to a delegate, the
compiler complains that it cannot convert from one type (delegate,
which the root class function returns) to another (pointer to
function, which the function of the other class expects).
Here is the snippet:
typedef double (* DISTANCE_FUNC) (double x1, double y1, double x2,
double y2);
delegate double delDistanceFunction(double x1, double y1, double x2,
double y2);
public ref class root_class {
delDistanceFunction^ pDistanceFunction;
delDistanceFunction^ getDistanceFunction() {
return pDistanceFunction;
}
}
public class not_a_ref_class {
not_a_ref_class(DISTANCE_FUNC func);
}
This statement used in root_class gives error:
not_a_ref_class narc = new not_a_ref_class(getDistanceFunction());
It will be great if somebody can help me solve this problem.
Thanks in advance for your time,
Vijay.