The MASM Forum

General => The Campus => Topic started by: xandaz on December 19, 2016, 12:33:55 PM

Title: Access Violation with a global variable inside WndProc
Post by: xandaz on December 19, 2016, 12:33:55 PM
   Hi guys. Long time no see. I'm trying to get back on track. The problem is of the sort:
.data
hToolbar  HWND ?
...
.code
...
WndProc...
...
    mov hToolbar,eax ( this right after CreateWndowEx )


olly says access violation.
works with local variables.
thanks
Title: Re: Access Violation with a global variable inside WndProc
Post by: jj2007 on December 19, 2016, 07:23:52 PM
Aggressive linker settings?

Using /MERGE:.data=.text, this one works with polink but with M$ link it crashes:include \masm32\include\masm32rt.inc

.data
global dd ?

.code
start:
  mov global, eax
  print "ok"
  exit
end start
Title: Re: Access Violation with a global variable inside WndProc
Post by: BugCatcher on December 22, 2016, 02:16:53 AM
Doesn't uninitialized data (?) have to be in a unitialized data section .data?
Title: Re: Access Violation with a global variable inside WndProc
Post by: hutch-- on December 22, 2016, 04:48:11 AM
Try this.


.data?        ; <<<< UNinitialised data section.
hToolbar  HWND ?
Title: Re: Access Violation with a global variable inside WndProc
Post by: jj2007 on December 22, 2016, 06:19:14 AM
Quote from: BugCatcher on December 22, 2016, 02:16:53 AM
Doesn't uninitialized data (?) have to be in a unitialized data section .data?

In can be in data?, but it doesn't have to. You increase your exe size by 4 bytes, but that's the only disadvantage.
Title: Re: Access Violation with a global variable inside WndProc
Post by: xandaz on December 23, 2016, 10:41:26 AM
   Really? I thought the question mark didn't matter... let me see. Thanks guys
Title: Re: Access Violation with a global variable inside WndProc
Post by: xandaz on December 23, 2016, 10:43:37 AM
   Not working... this never happened. Could it be one of those stupid things? I have a lot of that. Skipping the obvious details is my speciallty. ty
Title: Re: Access Violation with a global variable inside WndProc
Post by: xandaz on December 23, 2016, 11:10:23 AM
   Solved. Using WSTR instead of UCSTR. Forgot to mention it has been a problem before. ty