wallis@sieras.enet.dec.com (Barry L. Wallis) (03/13/91)
One of my first Windows programs is to try and encapsulate the Windows code into reusable objects (using Borland C++). I have studied the various techniques for passing an object pointer to WndProc() so it can be put into the cbWndExtra area via GetWindowWord/Long() PutwindowWord/Long(). Compiling the HELLOW project that comes with BC++ works successfully. However, when I try and stuff a pointer into the lpParam area when I do CreateWindow() (it's the last argument) I get an Exception 13 / error 0. I cannot find Windows exceptions documented in TFBM [where B => Borland and M => manual + online documentation; however, I have not yet purchased the MS Programmer's Guide to Windows 3.0 yet]. Cany anyone tell me what this means and where to find the reference for myself? Also, when I substitute NULL for the last argument the call succeeds. - Thanks for your help, - A Windows virgin who does not intend to be sacrificed ;-) --- Barry L. Wallis USENET: wallis@labc.dec.com Database Consultant Prodigy (don't laugh): DNMX41A U.S. DECtp Resource Center DECUServe: EISNER::WALLIS (not on the net yet) Los Angeles, CA "No one voted for me, I represent myself" ---
whkr@ciba-geigy.ch (Hans Kraft) (03/14/91)
Don't put a pointer into the extra data area of a window, as that pointer could refer to a movable or even discadable segment. After reload or move of the according segment (done without notice by windows) the pointer is obsolete. It is better to allocate a segment (e.g. GlobalAlloc) and store the handle of the segment. Then lock (GlobalLock) the segment before use. You could also lock the segment after allocation and leave it locked for the application. Then you could store the pointer - but this is not recommended as it deteriorates windows memory management and it can give problems in some memory models. Hope this helps Giovanni Forza (Hans Kraft)
bonneau@hyper.hyper.com (Paul Bonneau) (03/17/91)
In article <1991Mar14.071522.21044@ciba-geigy.ch> whkr@ciba-geigy.ch (Hans Kraft) writes: >Don't put a pointer into the extra data area of a window, as that >pointer could refer to a movable or even discadable segment. After >reload or move of the according segment (done without notice by >windows) the pointer is obsolete. I missed the parent article, so I don't know if the pointer was FAR or not, but... There is no problem with storing NEAR pointers. If the default data segment moves, so does the pointer. cheers - Paul Bonneau.
wallis@sieras.enet.dec.com (Barry L. Wallis) (03/21/91)
In article <1991Mar16.184505.18776@hyper.hyper.com>, bonneau@hyper.hyper.com (Paul Bonneau) writes... >In article <1991Mar14.071522.21044@ciba-geigy.ch> whkr@ciba-geigy.ch (Hans Kraft) writes: >>Don't put a pointer into the extra data area of a window, as that >>pointer could refer to a movable or even discadable segment. After >>reload or move of the according segment (done without notice by >>windows) the pointer is obsolete. > >I missed the parent article, so I don't know if the pointer >was FAR or not, but... > >There is no problem with storing NEAR pointers. If the >default data segment moves, so does the pointer. > >cheers - Paul Bonneau. Thanks to all who helped. Using GlobalAlloc() is certainly the safest way. However, yes I am using NEAR pointers. I am 400 miles from my PC so I cannot verify the following: does castng an object pointer to LPSTR change it from being a NEAR pointer to being a FAR pointer? --- Barry L. Wallis USENET: wallis@labc.dec.com Database Consultant Prodigy (don't laugh): DNMX41A U.S. DECtp Resource Center DECUServe: EISNER::WALLIS (not on the net yet) Los Angeles, CA "No one voted for me, I represent myself" ---
cadsi@ccad.uiowa.edu (CADSI) (03/21/91)
From article <21311@shlump.nac.dec.com>, by wallis@sieras.enet.dec.com (Barry L. Wallis): > > > Thanks to all who helped. Using GlobalAlloc() is certainly the safest way. > However, yes I am using NEAR pointers. I am 400 miles from my PC so I cannot > verify the following: does castng an object pointer to LPSTR change it from > being a NEAR pointer to being a FAR pointer? Yup. Actually, all it does (casting to LPSTR) is add the currect data segment to the offset (near). For instance, if you make a call like: CreateWindow(....., (LPSTR)this); It just pushes the data segment in addition to the 'this' pointer, thus on the stack goes a FAR pointer. |----------------------------------------------------------------------------| |Tom Hite | The views expressed by me | |Manager, Product development | are mine, not necessarily | |CADSI (Computer Aided Design Software Inc. | the views of CADSI. | |----------------------------------------------------------------------------|