News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

struct with pre-initialized values crashes

Started by usingMasm, August 16, 2010, 02:34:42 PM

Previous topic - Next topic

usingMasm

Hi,

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

Thanks for help.

dedndave

you might try using GetLastError after the ShellExecuteEx call to determine the cause of the error

usingMasm

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




jj2007


usingMasm

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


dedndave

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>

usingMasm

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?

usingMasm

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.

usingMasm

I think it has to do with the   
union   
hIcon     DWORD       0
      hMonitor  DWORD       0
  ends

which is embedded within the struct.

dedndave

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 ?

jj2007

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.

dedndave

don't suppose "shellinfo" or "url" are used elsewhere

usingMasm

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.

usingMasm


jj2007

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

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