473,385 Members | 1,942 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.

String to byte *

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
3 1362
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

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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
0
by: Christophe Elek | last post by:
Ok, I am completly at lost :) in both cases (my Yenc and zip utilities) i try to do the following 1) get a String 2) transform in byte 3) so some computation (either adding value to the byte...
15
by: Beeeeeves | last post by:
Is there a quick way to find the index of the first character different in two strings? For instance, if I had the strings "abcdefghijkl" and "abcdefxyz" I would want the return value to be...
4
by: Charlie | last post by:
Hi: I'm storing my dB connection in web.config file. Since it will be easily read by opening file, what is a good way to secure it? Thanks, Charlie
5
by: Sia Jai Sung | last post by:
Hi, I have a class that I modify from a sample program, like below ========================================== Imports System Imports System.Web.UI Imports System.Security.Cryptography ...
9
by: rsine | last post by:
I have developed a program that sends a command through the serial port to our business system and then reads from the buffer looking for a number. Everything worked great on my WinXP system, but...
8
by: moondaddy | last post by:
I need to convert a byte array to a string and pass it as a parameter in a URL and then convert it back to the original byte array. However, its getting scrambled in the conversion. In short,...
6
by: moondaddy | last post by:
I'm writing an app in vb.net 1.1 and need to convert a byte array into a string, and then from a string back to a byte array. for example Private mByte() as New Byte(4){11,22,33,44} Now how...
4
by: JJ | last post by:
I need to encrypt credit card # and store that in a database (and be able to decrypt it). Any codes that use strong encyption algorithm like AES 256 on the web that I can copy and paste? Thanks
5
by: jeremyje | last post by:
I'm writing some code that will convert a regular string to a byte for compression and then beable to convert that compressed string back into original form. Conceptually I have.... For...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...

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.