M
mclp
Hi. Just joined this group and I don't think this had been addressed
before..
I have a VB.NET class library assembly "xyz.dll" that I want to access
from some unmanaged code in an MFC DLL (contained in a cpp file
compiled with /clr) via:
#include <vcclr.h>
#using "xyz.dll"
using namespace System;
using namespace xyz;
...
gcroot<Moo^> boo = gcnew Moo;
My VB.NET assembly contains:
Public Class Moo
Public Sub Foo(ByRef s as String)
End Class
If I try to get to it using...
CString& mfcstr;
gcroot<String^> str = gcnew String(mfcstr);
boo->Foo(str);
mfcstr = str;
... the compiler complains that gcroot can't supply the reference
parameter (%).
However, if I just use:
CString& mfcstr;
String^ str = gcnew String(mfcstr);
boo->Foo(str);
mfcstr = str;
... then it works fine, but I'm concerned that by not using gcroot to
wrap the String^, that the String^ will not be garbage collected. The
working code does not result in a memory leak, but I'm not quite
satisfied with my understanding. Can anyone enlighten me as to what is
the correct way to handle my reference parameter.
Thanks,
M
before..
I have a VB.NET class library assembly "xyz.dll" that I want to access
from some unmanaged code in an MFC DLL (contained in a cpp file
compiled with /clr) via:
#include <vcclr.h>
#using "xyz.dll"
using namespace System;
using namespace xyz;
...
gcroot<Moo^> boo = gcnew Moo;
My VB.NET assembly contains:
Public Class Moo
Public Sub Foo(ByRef s as String)
End Class
If I try to get to it using...
CString& mfcstr;
gcroot<String^> str = gcnew String(mfcstr);
boo->Foo(str);
mfcstr = str;
... the compiler complains that gcroot can't supply the reference
parameter (%).
However, if I just use:
CString& mfcstr;
String^ str = gcnew String(mfcstr);
boo->Foo(str);
mfcstr = str;
... then it works fine, but I'm concerned that by not using gcroot to
wrap the String^, that the String^ will not be garbage collected. The
working code does not result in a memory leak, but I'm not quite
satisfied with my understanding. Can anyone enlighten me as to what is
the correct way to handle my reference parameter.
Thanks,
M