char to BSTR
-
Im a novice at C++ and Im working on VisualC++.NET on w2k, what am I doing wrong here: Code: BSTR McName = SysAllocString(TEXT("DaveMachine")); Error: error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [11]' to 'const OLECHAR *' Any help is really appreciated. We have a mathematician, a different kind of mathematician, and a statistician!
-
Im a novice at C++ and Im working on VisualC++.NET on w2k, what am I doing wrong here: Code: BSTR McName = SysAllocString(TEXT("DaveMachine")); Error: error C2664: 'SysAllocString' : cannot convert parameter 1 from 'const char [11]' to 'const OLECHAR *' Any help is really appreciated. We have a mathematician, a different kind of mathematician, and a statistician!
-
SysAllocString takes a Unicode string as it's parameter. If you don't have _UNICODE defined - TEXT() evalulates to nothing. Always pass a Unicode string to SysAllocString like this BSTR McName = SysAllocString(L"DaveMachine");
Excellent, that got rid of a few errors, just one to go. This is the code: wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); and the error is pretty similar to the last one: error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *' Cheers We have a mathematician, a different kind of mathematician, and a statistician!
-
Excellent, that got rid of a few errors, just one to go. This is the code: wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); and the error is pretty similar to the last one: error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *' Cheers We have a mathematician, a different kind of mathematician, and a statistician!
Same thing - if Unicode is not defined TEXT = nothing, if it is TEXT = L. Thats fine, but your using the wide (UNICODE) version of wsprintf so its expecting a Unicode string. Either change TEXT to L or use char neutral APIs. Basically, never use TEXT with the explicilty wide (say wsprintf) or explictly narrow (say sprintf) versions of functions as you know what type of char to pass ("" in narrow, or L"" in wide). Use TEXT when you want to be char neutrual - using the API's - _stprintf. With UNICODE defined _stprintf = wsprintf and TEXT = L"". Without UNICODE define _stprintf = sprintf and TEXT = "".
-
Excellent, that got rid of a few errors, just one to go. This is the code: wsprintf(sz, TEXT("Load Percentage: %s\n"), V_BSTR(&vVal)); wprintf(sz); and the error is pretty similar to the last one: error C2664: 'wprintf' : cannot convert parameter 1 from 'TCHAR [260]' to 'const wchar_t *' Cheers We have a mathematician, a different kind of mathematician, and a statistician!
See also http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfcnotes_tn059.asp[^]
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!