By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,459 Members | 1,472 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,459 IT Pros & Developers. It's quick & easy.

String to byte *

P: n/a
Hi,
How can I convert a String to a byte * pointer? I am using a third-party
component that has functions that take byte * parameters.

regards Tobias
Nov 15 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Can you give an example of a function prototype?

Regards
Brian W
"Tobias Svensson" <to***@hotmail.com> wrote in message
news:e7****************@tk2msftngp13.phx.gbl...
Hi,
How can I convert a String to a byte * pointer? I am using a third-party
component that has functions that take byte * parameters.

regards Tobias

Nov 15 '05 #2

P: n/a

private unsafe void button26_Click(object sender, System.EventArgs e)
{
string s = "Hello";
fixed ( char* pc = s )
{
byte * pb = (byte*)pc;
char c1 = *pc;
Console.WriteLine("Char0:"+c1);
char c2 = pc[1];
Console.WriteLine("Char1:"+c2);
Console.WriteLine("byte0:"+pb[0]);
Console.WriteLine("byte1:"+pb[1]);
Console.WriteLine("byte2:"+pb[2]);
Console.WriteLine("byte3:"+pb[3]);
}
}

--
William Stacey, MVP

"Tobias Svensson" <to***@hotmail.com> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Hi,
How can I convert a String to a byte * pointer? I am using a third-party
component that has functions that take byte * parameters.

regards Tobias

Nov 15 '05 #3

P: n/a
I can't be sure without some more information about the what the dll expects
but you should probably try out the System.Text.Encoding class. Create the
encoding appropriate to the application (Unicode, UTF-8, default, etc.) and
then call the GetBytes method. Declare the function prototype to take a byte
array and you should be fine.

"Tobias Svensson" <to***@hotmail.com> wrote in message
news:e7****************@tk2msftngp13.phx.gbl...
Hi,
How can I convert a String to a byte * pointer? I am using a third-party
component that has functions that take byte * parameters.

regards Tobias

Nov 15 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.