App does not run with VS 2008 SP1 DLLs, previous version works with RTM versions

I have battled this problem myself last week and consider myself somewhat of an expert now 😉 I’m 99% sure that not all dlls and static libraries were recompiled with the SP1 version. You need to put #define _BIND_TO_CURRENT_MFC_VERSION 1 #define _BIND_TO_CURRENT_CRT_VERSION 1 into every project you’re using. For every project of a real-world size, … Read more

Error LNK2019 when using GetFileVersionInfoSize()

You need to link against the library that contains the two functions VerQueryValue and GetFileVersionInfo – the linker doesn’t know by default where to find them. A quick search for the two functions on MSDN suggests that they’re both in the system library version.dll and the library you want to link against is version.lib. Just … Read more

What’s with the “Afx” in StdAfx.h?

From Wikipedia: One interesting quirk of MFC is the use of “Afx” as the prefix for many functions, macros and the standard precompiled header name “stdafx.h”. During early development what became MFC was called “Application Framework Extensions” and abbreviated “Afx”. The name Microsoft Foundation Classes (MFC) was adopted too late in the release cycle to … Read more

Which Font is the default for MFC Dialog Controls?

The first example is using the System font (SYSTEM_FONT), as retrieved with the GetStockObject function, which is a bitmap font that has not been used since the days of Windows 3. More information is available on Raymond Chen’s blog, and Michael Kaplan’s blog. The second example is using the “MS Shell Dlg” font, just like … Read more

C++ MFC vs .NET?

I’ve used both MFC and Windows Forms extensively for a very long time. I’m from the video game industry, so have had to write many desktop applications over the years, and before .net, MFC was extremely useful. Even before that I was writing tools in pure Win32. MFC definitely had its quirks, but overall it … Read more

Convert MFC CString to integer

The simplest approach is to use the atoi() function found in stdlib.h: CString s = “123”; int x = atoi( s ); However, this does not deal well with the case where the string does not contain a valid integer, in which case you should investigate the strtol() function: CString s = “12zzz”; // bad … Read more

error Please #define _AFXDLL or do not use /MD[d] occurs even after making changes in Project Properties

On Visual Studio 2011, this worked for me: Project -> “project” Properties -> Configuration Properties -> General -> Project Defaults -> Use of MFC : Use MFC in a shared DLL (In Visual Studio 2019, the latter setting can be found in “Properties -> Configuration Properties -> Advanced -> Use of MFC“

Convert CString to const char*

To convert a TCHAR CString to ASCII, use the CT2A macro – this will also allow you to convert the string to UTF8 (or any other Windows code page): // Convert using the local code page CString str(_T(“Hello, world!”)); CT2A ascii(str); TRACE(_T(“ASCII: %S\n”), ascii.m_psz); // Convert to UTF8 CString str(_T(“Some Unicode goodness”)); CT2A ascii(str, CP_UTF8); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)