MC++ and CString
-
I have a class that I use in a MFC application. The class uses a lot of CString. Now I want to use it in a MC++ class library to be able to use it in a .Net web application. How do I do it? // CPP_Class_Lib_01.h #pragma once #include "RegUser.h" #pragma managed #using using namespace System; namespace CPP_Class_Lib_01 { public __gc class MCRegUser { private: CRegUser __nogc* m_pCustomer; public: MCRegUser() { m_pCustomer = new CRegUser(); } String* GetNameManaged(String* strName) { return m_pCustomer->GetName(strName); } }; } //-- The file RegUser.h ----------->> #pragma once #pragma unmanaged class CRegUser { public: CRegUser(void); ~CRegUser(void); CString GetName(CString strName); }; //-- The file RegUser.cpp ----------->> #include "StdAfx.h" #include "reguser.h" #pragma unmanaged #include CRegUser::CRegUser(void) { } CRegUser::~CRegUser() { } CString CRegUser::GetName(CString strName) { return strName; }
-
I have a class that I use in a MFC application. The class uses a lot of CString. Now I want to use it in a MC++ class library to be able to use it in a .Net web application. How do I do it? // CPP_Class_Lib_01.h #pragma once #include "RegUser.h" #pragma managed #using using namespace System; namespace CPP_Class_Lib_01 { public __gc class MCRegUser { private: CRegUser __nogc* m_pCustomer; public: MCRegUser() { m_pCustomer = new CRegUser(); } String* GetNameManaged(String* strName) { return m_pCustomer->GetName(strName); } }; } //-- The file RegUser.h ----------->> #pragma once #pragma unmanaged class CRegUser { public: CRegUser(void); ~CRegUser(void); CString GetName(CString strName); }; //-- The file RegUser.cpp ----------->> #include "StdAfx.h" #include "reguser.h" #pragma unmanaged #include CRegUser::CRegUser(void) { } CRegUser::~CRegUser() { } CString CRegUser::GetName(CString strName) { return strName; }
Check out the Marshal .NET class. For example,
Marshal.PtrToStringAnsi Method (IntPtr, Int32)
Which returns a Managed String from unmanaged ansi string. Good luck!R.Bischoff
Tengas un buen dia