Home All Groups Group Topic Archive Search About

Specify DLL version when using mc.exe, rc.exe and/or link.exe

Author
15 Aug 2010 3:39 AM
Tony Toews
Folks

I'm creating a single entry DLL for the OS application event log so
developers and admin types don't get that ugly message when looking at
errors in the event log.

I've got the following make file which is working but I see the dll
produced does not have a version property like most DLLs and EXEs.
Any ideas on how to do such?   Any better newsgroups/forums to ask
this question?

del "test.dll"
"C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\mc.exe" MsgFile.mc
"C:\Program Files\Microsoft SDKs\Windows\v6.1\Bin\rc" -r -fo
MsgFile.res MsgFile.rc
del MSG00001.bin
del MsgFile.h
del MsgFile.rc
"C:\Program Files\Microsoft Visual Studio\VB98\link" /nologo /NOENTRY
/subsystem:windows /dll /machine:I386 /out:"test.dll" MsgFile.res
del msgfile.res

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
  updated see http://www.autofeupdater.com/

Author
15 Aug 2010 5:38 AM
Tony Toews
On Sat, 14 Aug 2010 21:39:27 -0600, Tony Toews
<tto***@telusplanet.net> wrote:

>I'm creating a single entry DLL for the OS application event log so
>developers and admin types don't get that ugly message when looking at
>errors in the event log.

That should be

creating a single entry message file DLL for

>I've got the following make file which is working but I see the dll
>produced does not have a version property like most DLLs and EXEs.
>Any ideas on how to do such?   Any better newsgroups/forums to ask
>this question?

This page  http://msdn.microsoft.com/en-us/library/ms853727.aspx might
have a lot of what I need if I can figure it out.   I'm sorta making
progress.

Tony

--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
  updated see http://www.autofeupdater.com/
Author
15 Aug 2010 3:25 PM
Nobody
First, in order to provide the DLL to Event Viewer so the messages look like
what you want, you need to add a subkey and values to HKLM, and a limited
user can't write to it, so this need to be added in an installer. Here is
the subkey that you need to add:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\AutoFEUpdater

And you need to add 2 values in the subkey above:

EventMessageFile(REG_SZ)=<Full path to DLL or EXE with MSG00001.bin added as
a resource>
TypesSupported(REG_DWORD)=7

"7" in TypesSupported means support for Error, Warning, and Information
types.

So to use a custom DLL, you need to add the values above first. Your users'
admins probably could do that if they use PsExec to run RegEdit silently and
remotely. They can also do it from RegEdit-->File-->Connect to Network
Registry, and specify the remote computer name to see its registry. You can
also do it in VB by calling RegConnectRegistry() and specify the computer
name. Randy Birch site has code to list computers in a domain, so it can be
done from your software, however, that function would return
ERROR_ACCESS_DENIED(5) if the user didn't use "Run as Administrator" to run
your program.

As for version information, you need to add the following to the RC file,
and change as needed:

////////////////////////////
//
// Version
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,0,0,1
PRODUCTVERSION 1,0,0,1
FILEFLAGSMASK 0x3fL
FILEFLAGS 0x0L
FILEOS 0x4L
FILETYPE 0x2L
FILESUBTYPE 0x0L
BEGIN
    BLOCK "StringFileInfo"
    BEGIN
        BLOCK "040904b0"
        BEGIN
            VALUE "Comments", "\0"
            VALUE "CompanyName", "My Company\0"
            VALUE "FileDescription", "Auto FE Updater Event Log Messages\0"
            VALUE "FileVersion", "1, 0, 0, 1\0"
            VALUE "InternalName", "AutoFEUpdater\0"
            VALUE "LegalCopyright", "\0"
            VALUE "LegalTrademarks", "\0"
            VALUE "OriginalFilename", "AutoFEUpdaterLog.dll\0"
            VALUE "PrivateBuild", "\0"
            VALUE "ProductName", "Auto FE Updater Event Log Messages\0"
            VALUE "ProductVersion", "1, 0, 0, 1\0"
            VALUE "SpecialBuild", "\0"
        END
    END
    BLOCK "VarFileInfo"
    BEGIN
        VALUE "Translation", 0x409, 1200
    END
END



Change FILEVERSION and PRODUCTVERSION, including in the block that lists
VALUE's to what you want. The way you are doing it is not the only way, you
can make the DLL in VB. Compile "mc" file into "bin" file as usual but
without the version resource, as VB adds that for you, then add MSG00001.bin
as a resource to your project using "Visual Basic 6 Resource Editor" Add-in.
You can add it to your EXE, but if Event Viewer is open, it maybe keeping
the file loaded, so it would be difficult to replace.

For those curious what the OP is talking about, when you use the following
line of code in VB:

App.LogEvent "Message from VB6.", vbLogEventTypeInformation

The event source in Event Viewer shows "VBRuntime", and here is what is
logged(The URL is also added by the VB runtime, and not by the OS):

=================

Event Type: Information
Event Source: VBRuntime
Event Category: None
Event ID: 1
Date:  8/15/2010
Time:  10:24:37 AM
User:  N/A
Computer: MYPC
Description:
The VB Application identified by the event source logged this Application
Project1: Thread ID: 4560 ,Logged: Message from VB6.

For more information, see Help and Support Center at
http://go.microsoft.com/fwlink/events.asp.

=================

If you try to use the API directly by calling ReportEvent() function without
making the messages DLL, this is what appears in Event Viewer:


=================
Event Type: Information
Event Source: MyEventSource
Event Category: None
Event ID: 100
Date:  8/15/2010
Time:  10:06:10 AM
User:  N/A
Computer: MYPC
Description:
The description for Event ID ( 100 ) in Source ( MyEventSource ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event: Message
from VB6..

=================

Note how the message that you actually written appears at the end of the
description. If you specify the DLL for Event Viewer, only what you provided
appears there. Some link about what message files are:

Message Files:
http://msdn.microsoft.com/en-us/library/aa363669%28VS.85%29.aspx

Once you made your text message file, you use the following command to turn
it into a BIN file that is ready to be included as a resource:

mc filename.mc

"mc" comes with the Platform SDK, and VC6, but not with VC 2003/2005/2008.
Author
16 Aug 2010 4:45 AM
Tony Toews
On Sun, 15 Aug 2010 11:25:58 -0400, "Nobody" <nob***@nobody.com>
wrote:

>First, in order to provide the DLL to Event Viewer so the messages look like
>what you want, you need to add a subkey and values to HKLM, and a limited
>user can't write to it, so this need to be added in an installer. Here is
>the subkey that you need to add:
>
>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Eventlog\Application\AutoFEUpdater

Already done that.   I've got Wix working quite nicely generating an
MSI file.

>And you need to add 2 values in the subkey above:
>
>EventMessageFile(REG_SZ)=<Full path to DLL or EXE with MSG00001.bin added as
>a resource>
>TypesSupported(REG_DWORD)=7
>
>"7" in TypesSupported means support for Error, Warning, and Information
>types.

Interesting because in my testing you don't need the TypesSupported
registry key.   You do need the EventMessageFile registry key. 

Side note.  The users don't need the above DLL or registry key to
record the entries.   The folks, such as the developers or admins, who
view the event log do need the DLL and registry key.

>As for version information, you need to add the following to the RC file,
>and change as needed:

I added what you specified and I still can't see the version info tab
when I right click on the DLL.   I doubled checked the .res and the
..dll file produced using Notepad and the information specified was in
there

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
  updated see http://www.autofeupdater.com/
Author
16 Aug 2010 11:34 AM
Nobody
"Tony Toews" <tto***@telusplanet.net> wrote in message
news:67gh66t9c7le78eb5g2pe0mfruo6521s6d@4ax.com...
> I added what you specified and I still can't see the version info tab
> when I right click on the DLL.   I doubled checked the .res and the
> .dll file produced using Notepad and the information specified was in
> there

If you have VC6, then remove the changes, and open the RC file, then go to
Insert-->Resource-->Version, and just type the information. Unfortunately,
you can't edit RC files in the express versions of VC. If you don't have
VC6, then try some of the software listed in this page:

http://en.wikipedia.org/wiki/Resource_%28Windows%29

Among the free ones, ResEdit and XN Resource Editor seem to be able to
import RC files.
Author
18 Aug 2010 4:08 AM
Tony Toews
On Mon, 16 Aug 2010 07:34:05 -0400, "Nobody" <nob***@nobody.com>
wrote:

>> I added what you specified and I still can't see the version info tab
>> when I right click on the DLL.   I doubled checked the .res and the
>> .dll file produced using Notepad and the information specified was in
>> there
>
>If you have VC6,

I do but not installed.   I'll try installing it and see if that works

>If you don't have
>VC6, then try some of the software listed in this page:
>
>http://en.wikipedia.org/wiki/Resource_%28Windows%29
>
>Among the free ones, ResEdit and XN Resource Editor seem to be able to
>import RC files.

So I tried ResEdit.  It put in a few slightly different lines/syntax
than you have along with all kinds of external variables.  So I tried
importing the various .h files required from the SDK folder until it
complained about a file called sal.h.  Which might be in the VC folder
that I'll install later.

So then I tried taking the ResEdit file it produced and replacing the
constants with the values from your file.   Compiled cleanly but still
no version properties.

I then tried the XN Resource Editor which inserted the data directly
into  into a RES file rather than the RC file.  I then ran the Link
and still no version number when I right clicked the DLL.

Tony
--
Tony Toews, Microsoft Access MVP
Tony's Main MS Access pages - http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
For a convenient utility to keep your users FEs and other files
  updated see http://www.autofeupdater.com/