Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Converting BYTE * -> BSTR ?

111 views
Skip to first unread message

S Kumar

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to
How can I convert BYTE * -> BSTR ?

Here's the psuedo code of the function:

mycrypt(BSTR str, BSTR * cipherText)
{
BYTE *pbData;
DWORD dwCryptDataLen = 0;
DWORD dwDataLen = 0;
pbData = (BYTE*)OLE2A(str);
.....

CryptEncrypt(hKey, 0, true, 0, pbData, &dwCryptDataLen, dwDataLen))

/* pbData now contains encrypted string*/
/* How do I convert pbData -> cipherText?? */

}

thanks
saur...@yahoo.com

Scott Tunstall

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to
Cast the BYTE * to a char * then use _bstr_t class.

_bstr_t RetBSTR = (char *) pbData; // This is untested, but _bstr_t
does overload = operator to take const char *

*cipherText = RetBSTR.copy();

--
Scott Tunstall
MFC & COM consultant

Personal URL: www.kwikrite.clara.net/bdash/
S Kumar wrote in message ...

S Kumar

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to
Here's the psuedo code of the function:

Alexander Nickolov

unread,
Aug 3, 1999, 3:00:00 AM8/3/99
to
I'd advise against using any BSTR helper class here!!! They are all
designed to expect zero terminated string. The SysAllocStringByteLen
API is exactly what you're looking for:

bstr = SysAllocStringByteLen(NULL, len);
CopyMemory(bstr, source, len);

--
===============================
Alexander Nickolov, MCP
Panasonic Technologies Inc.
Speech Technology Laboratory
email: agnic...@geocities.com
===============================

S Kumar wrote in message ...

0 new messages