Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!pyrnj!mirror!billc From: billc@mirror.UUCP (Bill Callahan) Newsgroups: comp.windows.ms Subject: Re: Does DialogBox preserve Data Segment Address? Message-ID: <23319@mirror.UUCP> Date: 14 Feb 89 17:52:13 GMT References: <460@msn005.misemi> <1366@agora.UUCP> <3816@metavax.UUCP> <10693@well.UUCP> Reply-To: billc@prism.TMC.COM (Bill Callahan) Organization: Mirror Systems, Cambridge Mass. Lines: 30 In article <10693@well.UUCP> brent@well.UUCP (Brent Southard) writes: >In article <3816@metavax.UUCP> adam@metavax.UUCP (Adam Hoffman -- Mr. Engineering) writes: >>I have a feeling that DialogBox (the function) does nothing >>special about locking the data segment while it calls PeekMessage or >>whatever it calls... > >You are absolutely correct. Your data segment may very well move during >calls to MessageBox, DialogBox, or other functions that directly or >indirectly call PeekMessage et all, thus losing the context. You must be >very careful not to hold far pointers to local data across such function >calls. Just as helpful hint, in such situations, you have several alternatives when you do need to pass a pointer and have it be good: 1. Allocate and lock the piece of memory using GlobalAlloc and GlobalLock. 2. Use memory in your data segment (such as static or global buffers) and lock your data segment before the call, remembering to unlock it afterwords. 3. If your stack resides in a fixed or locked data segment, long pointers to automatic storage are (obviously, but also suprisingly) good. This one can be very handy. --------------------------------------------------------------------------- Bill Callahan billc@mirror.TMC.COM {mit-eddie, pyramid, wjh12, xait, datacube}!mirror!billc Mirror Systems 2067 Massachusetts Ave. 617\661-0777 x149 Cambridge, MA 02140