figgy Posted February 8, 2004 Share Posted February 8, 2004 I have the following code int _tmain(int argc, _TCHAR* argv[]) { BSTR pgm = SysAllocString(argv[1]); I get the following error when I try to compile it: error C2664: 'SysAllocString' : cannot convert parameter 1 from '_TCHAR *' to 'const OLECHAR *'Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast I have been struggling with this for the past one hour. How do I fix it? Please help. Link to comment Share on other sites More sharing options...
0 MaceX Posted February 8, 2004 Share Posted February 8, 2004 type cast it? SysAllocString((OLECHAR*)argv[1]); Link to comment Share on other sites More sharing options...
0 kjordan2001 Posted February 8, 2004 Share Posted February 8, 2004 Yeah, that's what I was thinking too, it gives the hint right in the error. Whether it will cast to something good is questionable though. Link to comment Share on other sites More sharing options...
0 figgy Posted February 8, 2004 Author Share Posted February 8, 2004 In this case, _TCHAR* = char* & OLECHAR* = unsigned short* Therefore just casting will give incorrect results. I was under the impression that _TCHAR and OLECHAR are synonyms. This was not the case. Here is how I fixed the code: WCHAR buffer[512];ZeroMemory(buffer, sizeof(buffer)); char* param = argv[1]; MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, param, strlen(param), buffer, sizeof(buffer)-1); BSTR pgm = SysAllocString(buffer); Link to comment Share on other sites More sharing options...
Question
figgy
I have the following code
I get the following error when I try to compile it:
I have been struggling with this for the past one hour.
How do I fix it?
Please help.
Link to comment
Share on other sites
3 answers to this question
Recommended Posts