473,385 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Class, char array, error

MX
Welcome!

I have something like that:

ref class DCAM
{
...
private:
char str[64];
...

};

And in main program:

DCAM^ CAM = gcnew DCAM();
CAM->str[0] = 'a';
this->Text = gcnew System::String(Cam->str);

After compilation I got:
error C2664: 'System::String::String(const wchar_t *)' : cannot convert
parameter 1 from 'char [64]' to 'const wchar_t *'
1> Cannot convert a managed type to an unmanaged type

Thanks for any help.

--
MX
Apr 1 '06 #1
3 2196
DCAM^ CAM = gcnew DCAM();
CAM->str[0] = 'a';
this->Text = gcnew System::String(Cam->str);


Check this out, it might help you:
http://www.codeproject.com/managedcp...gConvertor.asp

--

Kind regards,
Bruno van Dooren
br**********************@hotmail.com
Remove only "_nos_pam"
Apr 1 '06 #2
MX wrote:
Welcome!

I have something like that:

ref class DCAM
{
...
private:
char str[64];
...

};

And in main program:

DCAM^ CAM = gcnew DCAM();
CAM->str[0] = 'a';
this->Text = gcnew System::String(Cam->str);

After compilation I got:
error C2664: 'System::String::String(const wchar_t *)' : cannot
convert parameter 1 from 'char [64]' to 'const wchar_t *'
1> Cannot convert a managed type to an unmanaged type

Thanks for any help.


Managed code always work in Unicode, so you can't directly convert from char
to String. Use System::Runtime::Interop::Marshal::PtrToStringAnsi .

Arnaud
MVP - VC
Apr 2 '06 #3
"Arnaud Debaene" <ad******@club-internet.fr> wrote
Thanks for any help.


Managed code always work in Unicode, so you can't directly convert from
char to String. Use System::Runtime::Interop::Marshal::PtrToStringAnsi .

It's probably also worth mentioning that C++'s char translates
to System::Byte and the C++ alias for System::Char is
wchar_t.

-hg
Apr 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Nimmi Srivastav | last post by:
Brief:- I am having trouble getting a FileWriter to write to a non-existent file if I instantiate the FileWriter with a String that is manipulated at run time. It works fine with a hard-coded char...
4
by: Piotr Sawuk | last post by:
Hello, I'm new in this group and new to c++ programming. And I already have my first question which wasn't answered by any text-book on c++ programming I have seen so-far: How can I define a...
3
by: matthurne | last post by:
I'm doing a chapter 12 exercise from Accelerated C++ ... writing a string-like class which stores its data in a low-level way. My class, called Str, uses a char array and length variable. I've...
6
by: Mattias Brändström | last post by:
Hello all! I am trying to write code that allows me to initialise one of my classes inline (with a vector like structure). Inline might not be the best term to use here but I can't think of any...
5
by: amparikh | last post by:
I have some test code which demonstrates the problem. I know I could solve this by just returning a pointer, but I better use a reference. In real code, what I actually want to return is a...
9
by: craig.overton | last post by:
All, I am currently developing an FTP class in VB.NET. It's kid tested, mother approved when trying to access an FTP Server on a Windows box meaning I can connect, run commands, upload and...
12
by: mast2as | last post by:
Hi everyone... I have a TExceptionHandler class that is uses in the code to thow exceptions. Whenever an exception is thrown the TExceptionHander constructor takes an error code (int) as an...
5
by: Lyle Avery | last post by:
Hello guys, Look at this in c++ file: class T { public: char c; char ca; };
3
by: Hamilton Woods | last post by:
Diehards, I developed a template matrix class back around 1992 using Borland C++ 4.5 (ancestor of C++ Builder) and haven't touched it until a few days ago. I pulled it from the freezer and...
1
by: kreator | last post by:
Hi i got an Access Violation error with AnsiStrings n char*. First chance exception at $7C812A5B. Exception class EAccessViolation with message 'Access violation at address 0040467E in module...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.