type conversion
-
Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.
-
Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.
titi@yahoo.com wrote: OCTETSTR(octant string) How many Byte One character take in OCTETSTR?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers, Alok Gupta VC Forum Q&A :- I/ IV
-
Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.
What on earth is an OCTETSTR ? It's obviously a different format entirely, and so needs some sort of conversion class. Christian Graus - Microsoft MVP - C++
-
Im using boZoi library to implement Elliptic curve cryptography to my VC project.The functions output r in the format of hexadecimal and OCTETSTR(octant string) now if i want to show the output in the edit box control of a dialog box...its not working. OCTETSTR str; HexEncoder hex(str); CEdit* poEdit = static_cast(GetDlgItem(IDC_EDIT3)); poEdit->SetWindowText(hex); hex cant b converted to CString or LPCTSTR...it gives type casting errors.
HexEncoder
doesn't provide a direct conversion tochar*
orCString
. It only offers the possibility to output its content to anstd::ostream
. You could use anstringstream
for that and then extract the string from it. On the other hand,OCTETSTR
is just a typedef forstd::vector<unsigned char>
, so you could iterate through each element and convert it to hexadecimal notation usingsprintf
like this:// [UPDATE]
// void OctetStrToHexString(OCTETSTR str, CString& sResult)
void OctetStrToHexString(const OCTETSTR& v, CString& sResult)
{
// [update] some minor errors corrected
LPTSTR p = sResult.GetBuffer(v.size()*2);
for (OCTETSTR::size_type i = 0; i < v.size(); i++)
p += _stprintf(p, _T("%02X"), (int)v[i]);
*p = _T('\0');
sResult.ReleaseBuffer(v.size()*2);
}Then your code could be written as follows:
OCTETSTR str;
CString sBuffer;
OctetStrToHexString(str, sBuffer);
poEdit->SetWindowText(sBuffer);Note I haven't actually compiled nor tested the code shown above, so it may contain errors. -- jlr http://jlamas.blogspot.com/[^]
-
HexEncoder
doesn't provide a direct conversion tochar*
orCString
. It only offers the possibility to output its content to anstd::ostream
. You could use anstringstream
for that and then extract the string from it. On the other hand,OCTETSTR
is just a typedef forstd::vector<unsigned char>
, so you could iterate through each element and convert it to hexadecimal notation usingsprintf
like this:// [UPDATE]
// void OctetStrToHexString(OCTETSTR str, CString& sResult)
void OctetStrToHexString(const OCTETSTR& v, CString& sResult)
{
// [update] some minor errors corrected
LPTSTR p = sResult.GetBuffer(v.size()*2);
for (OCTETSTR::size_type i = 0; i < v.size(); i++)
p += _stprintf(p, _T("%02X"), (int)v[i]);
*p = _T('\0');
sResult.ReleaseBuffer(v.size()*2);
}Then your code could be written as follows:
OCTETSTR str;
CString sBuffer;
OctetStrToHexString(str, sBuffer);
poEdit->SetWindowText(sBuffer);Note I haven't actually compiled nor tested the code shown above, so it may contain errors. -- jlr http://jlamas.blogspot.com/[^]
Ive used this code but the compiler gives v as undeclared identifier.whas v?? Thanx for ur help
-
Ive used this code but the compiler gives v as undeclared identifier.whas v?? Thanx for ur help
Oops!
v
was meant to be theOCTETSTR
parm, sorry. Change the function header to this:void OctetStrToHexString(OCTETSTR v, CString& sResult)
-- jlr http://jlamas.blogspot.com/[^]