473,228 Members | 1,663 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,228 software developers and data experts.

System.String conversion to System.Char*

Hi!

I've got a problem when converting a System.String into a System.Char*!
Problem: Invalid Cast Operation
Here is the source:

Type type = Type.GetType("System.Char*");
String val = "c";
Object o = Convert.ChangeType(val,type);

val can only be a string, because i'm reading it out of an xml-file!
Xml-Source:
<type>System.Char*</type>
<value>c</value>

I hope you can help me! Thank you ;)

Eva
Nov 15 '05 #1
4 3984
Eva,

What do you need a char* for? Anyway, you use the fixed statement for
that

fixed ( char* pc = val ) { ... }

Mattias

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

Thanks for your fast answere! I am developing a programm to store and
load classes/instances/methods... I store values for methods(according
to their MethodInfo)and for testing purpose i tried to construate a
System.String with the constructor String(Char*, int, int)! Creating and
storing works fine, but reloading does not work!
The method to reload a Value looks like this(Xml-Data see above):

private object GenerateValue(XmlElement element)
{
//Get Type
XmlNodeList xnl = element.GetElementsByTagName("type");
Type valType = Type.GetType(xnl.Item(0).InnerText);
//Get Value
xnl = element.GetElementsByTagName("value");
String value = xnl.Item(0).InnerText;
//Generate Value
return Convert.ChangeType(value,valType);
}

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3
Thanks for your fast answere! I am developing a programm to store and
load classes/instances/methods...
Any reason you're not using the framework's serialization support for
this?

//Generate Value
return Convert.ChangeType(value,valType);


The Convert class and its ChangeType method is pretty limited in which
types it can handle and what kinds of conversion. You can't expect it
to work for any value you've persisted.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 15 '05 #4
>Any reason you're not using the framework's serialization >support for
this?

Yes, the structure of the programm is too complicated and can't be
simplified to use xml-serialisation!
I already tried it, but it doesn't work out quite properly!

Ok! Thanks for your information! It seems that problem is far more
complicated, than it seemed at first ;) I'll have to work on that ;)

Eva

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5

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

Similar topics

10
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...
7
by: john | last post by:
On my form i have a message box called txtItemDesc that displays the french phrase qualité Père Noël. Now then when i run this code on that text box: Dim chrArr() As Char chrArr =...
11
by: Zordiac | last post by:
How do I dynamically populate a string array? I hope there is something obvious that I'm missing here Option Strict On dim s() as string dim sTmp as string = "test" dim i as integer ...
10
by: Herby | last post by:
I seem to be having a problem with System namespace. There seem to two System namepaces when viewing through Object browser within .NET 2005. One global System:: Then one under <mscorlib> Each...
6
by: karthi | last post by:
hi, I need user defined function that converts string to float in c. since the library function atof and strtod occupies large space in my processor memory I can't use it in my code. regards,...
24
by: Marcus Kwok | last post by:
Hello, I am working on cleaning up some code that I inherited and was wondering if there is anything wrong with my function. I am fairly proficient in standard C++ but I am pretty new to the .NET...
2
by: Alejandro Aleman | last post by:
Hello! i know this may be a newbie question, but i need to convert a string from System::String^ to char*, in the msdn page tells how, but i need to set to /clr:oldSyntax and i dont want it...
3
by: Kevin Frey | last post by:
I am porting Managed C++ code from VS2003 to VS2005. Therefore adopting the new C++/CLI syntax rather than /clr:oldSyntax. Much of our managed code is concerned with interfacing to native C++...
6
by: DaTurk | last post by:
Hi, I have several interfaces in CLI that I access via c#. My problem is, is that down in the unmanaged c++, which the CLI lies on top of, I have a lot of c_str() happening. But all of my...
8
by: Edson Manoel | last post by:
I have some C++ unmanaged code that takes std::string& arguments (as reference), and fills them (possibly growing the string). I want to call this code through PInvoke (DllImport), possibly using...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.