0
BOOL CTestBMPDoc::OnOpenDocument(LPCTSTR lpszPathName) { if (! CDocument::OnOpenDocument(lpszPathName)) return FALSE; m_pvtkBMPReader = vtkBMPReader::New(); m_pvtkBMPReader->SetFileName(lpszPathName); return TRUE; } 

The above code doesn't compile and produces the C2664 error. Why?

1
  • as the error says, you are passing the wrong argument type to the function setFileName. it expects a char* and you provide a LPCTSTR Commented Feb 15, 2017 at 11:08

1 Answer 1

0

Your VC++ project is setup as a UNICODE so all the references to TCHAR are resolved into a wide character type w_char. However your vtk's SetFileName() function doesn't support UNICODE thus the compilation error.

To fix this you should either change the properties of your project to use ASCII or MBCS (depending on your needs) or do the manual UNICODE->MBCS (or into ASCII) conversion.

Below is an example on how to convert UNICODE into MBCS using system codepage:

const size_t fnameLen = 1024; char * fname[fnameLen]; int converted = WideCharToMultibyte( CP_ACP , WC_COMPOSITECHECK | WC_ERR_INVALID_CHARS , lpszPathName , -1 // null-terminated string , fname , fnameLen , NULL // or whatever you'd like it to be , NULL); m_pvtkBMPReader->SetFileName(fname); // <-- this should work now as it is char* 

Please note that I have just written down that code without compiling, so expect that you may need some tweaking before this builds and runs properly.

ATL and MFC provide a bunch of convenient macroses to simplify the string conversions.

Sign up to request clarification or add additional context in comments.

1 Comment

stackoverflow.com/questions/4786292/… (Google is your friend ;-))

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.