You might have your charset set to UNICODE. Does one of the following help?
Main Topics
Browse All TopicsIn my Windows mobile MFC dialog based app I am trying to define a directory like so:
#define DBF_DIR "\\Program Files\\MyProgram\\DB"
This is included in the header file MyProgram.h
I get an error message when I try to build this like so:
error C2440: 'initializing' : cannot convert from 'const char [27]' to 'ATL::CStringT<BaseType,St
How do I solve this??
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
>> error C2440: 'initializing' : cannot convert from 'const char [27]' to 'ATL::CStringT<BaseType,Str
Try changing it to this...
#define DBF_DIR _T("\\Program Files\\MyProgram\\DB") // Wide or narrow depending upon compile time params
or this
#define DBF_DIR L"\\Program Files\\MyProgram\\DB" // Wide string
>> CStringT
I'm not 100% but I'm guessing the T at the end means the same as the T in a TCHAR type (it can be either wide or narrow).
Try: _stprintf(szDbFile, "%s\\%s.dbf", DBF_DIR, CONFIG_DB_FILE);
http://msdn.microsoft.com/
re: _stprintf(szDbFile, "%s\\%s.dbf", DBF_DIR, CONFIG_DB_FILE);
gives the error:
error C2664: 'swprintf' : cannot convert parameter 1 from 'char [260]' to 'wchar_t *'
re: Use CString
I have to use:
char szDbFile[MAX_PATH];
sprintf(szDbFile, "%s\\%s.dbf", DBF_DIR, CONFIG_DB_FILE);
as I am using codebase and it needs it to be in that format, i.e. the next line is:
m_pD4ConfigData = d4open(&m_c4CodeBase, szDbFile);
You can use CStringA (as opposed to CString) and easily convert to a char * for the d4open() method.
It gets hairy mixing Unicode and the T macros with ANSI APIs. The macros work well, but an ANSI API expects ANSI, period, and are usually compiled to expect char *.
I will often just use a CString, for general use, that way all MFC APIs are happy, but when I need to call an ANSI/traditional API I assign to a CStringA for a conversion, and cast that to a char *. Its either that or use the conversion APIs (WideCharToMultiByte....),
>> What do you mean? So I have a UNICODE app, all t* types and CString are wide-char. So what is the quickest, simplest way to convert for 8-bit APIs?
Just use UTF8 all the time, forget wide... it's not portable and causes so many headaches. Wide for Windows is UTF16 and for Linux it's UTF32 but both will happily work with UTF8.
>> UTF8 is great, but I am talking wide-chars here, right? What did I miss?
I know and I'm saying avoid the pain just use UTF8 rather than UTF16 or UTF32.
It was a bit of a glib and OT comment... sorry ;)
Now that we have successfully hijacked another thread.. :)
What I am saying is, assuming we are using MFC with UNICODE defined, we don't necessarily have control? _T("foo") is going to be 16-bit, not 8-bit. TCHAR is wide, LPCTSTR is wide. All of the MFC APIs that expect either CString or LPCTSTR, etc. want wide char stuff, which is not UTF8. I don't want to use the conversion routines, I just want smart strings.
So if it were up to me, I'd use UTF8, but is it really up to me?
Business Accounts
Answer for Membership
by: mrjoltcolaPosted on 2009-05-21 at 14:34:44ID: 24446133
Can you post code to show where you are actually using DBF_DIR? This error is not due to your #define above, but due to how you are using it.