The MASM Forum Archive 2004 to 2012

Project Support Forums => MASM32 => Topic started by: usingMasm on August 16, 2010, 02:34:42 PM

Title: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 02:34:42 PM
Hi,

When I use a struct with pre-initialized values, my app crashes. the struct is SHELLEXECUTEINFO

Thanks for help.
Title: Re: struct with pre-initialized values crashes
Post by: dedndave on August 16, 2010, 04:12:23 PM
you might try using GetLastError after the ShellExecuteEx call to determine the cause of the error
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 04:55:48 PM
Hi,
   .data

   shellinfo SHELLEXECUTEINFO <60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox ,url,0,SW_MAXIMIZE,0,0,0,0,0,0,0>

This doesn't work. assembler error:
: error A2138: invalid data initializer
: error A2036: too many initial values for structure

   .data
   shellinfo dword 60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox ,url,0,SW_MAXIMIZE,0,0,0,0,0,0,0

This works



Title: Re: struct with pre-initialized values crashes
Post by: jj2007 on August 16, 2010, 04:58:22 PM
Are firefox ,url defined?
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 05:10:25 PM
Quote from: jj2007 on August 16, 2010, 04:58:22 PM
Are firefox ,url defined?

Yes
Bad
   .data
   shellinfo SHELLEXECUTEINFO <60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox ,url,0,SW_MAXIMIZE,0,0,0,0,0,0,0>
   url byte "http://www.masm32.com/board/index.php",0
   firefox byte "C:\Program Files (x86)\Mozilla Firefox\firefox.exe",0

Good
   .data
   shellinfo dword 60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox ,url,0,SW_MAXIMIZE,0,0,0,0,0,0,0
   url byte "http://www.masm32.com/board/index.php",0
   firefox byte "C:\Program Files (x86)\Mozilla Firefox\firefox.exe",0

Title: Re: struct with pre-initialized values crashes
Post by: dedndave on August 16, 2010, 05:32:20 PM
it looks ok - i don't see the problem jumping out at me   :P
i can think of a few things to verify or try

1) certainly, windows.inc must be included prior to any of the data defines (we assume you have that)

2) maybe url and firefox should be defined before shellinfo

3) if all else fails, punt   :bg
shellinfo SHELLEXECUTEINFO <60,dword ptr SEE_MASK_NOCLOSEPROCESS,0,0,offset firefox,offset url,0,dword ptr SW_MAXIMIZE,0,0,0,0,0,0,0>
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 05:44:56 PM
Quote from: dedndave on August 16, 2010, 05:32:20 PM
it looks ok - i don't see the problem jumping out at me   :P
i can think of a few things to verify or try

1) certainly, windows.inc must be included prior to any of the data defines (we assume you have that)

2) maybe url and firefox should be defined before shellinfo

3) if all else fails, punt   :bg
shellinfo SHELLEXECUTEINFO <60,dword ptr SEE_MASK_NOCLOSEPROCESS,0,0,offset firefox,offset url,0,dword ptr SW_MAXIMIZE,0,0,0,0,0,0,0>

.data?
   shellinfo SHELLEXECUTEINFO <?>

This works. but then all members need to be filled by code.

windows.inc is included
defining url and firefox before shellinfo makes no difference.

I think I am doing something wrong. or is it a Masm bug?
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 06:04:13 PM
It accepts 13 members for the struct. but the struct has 15 members. so

   shellinfo SHELLEXECUTEINFO <60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox ,url,0,SW_MAXIMIZE,0,0,0,0,0>
assembles.
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 06:09:45 PM
I think it has to do with the   
union   
hIcon     DWORD       0
      hMonitor  DWORD       0
  ends

which is embedded within the struct.
Title: Re: struct with pre-initialized values crashes
Post by: dedndave on August 16, 2010, 06:19:34 PM
we have used that union syntax on many other items
it would be strange if it was the problem
but, you can test your theory by temporarily modifying the structure definition
probably easiest to just define a new structure in your asm file, named something else, that has 15 dwords
what version of masm are you using ?
Title: Re: struct with pre-initialized values crashes
Post by: jj2007 on August 16, 2010, 06:22:41 PM
Quote from: usingMasm on August 16, 2010, 06:09:45 PM
I think it has to do with the   
union   
hIcon     DWORD       0
      hMonitor  DWORD       0
  ends

which is embedded within the struct.


Example without union:

include \masm32\include\masm32rt.inc

SHELLEXECUTEINFOX STRUCT
  cbSize        DWORD       ?
  fMask         DWORD       ?
  hwnd          DWORD       ?
  lpVerb        DWORD       ?
  lpFile        DWORD       ?
  lpParameters  DWORD       ?
  lpDirectory   DWORD       ?
  nShow         DWORD       ?
  hInstApp      DWORD       ?
  lpIDList      DWORD       ?
  lpClass       DWORD       ?
  hkeyClass     DWORD       ?
  dwHotKey      DWORD       ? ; NO UNION
  hIcon     DWORD       ?
  hProcess      DWORD       ?
SHELLEXECUTEINFOX ENDS

.data
   url byte "http://www.masm32.com/board/index.php",0
   firefox byte "C:\Program Files (x86)\Mozilla Firefox\firefox.exe",0
   shellinfo1 SHELLEXECUTEINFOX <60, SEE_MASK_NOCLOSEPROCESS, 0, 0, firefox, url, 0, SW_MAXIMIZE>
   shellinfo2 SHELLEXECUTEINFOX <60, SEE_MASK_NOCLOSEPROCESS, 0, 0, firefox, url, 0, SW_MAXIMIZE, 0, 0, 0, 0, 0, 0, 0>

.code
start: inkey "OK"
exit
end start


Mysterious. Jwasm behaves the same. Apparently you can declare less members.
Title: Re: struct with pre-initialized values crashes
Post by: dedndave on August 16, 2010, 06:25:35 PM
don't suppose "shellinfo" or "url" are used elsewhere
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 06:35:03 PM
Quote from: dedndave on August 16, 2010, 06:19:34 PM
we have used that union syntax on many other items
it would be strange if it was the problem
but, you can test your theory by temporarily modifying the structure definition
probably easiest to just define a new structure in your asm file, named something else, that has 15 dwords
what version of masm are you using ?

latest version.
I did a struct of my own with 15 members. didn't work.
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 06:38:12 PM
Quote from: dedndave on August 16, 2010, 06:25:35 PM
don't suppose "shellinfo" or "url" are used elsewhere

no
Title: Re: struct with pre-initialized values crashes
Post by: jj2007 on August 16, 2010, 06:57:06 PM
It works without the UNION. Apparently M$ had that problem earlier and didn't fix it properly:
FIX: A2138, A2036 or Hang, Init Nested Structure Array (http://support.microsoft.com/kb/94912)

We may have never noticed this bug because most members don't use initialised structures.
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 07:08:33 PM
Quote from: jj2007 on August 16, 2010, 06:57:06 PM
It works without the UNION. Apparently M$ had that problem earlier and didn't fix it properly:
FIX: A2138, A2036 or Hang, Init Nested Structure Array (http://support.microsoft.com/kb/94912)

We may have never noticed this bug because most members don't use initialised structures.

the fix has apparently not fixed it. I am using the latest masm. and the struct doesn't have any dup operator. it seems 13 is as many members as can be initialized.
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 07:26:47 PM
it is worse than that. declaring "shellinfo SHELLEXECUTEINFO <>" in .data section and filling the members with code assembles but causes system crash. seems it is accessing some forbidden memory sections. only .data? section works.
Title: Re: struct with pre-initialized values crashes
Post by: jj2007 on August 16, 2010, 07:45:45 PM
Quote from: usingMasm on August 16, 2010, 07:08:33 PM
Quote from: jj2007 on August 16, 2010, 06:57:06 PM
It works without the UNION. Apparently M$ had that problem earlier and didn't fix it properly:
FIX: A2138, A2036 or Hang, Init Nested Structure Array (http://support.microsoft.com/kb/94912)

We may have never noticed this bug because most members don't use initialised structures.

the fix has apparently not fixed it. I am using the latest masm. and the struct doesn't have any dup operator. it seems 13 is as many members as can be initialized.

It works perfectly with 15 members if you redefine the structure without the UNION. Tested with ml 6.15, 9.0 and JWasm.
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 09:07:39 PM
Quote from: jj2007 on August 16, 2010, 07:45:45 PM
Quote from: usingMasm on August 16, 2010, 07:08:33 PM
Quote from: jj2007 on August 16, 2010, 06:57:06 PM
It works without the UNION. Apparently M$ had that problem earlier and didn't fix it properly:
FIX: A2138, A2036 or Hang, Init Nested Structure Array (http://support.microsoft.com/kb/94912)

We may have never noticed this bug because most members don't use initialised structures.

the fix has apparently not fixed it. I am using the latest masm. and the struct doesn't have any dup operator. it seems 13 is as many members as can be initialized.

It works perfectly with 15 members if you redefine the structure without the UNION. Tested with ml 6.15, 9.0 and JWasm.

it assembles but ShellExecuteEx returns access denied.
Title: Re: struct with pre-initialized values crashes
Post by: drizz on August 16, 2010, 09:52:55 PM
Quote from: jj2007 on August 16, 2010, 06:57:06 PMmost members don't use initialised structures.
Speak for yourself please  :snooty:

unions are initialized the same way as structures, see here (jj take notes  :wink):
http://www.masm32.com/board/index.php?topic=10272.msg75289#msg75289

shellinfo SHELLEXECUTEINFO <60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox,url,0,SW_MAXIMIZE,0,0,0,0,0,<0>,0>

Quote from: usingMasm on August 16, 2010, 09:07:39 PMit assembles but ShellExecuteEx returns access denied.
And you tried running it as an Administrator?
Title: Re: struct with pre-initialized values crashes
Post by: usingMasm on August 16, 2010, 10:17:15 PM
Quote from: drizz on August 16, 2010, 09:52:55 PM
Quote from: jj2007 on August 16, 2010, 06:57:06 PMmost members don't use initialised structures.
Speak for yourself please  :snooty:

unions are initialized the same way as structures, see here (jj take notes  :wink):
http://www.masm32.com/board/index.php?topic=10272.msg75289#msg75289

shellinfo SHELLEXECUTEINFO <60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox,url,0,SW_MAXIMIZE,0,0,0,0,0,<0>,0>

Quote from: usingMasm on August 16, 2010, 09:07:39 PMit assembles but ShellExecuteEx returns access denied.
And you tried running it as an Administrator?


Thanks a lot.
shellinfo SHELLEXECUTEINFO <60,SEE_MASK_NOCLOSEPROCESS,0,0,firefox,url,0,SW_MAXIMIZE,0,0,0,0,0,<0>,0>

works perfect.
Title: Re: struct with pre-initialized values crashes
Post by: jj2007 on August 16, 2010, 11:23:11 PM
Quote from: drizz on August 16, 2010, 09:52:55 PM
(jj take notes  :wink)

I will, thanks :U
Title: Re: struct with pre-initialized values crashes
Post by: dedndave on August 16, 2010, 11:26:24 PM
very cool Drizz - thanks for the help
i will take notes also   :P