|
There is no such thing as C++ destructors, but you can wrap a __gc class into a __nogc one that can implement reference counting for you.
|
|
|
|
|
Nemanja Trifunovic wrote:
There is no such thing as C++ destructors
I'm assuming you mean that there are no destructors in managed classes since we've used destructors in native classes for years. Even then, yes, there are destructors in managed C++ and as I noted in my reply to the original post you can explicitly call them.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Yes, wrong wording, sorry. What I meant is that we don't have destructors in __gc classes. We only have functions that look like destructors, but they are really finalizers, not real destructors.
|
|
|
|
|
True. However, even then we're talking a really fine line of differentiation as C++ .NET reference object destructors are invoked when the object is deallocated and can be manually invoked via the C++ delete operator.
Krista
"Who doesn't bend before the wind is mighty apt to break."
Author Unknown
|
|
|
|
|
Hi all
I'm trying to use a UnmanagedC++ class in my MC++ application.The unmanaged class internally using CString class as member variables.I'm converting the String to LPCTSTR and passing it as a parameter to the methods of the unmanaged class.There i'm getting access voilations on CString class GetData()method(this is inside the class CString).Can anybody help me how to solve this problem and what are all the other settings needed.(in project options i have enbaled using MFC in dynamic libraries).
Thanks You
Rgds
Krishna
|
|
|
|
|
Are you making sure to pin the String object's memory so that the GC doesn't move it once you've converted it? For example, the following code would convert a String to a __wchar_t type (note the pin keyword).
<br />
#include <vcclr.h><br />
String* s = S"Hello";<br />
const __wchar_t __pin * str = PtrToStringChars(s);<br />
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
I'm not using that method for conversion.My code looks like this
LPCTSTR _pszFileName = 0;
_pszFileName = static_cast<LPCTSTR>(const_cast<void*>(static_cast<const void*>(Marshal::StringToHGlobalAnsi(m_FileName))));
this->m_pUnManageClass->SetFilePath(_pszFileName);
//inside the unmanaged class i have a member variable of type CString
// m_strFilePath = _pszFileName.
Marshal::FreeHGlobal(static_cast<IntPtr>(const_cast<void*>(static_cast<const void*>(_pszFileName))));
after this,any operation on the CString variable causing access voilation at GetData() member of the CString template class.
Thank You verymuch
Rgds
Krishna
|
|
|
|
|
|
And since we know that your method is not working, have you tried my suggestion?
C'mon Tom, this is not an answer... What's wrong with his code???
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Why are you using LPCTSTR -- shouldn't LPSTR be used?
Your Unmanaged MFC implementation: is it Unicode? If yes it may explain the reason of problem: StringToHGlobalAnsi converts to Ansi(single byte) -- while your unmanaged MFC maybe expecting Unicode...
Just my 2 cents
"...Ability to type is not enough to become a Programmer. Unless you type in VB. But then again you have to type really fast..."
Me
|
|
|
|
|
Hi all
I'm trying to use a UnmanagedC++ class in my MC++ application.The unmanaged class internally using CString class as member variables.I'm converting the String to LPCTSTR and passing it as a parameter to the methods of the unmanaged class.There i'm getting access voilations on CString class GetData()method(this is inside the class CString).Can anybody help me how to solve this problem and what are all the other settings needed.(in project options i have enbaled using MFC as dynamic libraries).
Thanks You
Rgds
Krishna
|
|
|
|
|
Hello
Is there some way how to use windows forms or some third party .net controls and components in my MFC application?
I have a application, with MFC and COM controls and I' d like to use there some third party .NET components.
In all MS examples for MC++, there is only shown,. how to create applicatino, that opens new window with this windows forms controls.
Thanks
|
|
|
|
|
I've subclassed a textbox to create a texbox box that only allows numbers. I am using Version 2003 and I was wondering how I can get the subclassed text box to be visible in the form view, so that I can add them in the form view.
Thanks
|
|
|
|
|
Can you still use delete instead of leaving memory for the Garbage Collector? If so and you delete an object will the GC still work normally?
|
|
|
|
|
You can call the delete function of a managed object, but it won't actually be deleted until the next GC cycle.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
I heard that the compiler is confussed whith the use of MessageBox in Windows::Forms. Can anybody tell me what is the correct precompiler directive for the correct use of MessageBox Class in Windows::Forms???
THANK YOU, VERY MUCH
|
|
|
|
|
If you're trying to use the MessageBox class in a mixed mode app you'll run into compiler error because the WinUser.h file contains a #define that maps the MessageBox name to either the MessageBoxA (marshals the passed string to ANSI) or MessageBoxW (marshals the passed string to wide character format, or Unicode) function based on the project's defined character set option. If this is the case you have two options:
1) If you'll never use the Win32 MessageBox function, simply #undef it in the stdafx.h file.
<br />
#undef MessageBox<br />
2) If you only want to #undef the MessageBox within a given context, you can do the following:
<br />
#pragma push_macro("MessageBox")<br />
#undef MessageBox<br />
#pragma pop_macro("MessageBox")<br />
If you're writing a purely managed application, I don't think it's an issue but I never write managed only C++ apps so I'm not sure.
Cheers,
Tom Archer
Inside C#, Extending MFC Applications with the .NET Framework
It's better to listen to others than to speak, because I already know what I'm going to say anyway. - friend of Jörgen Sigvardsson
|
|
|
|
|
Thank you Tom. It's OK :
|
|
|
|
|
hi, i'm playing with CCW now - written a dummy managed C++ class lib, wrap it up in COM using RegAsm.exe - which generated a tlb (type library) file. The tlb is #import'ed into my WIN32 C++ client application.
#import "..\shared_bin\Sh*tty.tlb"
int _tmain(int argc, _TCHAR* argv[])
{
CoInitialize(NULL);
USES_CONVERSION;
NetLib::INetLibPtr obj( __uuidof(NetLib::NetLibServ));
char * msg = OLE2A(obj->NetLibMethod(0));
printf("Response from NetLib: %s\n", msg);
return 0;
}
I got it working, but that's after a long hard struggle: THE PROBLEM IS:
if namespace in "class library" is different from "project name", Intellisense won't give you the exposed "class":
ie. this won't work and you'll get compiler error:
NetLib::NetLibServ (this is referencing the exposed "class". Intellisense won't work also)
Any idea? It was okay after I changed namespace of class library to that of project name, things work just fine.
norm
|
|
|
|
|
norm wrote:
I got it working, but that's after a long hard struggle: THE PROBLEM IS:
if namespace in "class library" is different from "project name", Intellisense won't give you the exposed "class":
ie. this won't work and you'll get compiler error:
NetLib::NetLibServ (this is referencing the exposed "class". Intellisense won't work also)
Any idea?
I did my work through an interface, maybe my article: Creating a CCW for COM enabled non .NET applications[^] would help? Check under the MFC example I list at the bottom. HTH.
-Nick Parker
|
|
|
|
|
i got my code working, just dont understand why if "namespace"!="project name", then your "class" don't get registered by Intellisense. As a result, you cant call __uuid.
Weird. Was looking for people who had experienced same thing.
norm
|
|
|
|
|
I recommend Visual Assist .NET if you find Ms intelisense doesn't make sense to you. It is a nifty tool.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Hi, anyone can convert this C# statement to C++?
object [] objArgs = new object[] {123,23,45,265};
The following didn't work:
Object * args[] = new Object[] {1,2,3,4,5};
Thanks.
norm
|
|
|
|
|
|