wprintf problem
-
Im trying to print a VARIANT value to the screen using this code TCHAR sz[MAX_PATH]; VARIANT vVal; wprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); This builds ok, but doesnt print anything to the screen If I use printf(sz) then I get a missmatch in variable types. error C2664: 'printf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const char *' Anyone got any ideas on what I can do We have a mathematician, a different kind of mathematician, and a statistician!
-
Im trying to print a VARIANT value to the screen using this code TCHAR sz[MAX_PATH]; VARIANT vVal; wprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); This builds ok, but doesnt print anything to the screen If I use printf(sz) then I get a missmatch in variable types. error C2664: 'printf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const char *' Anyone got any ideas on what I can do We have a mathematician, a different kind of mathematician, and a statistician!
roadragedave wrote: If I use printf(sz) then I get a missmatch in variable types
printf("%s",sz); rite ???
-
Im trying to print a VARIANT value to the screen using this code TCHAR sz[MAX_PATH]; VARIANT vVal; wprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); This builds ok, but doesnt print anything to the screen If I use printf(sz) then I get a missmatch in variable types. error C2664: 'printf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const char *' Anyone got any ideas on what I can do We have a mathematician, a different kind of mathematician, and a statistician!
Use
_tprintf
instead Sonork 100.41263:Anthony_Yio Life is about experiencing ... -
roadragedave wrote: If I use printf(sz) then I get a missmatch in variable types
printf("%s",sz); rite ???
Very true, I am an idiot, BUT!, when I do that I get a strange output ╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠ I have never seen these characters before We have a mathematician, a different kind of mathematician, and a statistician!
-
Im trying to print a VARIANT value to the screen using this code TCHAR sz[MAX_PATH]; VARIANT vVal; wprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); This builds ok, but doesnt print anything to the screen If I use printf(sz) then I get a missmatch in variable types. error C2664: 'printf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const char *' Anyone got any ideas on what I can do We have a mathematician, a different kind of mathematician, and a statistician!
How about:
wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));
or
wprintf(TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
How about:
wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));
or
wprintf(TEXT("Load Percentage: %s\n"), V_BSTR(&vVal));
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
No good, now I get an Unhandled Exception http://www.81x.com/Authors/roadragedave/exception.jpg We have a mathematician, a different kind of mathematician, and a statistician!
-
No good, now I get an Unhandled Exception http://www.81x.com/Authors/roadragedave/exception.jpg We have a mathematician, a different kind of mathematician, and a statistician!
Hmmm, this code snippet works for me:
TCHAR sz[MAX_PATH];
VARIANT vVal;
vVal.vt = VT_BSTR;
vVal.bstrVal = SysAllocString(_T("95%"));
wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
No good, now I get an Unhandled Exception http://www.81x.com/Authors/roadragedave/exception.jpg We have a mathematician, a different kind of mathematician, and a statistician!
-
Hmmm, this code snippet works for me:
TCHAR sz[MAX_PATH];
VARIANT vVal;
vVal.vt = VT_BSTR;
vVal.bstrVal = SysAllocString(_T("95%"));
wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
Very nice, What my problem is, is that I am calling a function called GetProperty hRes = WmiTest.GetProperty(accClass, accProperty, accKey, &vVal); vVal, which is VARIANT, has the property value which I want to display, so how do I do this? Im sorry for being a pest on this one, thanks for your help We have a mathematician, a different kind of mathematician, and a statistician!
-
Hmmm, this code snippet works for me:
TCHAR sz[MAX_PATH];
VARIANT vVal;
vVal.vt = VT_BSTR;
vVal.bstrVal = SysAllocString(_T("95%"));
wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
I finally got it, it was so simple in the end, I was getting an exception because I was trying to pass a uint16 to a string. For future reference if anyone has this problem
wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));
should bewsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal));
Can you spot the simple difference:doh: Thanks for all yer help everyone We have a mathematician, a different kind of mathematician.............. and a statistician! -
I finally got it, it was so simple in the end, I was getting an exception because I was trying to pass a uint16 to a string. For future reference if anyone has this problem
wsprintf(sz, _T("Load Percentage: %s\n"), V_BSTR(&vVal));
should bewsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal));
Can you spot the simple difference:doh: Thanks for all yer help everyone We have a mathematician, a different kind of mathematician.............. and a statistician!roadragedave wrote: wsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal)); This is not right at all. The
%i
type is for signed decimal integers, which is not whatV_BSTR()
returns. When theV_BSTR()
macro is expanded, notice that it accesses thebstrVal
member of theVARIANT
structure, not theintVal
member. You've simply masked the problem.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
roadragedave wrote: wsprintf(sz, _T("Load Percentage: %i\n"), V_BSTR(&vVal)); This is not right at all. The
%i
type is for signed decimal integers, which is not whatV_BSTR()
returns. When theV_BSTR()
macro is expanded, notice that it accesses thebstrVal
member of theVARIANT
structure, not theintVal
member. You've simply masked the problem.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
I get what you mean, however the function that gets
vVal
passes it back asuint16
,VARIANT
, I presume, is a generic data type that holds almost all simple data types and what is needed it to convert to saystring, double, BSTR
. Using%s
threw and exception and I could not figure out using the debuging what exactly was going wrong, I took a chance and changed it to%i
, and the application works.:confused: We have a mathematician, a different kind of mathematician, and a statistician! -
I get what you mean, however the function that gets
vVal
passes it back asuint16
,VARIANT
, I presume, is a generic data type that holds almost all simple data types and what is needed it to convert to saystring, double, BSTR
. Using%s
threw and exception and I could not figure out using the debuging what exactly was going wrong, I took a chance and changed it to%i
, and the application works.:confused: We have a mathematician, a different kind of mathematician, and a statistician!roadragedave wrote: ...the function that gets vVal passes it back as uint16, Which means you should be using
V_INT()
instead ofV_BSTR()
.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)