The following forum(s) have migrated to Microsoft Q&A (Preview): Developing Universal Windows apps!
Visit Microsoft Q&A (Preview) to post new questions.

Learn More

 locked
How to work on stream string in C++/CX RRS feed

  • Question

  • Hi, I am having WinRT Component in my project, where I need to pass "const char *". that is image thumnail data. so I have taken String^ property for my component object[which can be used in c#]. and assigning String^ property from C# code like following:

    using (StreamReader reader = new StreamReader(fileStream))
                            {
                                imgThumb = reader.ReadToEnd();
                            }

    Then I want to convert the String^ to const char* [Note: const char* is an image data]. Please provide me solution. I don't have much coding experience in C++/CX.

    I have tried following code to convert String^ to const char *".  but it doesn't worked.

    char* narrow( const wstring& wstr )
    		{
    			//const char *cstr = wstr.c_str();
    			ostringstream stm ;
    			const ctype<char>& ctfacet =
    				use_facet< ctype<char> >( stm.getloc() ) ;
    			for( size_t i=0 ; i<wstr.size() ; ++i )
    				stm << ctfacet.narrow( wstr[i], 0 ) ;
    			string str = stm.str();
    			char* c = new char [str.size()+1];
    			//			strcpy(c, str.c_str());
    			return c;
    		}

    Please help me. thanks in advance...

    Pallam Madhukar Windows Phone Developer




    Tuesday, March 4, 2014 10:59 AM

All replies

  • Hi all,

    I have found one article for Windows Forms, but the code is not working for me, the namespace is not exists in WinRT,Please can any one provide conversion code.

    URL: http://answers.opencv.org/question/22588/convert-string-to-char-windows-form-application-c/

    thanks in advance.


    Pallam Madhukar Windows Phone Developer


    Tuesday, March 4, 2014 1:51 PM
  • Hi all,

    Please help me. as i am not familiar with C++/CX, any one who knows C++/CX, at-least suggest me their idea. i will try. i am waiting this thread response.

    thanks in advance....


    Pallam Madhukar Windows Phone Developer


    Tuesday, March 4, 2014 9:24 PM
  • Is no one there to help me here..?

    Pallam Madhukar Windows Phone Developer

    Wednesday, March 5, 2014 7:40 AM