hkBattousai
hkBattousai

Reputation: 10931

InitCommonControlsEx() fails with ICC_LINK_CLASS in Windows 8.1

I'm trying to put a simple hyperlink on my window.

INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(INITCOMMONCONTROLSEX);
iccx.dwICC  = ICC_LINK_CLASS;   // CommCtrl.h: #define ICC_LINK_CLASS 0x00008000
bool bResult = InitCommonControlsEx(&iccx); // bResult is false.
DWORD dwError = GetLastError(); // dwError is 0.

hWnd = CreateWindowExW( /*_In_      DWORD*/     0,
                        /*_In_opt_  LPCTSTR*/   WC_LINK, // CommCtrl.h: #define WC_LINK L"SysLink"
                        /*_In_opt_  LPCTSTR*/   L"Hello World",
                        /*_In_      DWORD*/     WS_VISIBLE | WS_CHILD | WS_TABSTOP,
                        /*_In_      int*/       50,
                        /*_In_      int*/       200,
                        /*_In_      int*/       100,
                        /*_In_      int*/       20,
                        /*_In_opt_  HWND*/      hWndParent,
                        /*_In_opt_  HMENU*/     NULL,
                        /*_In_opt_  HINSTANCE*/ hInstance,
                        /*_In_opt_  LPVOID*/    NULL);
DWORD dwError = GetLastError(); // hWnd is NULL and dwError is 1407.

The error code 1407 is explained in here as follows.

ERROR_CANNOT_FIND_WND_CLASS
    1407 (0x57F)
    Cannot find window class.

I'm using Windows 8.1 Pro x64, and I have never tried this code on any other version of Windows.

What is the problem here?

Upvotes: 0

Views: 1483

Answers (1)

andlabs
andlabs

Reputation: 11588

As you have figured out, adding

#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")

is one way to fix the problem.

The SysLink control was only added in Common Controls version 6. For backwards compatibility reasons, Common Controls 6 is NOT enabled by default. You have to opt into it by creating a manifest.

A manifest can exist as either a separate file (named program.exe.manifest) or as a resource with a specific resource ID. The #pragma line tells Microsoft's linker to generate the second one for you. You can also produce either form on your own. Here's how.

Upvotes: 3

Related Questions