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. C / C++ / MFC
  4. System::String _gc* to char *

System::String _gc* to char *

Scheduled Pinned Locked Moved C / C++ / MFC
c++helpcsharpdatabase
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.
  • D Offline
    D Offline
    deniz79s
    wrote on last edited by
    #1

    :eek::eek::eek::eek::eek:I can't achieve this process in .Net Visual C++. I use below code and the interpreter doesn't give any error at compile time but an error is occours at run time ("object referance not set to an object instance") char *dosya; String *dizi; dizi=textBox1->Text; dosya=new char(512); dosya=reinterpret_cast(dizi->ToCharArray()); also I used below code and the compiler gave an error at run time ("index was outside of range" like this I can't remember completly) dosya=reinterpret_cast(dizi->get_Chars(dizi->get_Lenght())); for summary I can't get the characters from a System::String class to a char pointer. (instead of char to use wchar_t variable didn't solve the problem

    H 1 Reply Last reply
    0
    • D deniz79s

      :eek::eek::eek::eek::eek:I can't achieve this process in .Net Visual C++. I use below code and the interpreter doesn't give any error at compile time but an error is occours at run time ("object referance not set to an object instance") char *dosya; String *dizi; dizi=textBox1->Text; dosya=new char(512); dosya=reinterpret_cast(dizi->ToCharArray()); also I used below code and the compiler gave an error at run time ("index was outside of range" like this I can't remember completly) dosya=reinterpret_cast(dizi->get_Chars(dizi->get_Lenght())); for summary I can't get the characters from a System::String class to a char pointer. (instead of char to use wchar_t variable didn't solve the problem

      H Offline
      H Offline
      HENDRIK R
      wrote on last edited by
      #2

      a look at msdn brings the following solution: using namespace System::Runtime::InteropServices; const char* str = (const char*) (Marshal::StringToHGlobalAnsi(managedString)).ToPointer(); // use str as you wish or copy it elsewhere // free string Marshal::FreeHGlobal(IntPtr((void*)str));


      We are men. We are different. We have only one word for soap. We do not own candles. We have never seen anything of any value in a craft shop. We do not own magazines full of photographs of celebrities with their clothes on. - Steve

      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