I'm having problems with data declarations in modules:
.386
.model flat, stdcall ; 32 bit memory model
option casemap :none ; case sensitive
include windows.inc
include user32.inc
.data
szText db "Module 4",0
szCaption db "Caption 4",0
.code
Module4 proc hWin:HWND
LOCAL hList:dword
invoke GetDlgItem,hWin,1005 ;Windows API result gets stored in eax
mov hList,eax
invoke SendMessage,hList,LB_ADDSTRING,0,offset szText
invoke SendMessage,hList,LB_ADDSTRING,0,offset lpstMenu ;lpstMenu defined in module.inc
ret
Module4 endp
end
;lpstMenu is declared global and should be visible in all modules? This will give me the following compile error:
Assembling: Mod\Module4.asm
Mod\Module4.asm(21) : error A2006: undefined symbol : lpstMenu
if I try externdef szText or extern szText
I get:
Assembling: Mod\Module4.asm
Mod\Module4.asm(8) : error A2008: syntax error : in directive
Also how to make this visible to all modules?
IDM_File equ 1001 I thought this was a global constant??
What is the proper way to expose global data to other modules?
hi
I understand your sourcecode not and
your correct problem send your sourcecode
i could probely could help you
lpstMenu must declarations in your modules
if that helps you only times
greets ragdog
Here is my code
I'm trying to load my menu from Module4 and display menu string to the list box.
I have commented out the last 2 instructions, so that the program runs.
[attachment deleted by admin]
Klod,
Have a look at the PUBLIC operator in MASM where you declare the data and EXTERNDEF in the module where you use the data. (Spelling corrected on EXTERNDEF).
I hope it help you
greets
ragdog
[attachment deleted by admin]
Thanks to you all
The PUBLIC and EXTERNDEF do the job, but its not exactly what I was after.
After playing around for a bit, it became obvious to me, that the problem I try to solve may be one of scope and of style.
Let me try to explain:
a proc may need data that is global and I would like to keep the declaration in the proc (readability) like this:
EditBoxProc proc
GLOBAL arrEdit dd 6 dup(0) ;global array holding the handles of the edit boxes
GLOBAL rc DD 10,0,90,18,10,23,90,18,10,46,90,18,10,69,90,18,10,93,90,18,10,116,90,18,10,139,90,18 ;coordinates of editboxes
push EBX
push ESI
push EDI
ASSUME eax:PTR RECT
mov esi, offset rc ; base address of tbl rc
mov ebx,0
top:
cmp ebx,6
je lout
mov eax, esi ;offset rc
invoke CreateWindowEx,NULL,SADD("EDIT"),SADD("Test "),\
WS_VISIBLE OR WS_CHILD,[eax].left,[eax].top,[eax].right,\
[eax].bottom,hWnd,NULL,hInstance,NULL
mov DWORD PTR arrEdit[ebx],eax
add esi,16
inc ebx
jmp top
lout:
pop ebx
assume eax:nothing
;invoke SetFocus, arrEdit(3) ;set focus if needed
pop EDI
pop ESI
pop EBX
ret
EditBoxProc endp
This works well if called from within the same module. But if I make call from another module, I get a link error arrEdit not defined. I conclude that arrEdit is global to this module but not to the entire program.
I could call the proc by passing the parameters but this would mean I would have to create stackframes for each call.
Is there a way around this delemma?
hi Klod
here is your souce
hav a nice day :bg
greets
ragdog
[attachment deleted by admin]
Thanks ragdog for your help.
Your code is were I started from, with the exeption that I used the GLOBAL macro instead of the better declaration for the arrays in .data.
The problem I have tryed to solve is that if I have procs that do not create a stack frame, I can't access global data directly, if hInstance is declared in module.inc and i try to access it from module1.asm then I get a compile error:
Mod\Module1.asm(19) : error A2006: undefined symbol : hInstance.
The Public and EXTERN combination that Hutch suggested works, but it defeats my initial idea to declare global data in the module it is first used (my style). Also much more typing.... more errors...
I have found 2 working solutions:
1. to create stack frames and pass the parameters via invoke hInstance, param2 syntax
2. to keep all functions that need access to global data in the same module the global data was declared.
maybe there are more solutions ?
Quote from: Klod on February 25, 2007, 12:21:59 AM
I have found 2 working solutions:
1. to create stack frames and pass the parameters via invoke hInstance, param2 syntax
2. to keep all functions that need access to global data in the same module the global data was declared.
maybe there are more solutions ?
Yes. Declare the data in a .data section in one module. Then in every module (including the one you declared the data in), put EXTERNDEF myData:DWORD (or whatever the names and types are). This is the idea method and is incredibly easy if you create a Globals.inc and put all the EXTERNDEFs in there.
Cheers,
Zooba :U