0

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?

hkBattousai
  • 10,583
  • 18
  • 76
  • 124
  • 4
    Did you forget the Common Controls 6 manifest? SysLink controls require Common Controls 6. – andlabs Oct 11 '15 at 01:56
  • @andlabs First time hearing it. I will google it now. Thanks. – hkBattousai Oct 11 '15 at 02:04
  • After a little internet research, I was able to solve my problem by adding the code `#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")` just after including CommCtrl.h by `#include `. Yet, I don't know the explanation of what I did. – hkBattousai Oct 11 '15 at 02:53
  • 2
    That line instructs the Microsoft linker to add a Common Controls 6 manifest. See [this page](http://msdn.microsoft.com/en-us/library/windows/desktop/bb773175%28v=vs.85%29.aspx) for more details. Windows requires you to do this to opt into the new version of the Common Controls library [for backward compatibility reasons](http://blogs.msdn.com/b/oldnewthing/archive/2008/01/29/7294949.aspx). – andlabs Oct 11 '15 at 03:13

1 Answers1

3

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.

andlabs
  • 11,290
  • 1
  • 31
  • 52