Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DWORD to BSTR Conversion 1

Status
Not open for further replies.

DougCa

Technical User
Nov 1, 2002
13
US
If strVal is a BString (e.g. its BSTRING &strVal) and data is a DWORD with 4 hex bytes. What is the easist way to get the 4 hex bytes in data to a decimal value in strVal?

Thanks,
Doug

DWORD data;


strVal = data; //This only gives me 2 of the hex bytes in
// strVal. So I need something else here.
 
I think if you are using COM it is not a big deal...
you can mail me at pankaj_kum@yahoo.com to get a sample code which coneverts a double to BSTR...as i used thse things in COM in one of my previous projects.
Hope it helps
 
Ok i give you the answer here only...as i had to cut short my code for this sample...
This is a simple Win32 Console code...

#include "stdafx.h"
#include <windows.h>
#include <comdef.h>
#include <stdio.h>
#include <ctype.h>
#include <conio.h>
#include <oleauto.h>

int main(int argc, char* argv[])
{
VARIANT dblvar,strvar;
dblvar.vt=VT_R8;
dblvar.dblVal = 1.98765432123456;

strvar.vt = VT_BSTR;
VarBstrFromR8(dblvar.dblVal,NULL,LOCALE_NOUSEROVERRIDE,&strvar.bstrVal);

MessageBoxW(0,strvar.bstrVal,L&quot;With BSTR&quot;,0);
return 0;
}

Hope it solves your problem
Let me know
PANKAJ KUMAR
 
why don't u use the _ltot function?

[tt]
TCHAR szBuffer[sizeof(DWORD)*16+1];
DWORD dwTest = 0x12345;

_ltot(dwTest, szBuffer, 10);
[/tt]

You can also use the _ltow function, but the _ltot function is _ltow if _UNICODE is defined. You can also convert it to a hex string by using radix 16 instead of radix 10, like:

[tt]
_ltot(dwTest, szBuffer, 16);
[/tt]
 
I think he said DWORD instead of long..ok this API _ltoa usage is fine
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top