Compiling DLL with Version Information - winapi

What steps are needed to compile Version Information inside a windows DLL from the command line. I have been looking at VersionInfo files, but could not figure out how to link them to the DLL.
Thank you

You need to create a version resource and add it to your project. This can be very easily done from within visual studio. in VS 2008, right click a folder of the project, choose add and under "Visual C++" select "Resource File" (not resource template), in the resource file just created you'll be able to add a version resource which looks like this:
VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
#else
FILEFLAGS 0x0L
#endif
FILEOS 0x4L
FILETYPE 0x1L
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "FileDescription", "XXX Application"
VALUE "FileVersion", "1, 0, 0, 1"
VALUE "InternalName", "XXX"
VALUE "LegalCopyright", "Copyright (C) 2010"
VALUE "OriginalFilename", "XXX.exe"
VALUE "ProductName", "XXX Application"
VALUE "ProductVersion", "1, 0, 0, 1"
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END
From the command line you'll need to use rc.exe, the resource compiler and then link the result to your dll.

Right-click project name in solution explorer, select Add then Resource. Select Version. In the bottom pane of the newly created VS_VERSION_INFO just modify each value accordingly, re-build and then there will be version info.

You normally put a VersionInfo resource into your .rc file and compile it with the resource compiler (rc.exe). Unfortunately, I don't know of any (recent) documentation of the source format. Imitating what VS produces seems to work all right though...

Related

How do I generate Windows DLL versioning information with CMake?

This is very similar to:
How to Generate Windows DLL versioning information with CMake
but I thought I might asked again since something may have changed since then.
Using the following CMakeLists.txt file:
https://github.com/malaterre/GDCM/blob/master/Source/Common/CMakeLists.txt
I append the following code chunk:
add_library(foo SHARED gdcmVersion.cxx)
set_target_properties(foo PROPERTIES VERSION "1.2.3" SOVERSION "4.5")
I would have assumed this would populate the respective version infos, but it does not on my side:
So my question is: what is actually missing from the above two lines cmake code to get proper version/soversion populated in the details box ?
My setup:
Windows 8.1
Visual Studio 2019 / 16.1.2
CMake 3.14.5
Update: I uploaded a minimal-reproducible-example case here:
https://github.com/malaterre/PublicRep/tree/master/CMake/test3
Using the same setup here is what I see:
Generated version.rc is:
$ cat version.rc
// version.rc.in
#define VER_FILEVERSION 3,5,49,0
#define VER_FILEVERSION_STR "3.5.49.0\0"
#define VER_PRODUCTVERSION 3,5,49,0
#define VER_PRODUCTVERSION_STR "3.5.49\0"
//
After multiple trials and errors, I was able to properly get what I wanted:
So it turns out that the important section is:
1 VERSIONINFO
FILEVERSION VER_FILEVERSION
PRODUCTVERSION VER_PRODUCTVERSION
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904E4"
BEGIN
VALUE "FileVersion", VER_FILEVERSION_STR
VALUE "ProductVersion", VER_PRODUCTVERSION_STR
END
END
/* For some reason the ProductVersion would not appear unless I add */
/* the following section: VarFileInfo */
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x0409, 1252
END
END
References:
https://learn.microsoft.com/fr-fr/windows/win32/menurc/versioninfo-resource
With inspiration from:
https://github.com/Kitware/CMake/blob/master/Source/CMakeVersion.rc.in

error RC2247: Symbol name too long (winnt.h)

I'm getting an RC2247 error (Symbol name too long) when attempting to display the dialogs in a Win32 app. The error is occurring in this file:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\winnt.h
This worked fine under VS2015. The error started when I upgraded to VS2017.
I have seen the following posts, they don't appear to be relevant because they pertain to prsht.h:
RC2247 : Cannot open Rc file : Resource explorer cannot load resource ; Load failed
http://social.msdn.microsoft.com/Forums/en-US/vcprerelease/thread/4a648d6a-ea81-44d3-89c2-57fa5caa6fd6
The error disappears if I comment out the entire resource.rc file. The error occurs if the RC contains the single line:
#include <winnt.h>
When I click on "Edit code"", nothing happens.
I am grateful for any suggestions.
We must not include windows.h or winnt.h to .rc file - this headers - for are for c/c++ compilers and not designed for RC (resource compiler which process .rc file). as result if we include such files we may get errors.
We need include #include <winres.h> to .rc files. this file specially designed for the RC compiler. Internally it included:
#include <winuser.rh>
#include <commctrl.rh>
#include <dde.rh>
#include <winnt.rh>
#include <dlgs.h>
#include <winver.h>
and define some macros.
All standard windows definitions, which we need/use in rc file - exist in winres.h (and it subincludes). From another side in it no extra symbols/definitions wich exist in windows.h - it's not needed for rc and some time can cause errors.
So simply #include <winres.h> at the beginning of resource files and all will be OK.
I have run into this complaint rc2247 when trying to edit the rc file in a project compiled in vs2010. This had been upgraded from vs2050. I found that if I chose to open the .sin file via 'version selector' instead of going straight to vs2010, then it still opens in vs2010 but there is no problem in editing the rc. I don't pretend to understand !
CalendarMan

external assembly file in visual studio

I searched and found I can not use __asm in x64 in visual studio. Instead I have to use an external assembly file.
How can I add external assembly file to my win32 console project?
How can compile them?
Can you explain step by step.
How to build a mixed-source x64-project with a x64 assembly file in Visual Studio:
1) Start Visual Studio (Community) 2015 and choose FILE - New - Project.
2) In the next window choose Win 32 Console Application.
3) You get a confirmation. Click on Next >.
4) In the next window you can accept the default settings. Click on Finish.
5) Make sure, that the project is highlighted in the Solution Explorer and and choose PROJECT - Build Customizations... from the menu.
6) In the next window tick masm(.targets,.props) and click on OK.
7) Choose Build - Configuration Manager...
8) Change the Active solution platform to x64
9) Create callee.asm: PROJECT - Add New Item.
10) In the next window choose C++File(.cpp) and - IMPORTANT! - give it a name with an .asm extension. Click on Add.
10) Now check if the .asm file has the right properties. In the Solution Explorer right-click on the file and choose Properties.
11) In the Property Page you should see at least:
Excluded From Build (empty) or No
Item Type Microsoft Macro Assembler
Under Command Line ensure that ml64.exe is chosen as the assembler.
Click on OK.
12) Now you can fill the files with content.
ConsoleApplication1.cpp:
#include <iostream>
using namespace std;
extern "C" void hello_from_asm();
int main()
{
cout << "Hello from CPP" << endl;
hello_from_asm();
return 0;
}
callee.asm:
PUBLIC hello_from_asm
EXTERN puts:PROC
.data
hello1 db "Hello from ASM.",0
.code
hello_from_asm PROC
push rbp
mov rbp, rsp
sub rsp, 32 ; Shadow Space
and spl, -16 ; Align stack at 16
lea rcx, hello1
call puts
leave ; Restore stack (rsp) & frame pointer (rbp)
ret
hello_from_asm ENDP
END
13) Build the .exe
and run it with CTRL-F5.
The application will be opened in a new window.

Linking to winmm.dll in Visual Studio 2013 Express for mciSendString

I am trying to use mciSendString in visual studio express 2013 (Visual C++) but I keep getting an error
Error 1 error C3861: 'mciSendStringA': identifier not found
I assume this i because I have not linked to the correct dll, but I cannot find any details online or on msdn about how to link to the dll. It seems quite strange that there wouldn't be more obvious documentation about this. Can someone tell me how to link to the dll?
EDIT:
Here is the code I am trying to run:
#include <Windows.h>
#include <iostream>
#include <mmsystem.h>
extern char command1[] = "open C:\\boing.mp3 type MPEGVideo alias 0";
extern char command2[] = "play 0 from 0";
int main()
{
mciSendStringA(command1, NULL, 0, 0);
mciSendStringA(command2, NULL, 0, 0);
}
To make mciSendString() to work, you need to link to winmm.lib.
Just adding winmm.lib to Project Properties > Linker > Input > Additional Dependencies will be fine.
Looking at mmsystem.h (admittedly from the V7.1A Windows SDK, which is the most recent I have installed), I can see that there's a #ifdef _WIN32 block in there. If _WIN32 is not defined, then mciSendStringA is not declared. Instead mciSendString is declared.
Check your project options and ensure that both WIN32 and _WIN32 are defined. I'm guessing that you started from a console project, rather than a Windows Application project, and that at least one of those isn't defined.

Error 3 error LNK1104: cannot open file 'gtk-3.lib'

I have been trying to get GTK 3.0 to work, and have followed all the steps here
How to configure gtk on Visual studio 2010
And changing to 3.0 where needed to get GTK to work, and it seems to have loaded everything it needs in order to compile, but it gives me the error
Error 3 error LNK1104: cannot open file 'gtk-3.lib'
Whenever I try to run the program.
I am using visual studios 2012, but this was the only place i found anything about getting GTK to run on any visual studios.
Here is the code I am using:
#include <gtk-3.0\gtk\gtk.h>
int main(int argc, char* argv[])
{
gtk_init(&argc, &argv);
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
//gtk_widget_get_preferred_size(window, 300, 200);
g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_title(GTK_WINDOW(window), "GTK+ with VS2010");
gtk_widget_show(window);
gtk_main();
return 0;
}
I commented out the gtk_widget_get_prefered_size call because it is irrelevant to the problem
any suggestions? I've looked in several places but none came up with clear answers.
The library gtk-3.lib does not exist. In fact, the library reference is not required to build your GTK 3 application. The pkg-config helper doesn't seem to generate the correct linker flags needed to link your application.
Just add in your Additional Options area all the existing libraries found in your GTK package (\gtk3\lib). The lib files for my bundle (gtk+-bundle_3.6.4-20130921) were as follows:
atk-1.0.lib cairo.lib fontconfig.lib gailutil.lib gdk-win32-3.0.lib gdk_pixbuf-2.0.lib gio-2.0.lib glib-2.0.lib gmodule-2.0.lib gobject-2.0.lib gthread-2.0.lib gtk-win32-3.0.lib pango-1.0.lib pangocairo-1.0.lib pangoft2-1.0.lib pangowin32-1.0.lib
(or you can go to your library path via a command prompt and enter dir *.lib /B)
Don't forget to include the /ENTRY:mainCRTStartup flag mention in the initial answer you started with.
you may have to edit your project settings or use a pragma comment to link with your gtk library:
#pragma comment(lib, "gtk-3")//if the libray is on your project's path
#define PATH "C:\\example\\"
#pragma comment(lib, PATH"gtk-3")//if the library is on PATH

Resources