473,491 Members | 2,074 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Managed String to char * conversion

I've been battling with this a little bit.
The Marshal class Copy method should do this. but......

I have the following (simple - not real code)

String * strString = DotNetMethodReturnValue(...);
char * pszString = new char[strString->Length + 1];

Now, using the marshal->copy method, I get various different errors
depending on how i try to convert it, but I can't seem to get my head around
the correct conversion.

Surely there is a simpler method than having to do the Marshal->Copy(...)
thing each time?

I have about a million lines of code which is partly in .net, and is slowly
being converted to full .net as time permits. Customer's don't like to wait
for 'conversions' so this is being done slowly.
Thus, I am in the position of having DotNet and Standard C++ mixed together
and conversions need to be done in places.

Thanks in advnace for the help.
Jul 21 '05 #1
1 5092
Surely there is a simpler method than having to do the Marshal->Copy(...)
thing each time?


See

How To Convert from System::String* to Char* in Visual C++ .NET
http://support.microsoft.com/?kbid=311259

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Jul 21 '05 #2

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

Similar topics

10
3592
by: Marcin Kalicinski | last post by:
Why string literals are regarded as char * not as const char *? (1) void f(char *); (2) void f(const char *); f("foo") will call version (1) of function f. I understand that the exact type...
0
1573
by: Jonathan Beck | last post by:
Hi All, How do I convert from a Managed String to a good 'ol char * or char array? Thanks in advance Jonathan
4
11326
by: Aaron Queenan | last post by:
When I build a C++ library to .NET using the managed C++ compiler, I get the following error message: Linking... LINK : error LNK2020: unresolved token (0A000005) _CrtDbgReport LINK : error...
7
7544
by: Bob Rock | last post by:
Hello, converting from the managed to the unmanaged world (and viceversa strings) and byte arrays is something I do often and I'd like to identify the most correct and efficient way to do it....
3
5618
by: keith | last post by:
In managed C++, there is variable String *s. The variable got value from a C# assembly. Then I need to convert it into char *c in order to call an external function in a dll that accepts parameter...
0
1071
by: Daylor | last post by:
hi. i use the function the ms publish,to convert Managed String to Char * . with english string it works ok. now, i have problem, when for example ,im try to convert a path to file , when the...
3
3477
by: zhphust | last post by:
I want to convert a object of a managed class to a unmanaged structure that has the same member with that managed class. Can anybody tell me how i can do it? Thanks in advance. -- zhphust...
10
5136
by: Bonj | last post by:
I use the following code to convert a managed string to an unmanaged one: _TCHAR error; const char* umstring = (const char*)Marshal::StringToHGlobalAnsi (merror).ToPointer(); _tcscpy(error,...
3
1180
by: richard.usenet | last post by:
I want a 'binary' value to be included in a managed string. ie a binary 0x01 not its ascii equivalent of 49 decimal or 0x31 hexidecimal. The following code converts the checksum unsigned char to...
16
8753
by: pkoniusz | last post by:
Hello everybody, Been just thinking how actually one could convert the following unmanaged code to the managed C++: struct JustAnExample { char value1; int value2; // etc ....
0
7154
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,...
0
7190
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...
1
6858
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
4881
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4578
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...
0
3076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1392
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 ...
1
633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
280
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...

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.