Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' [modified]
-
I am using C# class library in C++ using C++/CLI mode. I have declared a class member as follows gcroot <> m_objTest; And the following call gives compilation error m_myInterface->GetResults(m_objTest); Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' The following is the prototype of GetResults function in C# void GetResults(ref JobResults jobRes); Help me to solve this error.
modified on Monday, June 28, 2010 12:35 AM
-
I am using C# class library in C++ using C++/CLI mode. I have declared a class member as follows gcroot <> m_objTest; And the following call gives compilation error m_myInterface->GetResults(m_objTest); Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' The following is the prototype of GetResults function in C# void GetResults(ref JobResults jobRes); Help me to solve this error.
modified on Monday, June 28, 2010 12:35 AM
-
I am using C# class library in C++ using C++/CLI mode. I have declared a class member as follows gcroot <> m_objTest; And the following call gives compilation error m_myInterface->GetResults(m_objTest); Error 1 error C2664 : 'cannot convert parameter 1 from 'gcroot<T>' to 'System::IO::Stream ^%' The following is the prototype of GetResults function in C# void GetResults(ref JobResults jobRes); Help me to solve this error.
modified on Monday, June 28, 2010 12:35 AM
Before passing it to the by-ref function, you need to use a temp variable. Example:
ref class Derived : Base
{
String^ _s;
public:
Derived(String^ s):_s(s){}
};void Foo(Derived^% derived)
{
derived = gcnew Derived("From Foo");
}class Native
{
gcroot<Derived^> _derived;public:
void Bar()
{
_derived = gcnew Derived("Before");
Derived^ tmp = _derived;
Foo(tmp);
_derived = tmp;
}
};Regards, Nish
Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application
-
Before passing it to the by-ref function, you need to use a temp variable. Example:
ref class Derived : Base
{
String^ _s;
public:
Derived(String^ s):_s(s){}
};void Foo(Derived^% derived)
{
derived = gcnew Derived("From Foo");
}class Native
{
gcroot<Derived^> _derived;public:
void Bar()
{
_derived = gcnew Derived("Before");
Derived^ tmp = _derived;
Foo(tmp);
_derived = tmp;
}
};Regards, Nish
Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application
-
Yes Exactly i did the same. So there is no option to pass gcroot object as reference to other function?
As far as I know, no. Remember that the by-ref language behavior is implemented at runtime by the CLR whereas the gcroot is an unmanaged wrapper class. So unless the callee is a C++/CLI method expecting a gcroot argument, what you want to do is quite impossible (in my opinion anyway).
Regards, Nish
Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application
-
As far as I know, no. Remember that the by-ref language behavior is implemented at runtime by the CLR whereas the gcroot is an unmanaged wrapper class. So unless the callee is a C++/CLI method expecting a gcroot argument, what you want to do is quite impossible (in my opinion anyway).
Regards, Nish
Blog: blog.voidnish.com Most recent article: An MVVM friendly approach to adding system menu entries in a WPF application