CString to System::String + MFC Q
-
Hi, I am trying to write a very simple application that mixes MFC with C++ Managed. I have two questions: 1. Is it possible to build the mixed project with the MFC library statically linked. I get some errors of conflict which I don't get when building with dynamically linked. 2. I want to use .NET functions that ask for System::String^ str. When I supply these functions with CString I get error. I read every where that it suppose to work. CString str = _T("Works"); CString str2 = _T("Doesn't Work"); String ^ stringEx = gcnew String( str ); // OK :) strinEx = str2; // Is not working :omg: Thanks. -- modified at 4:32 Thursday 20th April, 2006 eladbo
-
Hi, I am trying to write a very simple application that mixes MFC with C++ Managed. I have two questions: 1. Is it possible to build the mixed project with the MFC library statically linked. I get some errors of conflict which I don't get when building with dynamically linked. 2. I want to use .NET functions that ask for System::String^ str. When I supply these functions with CString I get error. I read every where that it suppose to work. CString str = _T("Works"); CString str2 = _T("Doesn't Work"); String ^ stringEx = gcnew String( str ); // OK :) strinEx = str2; // Is not working :omg: Thanks. -- modified at 4:32 Thursday 20th April, 2006 eladbo
Hi, You cannot assign an CString object to a string. Every string assignment in .NET creates a new string on the garbage collector and recycles the old one. There is no global defined assignment operator for this available :(. You could try to write: strinEx = gcnew String(str); This makes no difference to the other assignment.
-
Hi, I am trying to write a very simple application that mixes MFC with C++ Managed. I have two questions: 1. Is it possible to build the mixed project with the MFC library statically linked. I get some errors of conflict which I don't get when building with dynamically linked. 2. I want to use .NET functions that ask for System::String^ str. When I supply these functions with CString I get error. I read every where that it suppose to work. CString str = _T("Works"); CString str2 = _T("Doesn't Work"); String ^ stringEx = gcnew String( str ); // OK :) strinEx = str2; // Is not working :omg: Thanks. -- modified at 4:32 Thursday 20th April, 2006 eladbo
Hi, The answer to the first question is probably that it is impossible to do static linking since the code produced for managed application is not native binary code but MSIL. For different string conversions check following article: http://msdn2.microsoft.com/en-us/library/ms235631.aspx Max
-
Hi, I am trying to write a very simple application that mixes MFC with C++ Managed. I have two questions: 1. Is it possible to build the mixed project with the MFC library statically linked. I get some errors of conflict which I don't get when building with dynamically linked. 2. I want to use .NET functions that ask for System::String^ str. When I supply these functions with CString I get error. I read every where that it suppose to work. CString str = _T("Works"); CString str2 = _T("Doesn't Work"); String ^ stringEx = gcnew String( str ); // OK :) strinEx = str2; // Is not working :omg: Thanks. -- modified at 4:32 Thursday 20th April, 2006 eladbo