Hey all,

I'm in programming hell! Weird things are happening with one of my assembly programs, things that are simply beyond my comprehension...

I've created a program that changes mixer settings. The problem is that on WinXP & 2K the program works or fails based on the way the variables in the data section are arranged (oh yeah, hard to believe :mad: ). The function that fails is mixerGetControlDetails. This function uses only 2 structs (MIXERCONTROLDETAILS and MIXERCONTROLDETAILS_BOOLEAN) and a handle. Different arrangements of the variables in the data section can make or break this proggie.

I've isolated several patterns that work. Moving the block

Mute db 5 dup (0)

to the beginning of the data section with a Blank db 0 dup(11) ahead of it, will make it work. If you comment out the Mute while leaving the Blank, it will fail once again. Removing the Blank but leaving Mute will once again cause it to fail.

The same block (without Blank) can be added after

(see attachment for the overall order of variable in my proggie)

and the function will work once again. Keeping the position of the block, and commenting out the Mute, will cause the function to fail once again.

I've tried to think about what these arrangements tell me, but I haven't yet figured it out. I thought that maybe a structure overflows onto the variables below it or something, but then why would you need 11 bytes (no less no more) ahead of the variables, when placing these at the beginning of the data section? These patterns don't seem point to any particular struct overflowing.

So, I invite everyone to take a look at my code (attachment) and tell me what the h*ll is happening... What do these different variable arrangements (some which cause the function to fail and some which cause it to work) tell me about a possible solution? I can see no correlation between them - they seem totally random.

Please help, for the last 2 days I've tried everything I can think about with no results. Once gain, this is XP and 2K, not the 9x variety.

Posted on 2002-03-10 19:52:31 by Lysic
The dwords and the structure are probably not aligned properly. Try to use ALIGN 4 before the non-aligned dwords and the structure variables.
Posted on 2002-03-11 00:54:52 by Dr. Manhattan
I'd say your reading memory you shouldn't be and Win2k just isn't as forgiving as 9x is.

However its very hard to help without more info, possibly even complete source. Or at least a stand alone bit which demonstrates the problem.
Posted on 2002-03-11 03:32:20 by Eóin
its definitive the problem, which Dr. Manhattan said. I had similar errors, f.e. failing of CreateFile with valid filenames and some more.

change it to:

align 4
Blank db 11 dup (0)
align 4
Mute db 5 dup (0)
More better, you define some extra bytes, which are unused but keep the alignment.
Posted on 2002-03-11 03:53:22 by beaster
It would be better to figure out what the *real* problem is, than
trying to "cure the disease by taking away the symptoms". It might
be a struct that's defined wrong, filled wrongly... or something else.
I haven't seen any ring3 structures that require alignment, neither
on 9x nor NT.
Posted on 2002-03-11 07:56:13 by f0dder
just a guess: you are writing/reading to/from the places you shouldn't, i mean :

a db 11
b db 22
mov a, dword ; not correct statment, just an idea.. :-)

this changes b :-)

hope you understood me :-)) range exceed...dunno how it is called...
Posted on 2002-03-11 08:14:47 by me8
Thank you all for the replies.

Eoin, the source is rite there, in my first post. Download it first, and then do the mods that I talk about in the message, to see the problem for yourself :( .

me8, show me a single place in my code where I move a dword value into a variable defined as a string... I don't think I do it... Also, a dword is only 4 bytes, so it should fit nicely in a string of 11 bytes or 22 bytes. Maybe I don't understand your post, could you elaborate?

Beaster, what kind of programming were you doing when you had similar errors? Was it ring 3, run of the mill, or something more exotic? And was it on WinXP / 2K?

To all those who suggested allignment... I'll try it soon, although our modest genius is rite, it doesn't touch the core of the problem.

Any other ideas?
Posted on 2002-03-11 08:30:30 by Lysic
I haven't seen any ring3 structures that require alignment, neither on 9x nor NT.

Posted on 2002-03-11 09:17:35 by Tola
Yep, alignment certainly works on 2K... so I think it will also work on XP. Basically BOTH structs need to be aligned for the function to work.

I'm satisfied with aligning, so I'll leave it at this. You can all add this to the set of magic tricks for programming in Win 2K/XP.

Thanks, everyone :alright:
Posted on 2002-03-11 12:41:20 by Lysic
Had the same problem a couple days ago...My beloved proggy just did not like where I had some of my vairables... Only moving them from the place where they were to the end of the .data? section fixed it... I thought it was because of XP or my resource section.. but here we go... I'm not alone. :)
Posted on 2002-03-11 12:56:00 by JimmyClif
You are not alone.
I had a similar thing happen with a variable in

I had to move things around to get rid of it . HOw I hate solving prolems that way. Its not good and willl probablyh come back to haunt me.
Posted on 2002-03-31 19:39:39 by nolpak
Originally posted by f0dder I haven't seen any ring3 structures that require alignment, neither
on 9x nor NT.
On Windows 2000 (reportedly also on XP, but I haven't checked this last one by myself), try QueryPerformanceFrequency / QueryPerformanceCounter, for example.
Posted on 2002-04-01 01:40:18 by Maverick