473,770 Members | 4,029 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2211
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************* *********@hotma il.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::Mars hal::PtrToStrin gAnsi.

Arnaud
MVP - VC
Apr 2 '06 #3
"Arnaud Debaene" <ad******@clu b-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::Mars hal::PtrToStrin gAnsi.

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
7743
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 array. The error that I get in the former case is: (The specified path is invalid)tion Detailed:- This is my first serious foray into Java ----- I recently completed the Hello World program ----- so my apologies if I am not
4
1720
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 class who's size is only known at the time the constructor gets executed -- without the overhead of pointer-managment (for copying) and without any additional memory getting allocated for size or location of the variable sized member-data?
3
2324
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 gotten everything working that I want working so far, except for std::istream& operator>>(std::istream&, Str&) The way my Str class manages itself of course requires that the size of the char array to store is known when it is allocated. The...
6
3147
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 other right now. Here is my code: template <typename T> class Array { public: Array& operator()(const T& v) {
5
5834
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 reference to an array of function pointers. But the code below is good enough to show the problem. Thanks. #define MAX_DEC 11
9
8333
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 download a file no problem. My issues come when I try to use the same class with the same commands to access an FTP server on a UNIX box. I can connect and login just fine, but after that all my commands come back "500 'PWD': command not understood."....
12
2535
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 argument. I was hoping to create a map<int, const char*that would be used in the showError member function of the TExceptionHandler class where the key (int) would be the error code and const char* the message printed out to the console. My question...
5
4749
by: Lyle Avery | last post by:
Hello guys, Look at this in c++ file: class T { public: char c; char ca; };
3
3758
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 thawed it out. I built a console app using Microsoft Visual C++ 6 (VC++) and it worked great. Only one line in the header file had to be commented out. I built a console app using Borland C++ Builder 5. The linker complained of references to...
1
5989
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 'Serial.exe'. Write of address 0518F503'. Process Serial.exe the code is here: AnsiString temp = Hex2Ascii(APDUCmd, index);
0
10237
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10071
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9882
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8905
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6690
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5326
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3987
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2832
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.