Path: utzoo!attcan!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!microsoft!davidds From: davidds@microsoft.UUCP (David D'SOUZA) Newsgroups: comp.windows.ms.programmer Subject: Re: Turbo C++ and Win3 SDK Message-ID: <59996@microsoft.UUCP> Date: 23 Dec 90 23:45:56 GMT References: <1990Dec11.132543.7715@watserv1.waterloo.edu> <1990Dec12.205410.16319@amd.com> Reply-To: davidds@microsoft.UUCP (David D'SOUZA) Organization: Microsoft Corp., Redmond WA Lines: 43 In article <1990Dec12.205410.16319@amd.com> mikem@brahms.amd.com (Mike Moretti) writes: >I have been able to generate Windows3 applications using Turbo C++ >and the SDK. I have noticed messages posted that this is not possible. >One reason mentioned the movement of segmetns. You can define a segment >to not be movable in your def file for the linker. I have not found this > >5. In ALL functions/procedures add the _loadds directive. I.E. > >int PASCAL _loadds WinMain(.... > >Note: ALL functions and procedures not just the ones called by windows. > Yes, this will work but beware... The application you just created is a single instance application! If you run multiple instances of the app, bizarre things will happen. Remember, windows shares code segments among multiple instances of applications. _loadds causes (something similar to) the following prologue to be added to each function. mov ax,DGROUP mov ds,ax DGROUP is patched at load time with your data segment. Now if you load a second instance of your app, some code segments will be patched to load your second ds (note patching is done only once at segment load time). If something is called from your first instance, ds changes to something unexpected... Also, it will only work in a protected mode environment unless you mark you data segment as fixed. This follows from my above statement that at load time your ds segment is patched into the code. If your ds moves (as happend in real mode), you are hosed. In protected mode, ds is a selector which never changes so you win... Another nice side effect of this trick is that since you are single instance loadds, you won't have to do a MakeProcInstance on any of your call back procedures. BTW: This is a very good thing to use if you have a protected mode only DLL since your dll will be much smaller without the windows prologue hanging around every entry point... (Remember DLLs in Windows have only one ds no matter how many apps use them so this works fine.)