|
|
I have an string which contains the following data
str = "FFDA0890DA"
"FFDA0890DA" is actually an hexadecimal for of data , i need to convert this to an BYTE array
*bArray = {'F','F','D','A','0','8','9','0','D','A'}
|
|
|
|
|
you can access individual characters using
str[i] // where i is the index of that char you want to access.
There is no need to convert..
I hope it makes sense.
Regards,
Sandip.
|
|
|
|
|
kapardhi wrote: str = "FFDA0890DA"
"FFDA0890DA" is actually an hexadecimal for of data , i need to convert this to an BYTE array
*bArray = {'F','F','D','A','0','8','9','0','D','A'}
Will be something like this, take care of empty string issues.
std::vector<BYTE> ToBytes( const CString& str )
{
const int ByteLength = ( str.GetLength() * sizeof( TCHAR )) + 1;
std::vector<BYTE> Bytes(ByteLength);
memcpy_s( &Bytes[0], ByteLength, static_cast<lpctstr>( str ), ByteLength );
return Bytes;
}</lpctstr>
std::vector<BYTE> Bytes = ToBytes( CString( _T( "Nibu in bytes :P" )));
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
modified on Friday, August 22, 2008 4:15 AM
|
|
|
|
|
Usually hex string are converted to BYTE arrays two characters at time. For instance
str = "FFDA0890DA"; becomes BYTE a[]={0xFF, 0xDA, 0x08, 0x90, 0xDA};
Are sure about the conversion required?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yes i need some what in similiar manner!
|
|
|
|
|
Please, be precise.
Given str = "FFDA0890DA"
do you need
BYTE b[] = {'F','F','D','A','0','8','9','0','D','A'}; or
-
BYTE b[] = { 0xFF, 0xDA, 0x08, 0x90, 0xDA };<br />
?
(no need to say they're quite different... )
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
sorry i have shown in a wrong way previously i actually need in following manner
BYTE b[] = { 0xFF, 0xDA, 0x08, 0x90, 0xDA };
|
|
|
|
|
kapardhi wrote: sorry i have shown in a wrong way previously i actually need in following manner
BYTE b[] = { 0xFF, 0xDA, 0x08, 0x90, 0xDA };
This function does this, do test well, you also need to handle empty string cases...
std::vector<BYTE> CStringBytes_To_RealBytes( const CString& str )
{
const LPCTSTR pBuff = static_cast<lpctstr>( str );
const int ByteLength = str.GetLength();
std::vector<BYTE> Bytes;
Bytes.reserve( ByteLength );
for( int Index = 0; Index < ByteLength; Index+=2 )
{
TCHAR Temp[3] = { 0 };
_tcsncpy_s( Temp, 3, &pBuff[Index], 2 );
Bytes.push_back( static_cast<BYTE>( _tcstol( Temp, NULL, 16 )));
}
return Bytes;
}</lpctstr>
std::vector<BYTE> Bytes = CStringBytes_To_RealBytes( CString( _T( "FFDA0890DA" )));
This function assumes that two characters in the above string equals one byte.
Nibu babu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
Well, for instance, using plain C (working on even-lenght hex strings, error checking omitted)
void main()
{
char * str = "FFDA0890DA";
int i, size;
int k;
BYTE * b;
size = strlen(str) / 2;
b = (BYTE*) malloc(size * sizeof(BYTE));
for (i=0; i<size;> {
sscanf(str+2*i, "%2x", &k);
b[i]= (BYTE) k;
}
for (i=0; i<size;> {
printf("b[%d] = 0x%02X\n",i, b[i]);
}
free( b);
}
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Please Guide Connect Sqlserver with VC++6.0.
application is win32 consoleApplication
thanks very much
|
|
|
|
|
|
Please You check it is error code ?
"
void CReadDBDlg::OnRead()
{
CDatabase database;
CString SqlString;
CString sCatID, sCategory;
CString sDriver = "Microsoft Access Driver(*.mdb)";
CString sDsn;
CString sFile = "C:\\CONNECTACCESS_2.mdb";
int iRec = 0;
CString s = "MS Access Database";
sDsn.Format("ODBC;Driver={%s};DSN={%s};Dbq=%s",sDriver,s, sFile);
TRY
{
database.Open(s,false, true,sDsn); //ERROR this is
CRecordset recset( &database );
}
CATCH(CDBException, e)
{
// If a database exception occured, show error msg
AfxMessageBox("Database error: "+e->m_strError);
}
END_CATCH;
}
"
|
|
|
|
|
|
I've written a simple standalone win32 exe in plain C
that I'd like to ship to friends on an install/setup CD.
I'm using VS 2003 Academic and can't find a clear explanation
how to go about creating a simple setup.
I recall how easy it was with VB5 Enterprise, and was expecting
the VS 2003 procedure to be at least as easy - but not to be.
There must be an understandable way to create a simple setup for
a simple win32 exe - understandable to me, that is.
All help appreciated!
glyfyx
|
|
|
|
|
|
|
I second InnoSetup, very easy to use and all the features you could wish for. And it's free!
|
|
|
|
|
Thanks everyone for a great solution -
InnoSetup is excellent, and sooo easy to use.
I got it to work first pass !!
Thanks again
glyfyx
|
|
|
|
|
Forgot to mention - You should also give ISTool (link on the Innosetup site) a try, it's a great gui configuration utility for your InnoSetup scripts.
|
|
|
|
|
Hi all
We have an application developed in VC++ which configures a server . It runs in Windows XP .
This application is used by a testing tool to automatic testing . Thats , the user interface will be fed with values and configuration will be happening . Is there any way to make this application run in the background without affecting the testing tool when it modifies the UI values ?
I am sure we can make the process run in the background when there is not user interface activity . But keeping UI active for the test tool and making it invisible is something new for me .
Any ideas please ...
redindian
|
|
|
|
|
Are you looking for a windows service and IPC? Then your UI can interact with the windows service which will be running in the background.
You can simply hide the dialog if UI is inactive (something like a office scan client) which continues it's work in the background when UI is minimized.
Somethings seem HARD to do, until we know how to do them.
_AnShUmAn_
|
|
|
|
|
No i don't think it will be possible because Testing tools i have seen need your UI to be active. And moreover tools require mouse and keyboard control to automate the testing scripts.
Regards,
Sandip.
|
|
|
|
|
Hi all,
In MS-Access when i create a table than its first field is ID field that is Automunber type field.
it is automatic updated when add or remove records.
Here i have one problem,
For example::
if Tabel has 4 records than ID field has number like 1,2,3,4 if i delete the 4th record than after this when i add new record than its number is 5.
like 1,2,3,5.
i want wheater i delete any record the Numbering of ID field must be as increeasing order like 1,2,3,4.... and so on, if i delete any record than at time of adding record it is itself take number greater than last record.
So please tell me how can i do this.
If possible please explain with example.
Thank in advance.
IN A DAY, WHEN YOU DON'T COME ACROSS ANY PROBLEMS - YOU CAN BE SURE THAT YOU ARE TRAVELLING IN A WRONG PATH
|
|
|
|
|
|