Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. MC++ and CString

MC++ and CString

Scheduled Pinned Locked Moved Managed C++/CLI
c++questioncsharp
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    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; }

    T 1 Reply Last reply
    0
    • L Lost User

      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; }

      T Offline
      T Offline
      TigerNinja_
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups