I am relatively new to Win32 assembly, and am facing a difficult challenge (for me at least). I have written an ActiveX control which uses a lot of legacy assembly code in a static library. Unfortunately, the legacy code was written for use in a stand-alone EXE and uses a lot of global variables. These globals cause a lot of problems when running the ActiveX control in typical environments because each instance overwrites the values of other instances.

I want to get around the global problem, but I don't want to re-write a large amount of assembly code. If I create the variables inside the class of my ActiveX control, there are no problems because a different instance of the class is created each time it is invoked. I somehow need to put the globals inside the class (in a struct say) and pass a pointer to the struct to the assembler code.

I was also thinking that I may be able to use x86 segment registers. I somehow need to set up a separate descriptor table for each instance of the control and setup the segment register each time the assembler code is invoked. I think I need to call Win32 functions to do this.

Does anyone have any ideas? I would really appreciate some suggestions - could you please emailhttp://www.asmcommunity.net/board/cryptmail.php?tauntspiders=in.your.face@nomail.for.you&id=182a79a97d378070d2e60fbd9217ce16? Thanks in advance.

Posted on 2003-06-09 19:50:49 by Dan Amos
I think its not possible, or even tricky and not very stable to make own entries for the descriptor table.

You can try to create an own process for each object instance, this would setup an own data area
for each process. (maybe OpenProcess or similar function)

Other way is simply to rebuild the asm code, if you have all sources and can build them.
Replacing each global with a structure entry into a global allocated data structure is not too
difficult I think (if the asm source is not too wired :) )
Posted on 2003-06-10 05:21:00 by beaster
Thanks for the feedback.

I really don't think I can launch an additional process, because these controls are running in Internet Explorer and integrate nicely into it (ie receive and respond to messages).

I was think of turning the assembly code into a DLL and trying to load it using LoadLibrary, forcing it to allocate its own memory, but I am not sure if this will work. The options I see are:

1. Rewrite every line of the code changing references to global variables into references to a structure (relative to a pointer to the structure)

2. Write a pre-processor which automates step 1.

3. The DLL approach listed above

4. A clunky memory copy approach - keep a copy of globals inside ActiveX control and copy them to assembly before calling it and copy them back after calling it. Not a terribly good approach

5. Use segment registers to change the place that globals are being accessed from (without assembly code even being aware of it). Setup up segment registers before calling assembly and restore them afterwards

Any comment on these ideas or alternative suggestions will be greatly appreciated.

Posted on 2003-06-10 18:52:01 by Dan Amos