Character set encoding in Visual Studio 2013

By , last updated October 30, 2015

Visual Studio character set encoding is not only important for representation of local character sets. It’s also an important factor that will let you compile different libraries together. If you are using many different libraries you must decide what character set your project should use.

In Visual Studio you can select different character sets. In general, if you’re not sure if you need those, then you don’t need it. You’ll know when you need to use those character sets.

Read also: How to show compile build time in Visual Studio

This rather annoying warning comes if you mix character sets in your application and libraries. Stay consistent and use only one of Not SetUnicode, or Multibyte Character Set in all your libraries and applications.

LINK : warning LNK4098: defaultlib 'mfc120.lib' conflicts with use of other libs; use /NODEFAULTLIB:library
LINK : warning LNK4098: defaultlib 'mfcs120.lib' conflicts with use of other libs; use /NODEFAULTLIB:library

Open up your project property settings (right click your project in the solution explorer) and make sure all projects and all configurations use the same character set.


I usually use Not Set, unless I plan to use other than English characters in my applications. Anything else is a hornet nest of incompatibilities.

Behind the covers, Visual Studio and the Microsoft SDK, will do some things if you select Unicode. It will define the macro _UNICODE.

A very common WinAPI method is MessageBox. It comes in two flavors, an ASCII version (MessageBoxA) and a Wide version (MessageBoxW).

#ifdef UNICODE
#define MessageBox  MessageBoxW
#define MessageBox  MessageBoxA
#endif // !UNICODE

The definition of MessageBoxA and MessageBoxW are similar, but with one crucial difference.

    _In_opt_ HWND hWnd,
    _In_opt_ LPCSTR lpText,
    _In_opt_ LPCSTR lpCaption,
    _In_ UINT uType);
    _In_opt_ HWND hWnd,
    _In_opt_ LPCWSTR lpText,
    _In_opt_ LPCWSTR lpCaption,
    _In_ UINT uType);

The former uses LPCSTR, and the latter use LPCWSTR. And much of the WinAPI goes like this.

Read also  1.#INF, 1.#IND and #QNAN floating point numbers and errors

If you have two modules built with different character sets, you can get crazy results when running the program (if you’re able to build and run it).


Be the first to comment.

Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>