News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Manifest plays foul

Started by jj2007, February 07, 2014, 10:21:30 AM

Previous topic - Next topic

jj2007

Simple example:

include \masm32\include\masm32rt.inc

.code
start:
   MsgBox 0, "Hello World", "Masm32:", MB_OK
   exit

end start


Without rc file, no problem. But this one-liner as *.rc makes the MsgBox invisible (Win XP SP3):
1 24 "XpManifest.xml"

Any idea why? The manifest is the usual one:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
   version="1.0.0.0"
   processorArchitecture="*"
   name="whatever"
   type="win32"
/>
<description></description>
<dependency>
   <dependentAssembly>
      <assemblyIdentity
         type="win32"
         name="Microsoft.Windows.Common-Controls"
         version="6.0.0.0"
         processorArchitecture="*"
         publicKeyToken="6595b64144ccf1df"
         language="*"
      />
   </dependentAssembly>
</dependency>
</assembly>

Two observations:
- with call InitCommonControls, it works
- when assembled with the MasmBasic library, it also works, although InitCommonControls is not being called.

dedndave

you can either remove the common controls 6.0 dependency
or reference InitCommonControls/Ex

jj2007

With "reference" you mean this, right?

include \masm32\include\masm32rt.inc

.code
start:
   MsgBox 0, "Hello World", "Masm32:", MB_OK
   exit
   mov eax, InitCommonControls  ; sure that doesn't look logical but it works ;-)

end start

dedndave

i prefer to invoke InitCommonControlsEx and control the flag bits
but, it seems all you really need is a reference
    .DATA

    dd InitCommonControls

    .CODE

;;;


it could be in the code section, i guess - to avoid an additional section
include \masm32\include\masm32rt.inc

.code
start:
   MsgBox 0, "Hello World", "Masm32:", MB_OK
   exit
   dd InitCommonControls

end start

in reality, you have a data section, but it could be eliminated in this case

jj2007

Quote from: dedndave on February 07, 2014, 11:06:37 PM
   exit
   dd InitCommonControls

IMHO it's manifest nonsense but it works :P

TWell

Thank's dedndave and jj2007
Nice trick and it may work in C too ?
void* pICC = InitCommonControls;

dedndave

depending on which C compiler you are using....
it may recognize that you have a manifest in the project,
and add the call to InitCommonControls/Ex into the startup code
that may be done in a way that is transparent to the programmer

in ASM, we have to make up for such things - and this is a good example of that

TWell

Quote from: dedndave on February 08, 2014, 12:02:41 AM
depending on which C compiler you are using....
it may recognize that you have a manifest in the project,
and add the call to InitCommonControls/Ex into the startup code
that may be done in a way that is transparent to the programmer

in ASM, we have to make up for such things - and this is a good example of that
I don't think that C compiler care about manifest, it's a linker thing (and IDE) :icon_confused:

dedndave

i don't use compilers
but i bet if you add a manifest to a visual C project, it will add the needed code to startup
much like it will perform any required initialization/deinitialization of MSVCRT functionality

TWell

Quote from: dedndave on February 08, 2014, 01:25:15 AM
i don't use compilers
but i bet if you add a manifest to a visual C project, it will add the needed code to startup
much like it will perform any required initialization/deinitialization of MSVCRT functionality
MSVCRT: cl.exe with /MD option add /DEFAULTLIB:"MSVCRT" to object file into SECTION  .drectve
similar like INCLUDELIB in masm.
Initialization is somewhere in MSVCRT.DLL's DllMain.

jj2007

dd crt_strlen is not sufficient, i.e. linking in the CRT has no effect.

I've followed the MsgBox down:

MessageBoxTimeout
MessageBoxTimeoutW
MessageBoxIndirect
SoftModalMessageBox
...
call 7E3A490E                   ; XP SP3...
call 7E3A6048                   ; Crucial test
cmp eax, ebx                    ; if not equal, it will be displayed
...
7E3A760C        E8 8A1CFFFF       call PeekMessageW
...
7E3A49BF         E8 B72B0000       call 7E3A757B                   ; The BOX, really


It's tedious...

qWord

you can save 4 bytes by using MASM's EXTERN directive and the linker option /OPT:NOREF
EXTERN InitCommonControls@0:NEAR

:biggrin:
MREAL macros - when you need floating point arithmetic while assembling!

MichaelW

The 1 and 24 are defined in WinUser.h as:

#define CREATEPROCESS_MANIFEST_RESOURCE_ID  1
#define RT_MANIFEST                        24


And also in the MASM32 windows.inc.

Including a reference does work, but for whatever reason per Microsoft you should link with and call the function:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773175(v=vs.85).aspx



Well Microsoft, here's another nice mess you've gotten us into.

dedndave

they are defined in windows.inc, but not in resource.h
i usually do something like this...
#include "\masm32\include\resource.h"

#ifndef  CREATEPROCESS_MANIFEST_RESOURCE_ID
#define  CREATEPROCESS_MANIFEST_RESOURCE_ID  1
#endif

#ifndef  RT_MANIFEST
#define  RT_MANIFEST                         24
#endif

;#####################################################################################

; manifest file

CREATEPROCESS_MANIFEST_RESOURCE_ID RT_MANIFEST "ProjectName.xml"

TWell

#14
Quote from: MichaelW on February 08, 2014, 04:26:09 AM
Including a reference does work, but for whatever reason per Microsoft you should link with and call the function:

http://msdn.microsoft.com/en-us/library/windows/desktop/bb773175(v=vs.85).aspx
Maybe reference is just enough because then dll is loaded and initialized by OS.
Calling function InitCommonControls() leads just stub function codemov eax,eax
ret


Link InitCommonControls by ordinal @17 with library generated from this def-fileLIBRARY comctl32.dll
EXPORTS
InitCommonControls@0 @17