legolas82
April 17th, 2005, 11:45 AM
Hi,
I want to display the decimal value that is stored in a DWORD in a Messagebox.
When the box appears there's no value displayed, so prolly I have to convert the DWORD?
Greetz,
Fred
SuperKoko
April 18th, 2005, 05:42 AM
Yes of course you need to convert the DWORD to a string.
If you want to convert it to a BSTR, like you said, this code must work:
BSTR LONGToBstr(long lVal)
{
VARIANT v;
VARIANT nv;
v.vt=VT_I4;
v.lVal=lVal;
VariantInit(&nv);
if (FAILED(VariantChangeType(&nv,&v, VARIANT_NOVALUEPROP, VT_BSTR))) return NULL;
return nv.bstrVal;
}
The interest of this conversion function, is that is uses the locale to convert the number to the string.
But the problem with this code, is that it converts a LONG to a BSTR, and not a DWORD.
You can use it like that:
int LONGMessageBoxW(HWND hWnd,long lVal,LPCWSTR pwszTitle,DWORD dwFlags)
{
BSTR bstr=LONGToBstr(lVal);
if (bstr==NULL) {SetLastError(ERROR_NOT_ENOUGH_MEMORY);return 0;}
int r=MessageBoxW(hWnd,bstr,pwszTitle,dwFlags);
SysFreeString(bstr);
return r;
}