Author Topic: Manifest plays foul  (Read 6925 times)

jj2007

  • Member
  • *****
  • Posts: 10087
  • Assembler is fun ;-)
    • MasmBasic
Manifest plays foul
« on: February 07, 2014, 10:21:30 AM »
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

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: Manifest plays foul
« Reply #1 on: February 07, 2014, 10:28:25 AM »
you can either remove the common controls 6.0 dependency
or reference InitCommonControls/Ex

jj2007

  • Member
  • *****
  • Posts: 10087
  • Assembler is fun ;-)
    • MasmBasic
Re: Manifest plays foul
« Reply #2 on: February 07, 2014, 06:02:47 PM »
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

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: Manifest plays foul
« Reply #3 on: February 07, 2014, 11:06:37 PM »
i prefer to invoke InitCommonControlsEx and control the flag bits
but, it seems all you really need is a reference
Code: [Select]
    .DATA

    dd InitCommonControls

    .CODE

;;;

it could be in the code section, i guess - to avoid an additional section
Code: [Select]
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

  • Member
  • *****
  • Posts: 10087
  • Assembler is fun ;-)
    • MasmBasic
Re: Manifest plays foul
« Reply #4 on: February 07, 2014, 11:33:55 PM »
   exit
   dd InitCommonControls

IMHO it's manifest nonsense but it works :P

TWell

  • Member
  • ****
  • Posts: 748
Re: Manifest plays foul
« Reply #5 on: February 07, 2014, 11:41:08 PM »
Thank's dedndave and jj2007
Nice trick and it may work in C too ?
Code: [Select]
void* pICC = InitCommonControls;

dedndave

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: Manifest plays foul
« Reply #6 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

TWell

  • Member
  • ****
  • Posts: 748
Re: Manifest plays foul
« Reply #7 on: February 08, 2014, 01:15:49 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

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: Manifest plays foul
« Reply #8 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

TWell

  • Member
  • ****
  • Posts: 748
Re: Manifest plays foul
« Reply #9 on: February 08, 2014, 02:04:47 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

  • Member
  • *****
  • Posts: 10087
  • Assembler is fun ;-)
    • MasmBasic
Re: Manifest plays foul
« Reply #10 on: February 08, 2014, 02:59:19 AM »
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

  • Member
  • *****
  • Posts: 1473
  • The base type of a type is the type itself
    • SmplMath macros
Re: Manifest plays foul
« Reply #11 on: February 08, 2014, 03:23:41 AM »
you can save 4 bytes by using MASM's EXTERN directive and the linker option /OPT:NOREF
Code: [Select]
EXTERN InitCommonControls@0:NEAR
 :biggrin:
MREAL macros - when you need floating point arithmetic while assembling!

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: Manifest plays foul
« Reply #12 on: February 08, 2014, 04:26:09 AM »
The 1 and 24 are defined in WinUser.h as:
Code: [Select]
#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

  • Member
  • *****
  • Posts: 8825
  • Still using Abacus 2.0
    • DednDave
Re: Manifest plays foul
« Reply #13 on: February 08, 2014, 09:05:26 AM »
they are defined in windows.inc, but not in resource.h
i usually do something like this...
Code: [Select]
#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

  • Member
  • ****
  • Posts: 748
Re: Manifest plays foul
« Reply #14 on: February 08, 2014, 09:55:28 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 code
Code: [Select]
mov eax,eax
ret

Link InitCommonControls by ordinal @17 with library generated from this def-file
Code: [Select]
LIBRARY comctl32.dll
EXPORTS
InitCommonControls@0 @17
« Last Edit: February 08, 2014, 01:40:46 PM by TWell »