Windows Common Controls (Using specific version) [duplicate] - c++

This question already has answers here:
An XP style combobox in a DLL
(2 answers)
Closed 6 years ago.
I need to use Windows Common Controls v6.0 to see new style UIs.
I know I can do it by a manifest dependency but when I haven't access to the manifest (or source code... it's not my app but I have a DLL which will be attached to the process and every CommCtrls I need will be called from that DLL) what should I do to specify Windows Common Controls version for that process? Is there any API or someway to do it?
[By the way, I'm using C++ & VS2015]

Try this in your DLL:
#if defined(_M_IX86)
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined(_M_X64)
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif

Related

__declspec(dllexport) static linked libraries to dll

I have a simple project setup for an OpenGL-project for University.
An API project where every library I want to use (GLEW, GLFW, GLM) is linked statically. These libraries should be combined with my own API code into one single DLL file.
The other project should only have one dependency, the DLL. Throw that DLL it should get access to the API code and all libraries linked inside the API.
My problem is that inside the API I have access to all functions of all libraries I linked. But inside the actual project which has the API as a dependency, I can call the functions and the compiler throws out no error (of cause) because the function declaration is in the linked header files but the linker does not find the function definition inside the DLL, which mean the build of the API does not export the linked libraries into the DLL.
In the API project, I also defined the necessary preprocessor definitions:
I defined _GLFW_BUILD_DLL:
from "glfw3.h" l. 233-245
/* GLFWAPI is used to declare public API functions for export
* from the DLL / shared library / dynamic library.
*/
#if defined(_WIN32) && defined(_GLFW_BUILD_DLL)
/* We are building GLFW as a Win32 DLL */
#define GLFWAPI __declspec(dllexport) <----- this one is active
#elif defined(_WIN32) && defined(GLFW_DLL)
/* We are calling GLFW as a Win32 DLL */
#define GLFWAPI __declspec(dllimport)
#elif defined(__GNUC__) && defined(_GLFW_BUILD_DLL)
/* We are building GLFW as a shared / dynamic library */
#define GLFWAPI __attribute__((visibility("default")))
#else
/* We are building or calling GLFW as a static library */
#define GLFWAPI
#endif
I defined GLEW_BUILD:
from "glew.h" l. 200-208
#ifdef GLEW_STATIC
#define GLEWAPI extern
#else
#ifdef GLEW_BUILD
#define GLEWAPI extern __declspec(dllexport) <---- this one is active
#else
#define GLEWAPI extern __declspec(dllimport)
#endif
#endif
Any help?
EDIT:
The linker options:
/OUT:"D:\Programmierung\C++-Projekte\CG-Project\CGAPI\bin\Debug\Win32\CGAPI.dll" /MANIFEST /NXCOMPAT /PDB:"D:\Programmierung\C++-Projekte\CG-Project\CGAPI\bin\Debug\Win32\CGAPI.pdb" /DYNAMICBASE "glew32s.lib" "glfw3.lib" "opengl32.lib" "kernel32.lib" "user32.lib" "gdi32.lib" "winspool.lib" "comdlg32.lib" "advapi32.lib" "shell32.lib" "ole32.lib" "oleaut32.lib" "uuid.lib" "odbc32.lib" "odbccp32.lib" /IMPLIB:"D:\Programmierung\C++-Projekte\CG-Project\CGAPI\bin\Debug\Win32\CGAPI.lib" /DEBUG /DLL /MACHINE:X86 /INCREMENTAL /PGD:"D:\Programmierung\C++-Projekte\CG-Project\CGAPI\bin\Debug\Win32\CGAPI.pgd" /SUBSYSTEM:WINDOWS /MANIFESTUAC:NO /ManifestFile:"D:\Programmierung\C++-Projekte\CG-Project\CGAPI\bin-int\Debug\Win32\CGAPI.dll.intermediate.manifest" /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"D:\Programmierung\C++-Projekte\CG-Project\Dependencies\GLFW\Win32\lib-vc2019\" /LIBPATH:"D:\Programmierung\C++-Projekte\CG-Project\Dependencies\GLEW\lib\Release\Win32\" /TLBID:1
The one I added:
/WHOLEARCHIVE:glew32s.lib
/WHOLEARCHIVE:glfw3.lib
/WHOLEARCHIVE:opengl32.lib
EDIT 2:
So I had to download the source code from glew and build it myself and also I had to remove the .res file inside the option of my own glew build. Now the API builds successfully but the methods aren't part of the DLL. So nothing changed.
I don't fully understand your motivation for doing things this way. The common approach (that I'd also use) is shipping the OpenGL .dlls (I'm not aware of the licensing implications) along with yours.
However, even if this looks like an XY Problem, in order to achieve your goal, you could pass [MS.Docs]: /WHOLEARCHIVE (Include All Library Object Files) to the linker. In order to differentiate which .libs to include and which not, specify the flag once per each target library: /wholearchive:glew32.lib /wholearchive:glfw3.lib /wholearchive:glm.lib.
Check [SO]: Exporting symbols in static library that is linked to dynamic library (#CristiFati's answer) for more details.
As a note: the .libs must have been built with exportable symbols. If not, you'll have to export them "manually", using one of the other choices:
/EXPORT linker option
Module definition (.def) files
or rebuild the .lib as static but with exportable symbols. However, there's high chance it won't work OOTB (you'l probably need to modify a file or 2 or manually pass a compile flag), as it's not a normal way (most of the people would agree that's a NO-NO, especially for someone without a fairly deep know-how) of doing things.

C++ POCO build error

I am trying to use the POCO C++ library in my existing Windows CE project on Visual Studio 2008.
I have compiled the POCO library using the provided .bat files. I used the one nammed build_CE_vs90.cmd and it successfully generated several .lib files.
However a header of the POCO library (Foundation.h) has a pragma to automatically link the right .lib file :
#if defined(_MSC_VER)
#if defined(POCO_DLL)
#if defined(_DEBUG)
#define POCO_LIB_SUFFIX "d.lib"
#else
#define POCO_LIB_SUFFIX ".lib"
#endif
#elif defined(_DLL)
#if defined(_DEBUG)
#define POCO_LIB_SUFFIX "mdd.lib"
#else
#define POCO_LIB_SUFFIX "md.lib"
#endif
#else
#if defined(_DEBUG)
#define POCO_LIB_SUFFIX "mtd.lib"
#else
#define POCO_LIB_SUFFIX "mt.lib"
#endif
#endif
#if !defined(POCO_NO_AUTOMATIC_LIBS) && !defined(Foundation_EXPORTS)
#pragma comment(lib, "PocoFoundation" POCO_LIB_SUFFIX)
#endif
#endif
The problem is that POCO_LIB_SUFFIX is defined as "mtd.lib" and I have no "mtd" version of the lib in the directory where the .lib files are. I only have PocoFoundation.lib and PocoFoundationd.lib, but no PocoFoundationmtd.lib, which is causing an error while linking because the file is not found.
I have compiling my project using :
POCO_STATIC
POCO_NO_UNWINDOWS
I openned the build .bat script and it does contain the argument "static_mt" passed to the main build file :
#echo off
buildwin 90 build static_mt both WinCE samples
What am I missing ? Thank you.
You're compiling your project with DEBUG config, change it and undef POCO_STATIC (it's the MultiThread build), for some reason you compiled the shared version, that's why you've the .lib file without any suffix.

Changing style of CListCtrl in MFC

I have a ListCtrl in one of the dialog of a mfc application. I want to change the column name style and the button style to look more like win7 themed. this is the old dialog with the listCtrl in right.
what I want to change the top row of the table and the buttons to something like this ,
can this be done by changing any style by doing m_ElementListCtrl.SetExtendedStyle(..) ? or chaning some of its properties ?
Hi If your app is Unicode(otherwise there is some problems) you need to use Common controls 6.
In your stdafx.h file you probably could see this kind of code , if no , just add it in the end of file, if you change your app to UNICODE you will see controls with new style.
#ifdef _UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32'name='Microsoft.Windows.Common-Controls' version='6.0.0.0'processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
Also check Project Properties -> linker-> Manifest File-> Generate Manifest should be set on Yes (/MANIFEST)

MFC SysLink Control

when ever am adding MFC SysLink Control to my application , it forces the application to close , am using VC++ 11 , and am just dragging a syslink control tool to my dialog box, any clue why it forces the app to close?
I had similar problem. SysLink requires Common Control 6.0 defined in the manifest. I solved it by adding the following line in the project
#pragma comment(linker,"\"/manifestdependency:type='win32' \
name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \
processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
You must set Generate manifest=yes in the properties-linker-manifest files.

MFC CMenu tooltip not being displayed

I tried using something like this to set the tool tip of a CMenu item (as described here) but it is just being displayed in a single line and the line break is not visible.
// read control id
UINT id = menu->GetMenuItemID(1235);
// modify caption and add tooltip?
menu->ModifyMenu( id, MF_BYCOMMAND, id, "Click here\nThis is the tooltip for the menu item ...");
I also tried to set the caption directly in the visual studio resource designer of the menu item with the same effect.
Can you give me any hints on whats wrong? I am using VS2008 on windows 7.
Any help is appreciated!
Perhaps you have not added the windows xp common controls to your application.
Try adding the common controls to your stdafx.h:
#ifdef UNICODE
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_IA64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif
#endif
Looks like an duplicate
Mainly you should use \r\n instead of \n because this is what mfc expects.