home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!ira.uka.de!chx400!sicsun!masg1.epfl.ch!gulcu
- From: gulcu@masg1.epfl.ch (Ceki Gulcu)
- Newsgroups: comp.os.ms-windows.programmer.misc
- Subject: Re: Qns abt drag/drop & GlobalUnlock
- Message-ID: <1992Sep11.143225@masg1.epfl.ch>
- Date: 11 Sep 92 12:32:25 GMT
- References: <1992Sep11.052535.1107@nuscc.nus.sg>
- Sender: news@sicsun.epfl.ch
- Organization: Ecole Polytechnique Federale de Lausanne
- Lines: 66
-
- In article <1992Sep11.052535.1107@nuscc.nus.sg>, twchan%Solomon.Technet.sg (Chan Tur Wei) writes:
- |>
- |> Dear netters,
- |>
- |> I'm posting the questions below on behalf of a friend who's having
- |> trouble with some Windows programming problem. Appreciate if someone
- |> could help!
- |>
- |> (1) Supporting "Drag" besides "Drop"
- |>
-
- Sorry, I can't help you on this one.
-
- |> (2) Lock and Free Memory problem
- |>
- |> When an application calls GlobalUnlock() and receives zero in
- |> return, it means that the lock count of the memory handle has
- |> reduced to zero. However, when the application immediately
- |> tries to free it, it receives a GP fault saying that the
- |> application is trying to free a locked memory object. This
- |> problem can be worked around by calling another GlobalUnlock()
- |> before GlobalFree(). Therefore, it seems that when
- |> GlobalUnlock() returns a zero, it does not necessarily mean that
- |> the lock count is already decremented to zero. Is this true?
- |>
-
- I have massively used GlobalAlloc/GlobalLock/GlobalUnlock functions. Here is
- a simplified version of what I usually do:
-
-
- void foo(void)
- {
- HANDLE testHandle; /* memory handle */
- LPSTR stringPointer;
- char sampleString[] = "Hello World!";
-
- /* Allocate sufficient space to accomodate the "Hello World" string */
- /* WARNING: The GMEM_MOVEABLE and GMEM_NONDISCARD constants may contain
- typos as I am writing code from the back of my head. */
- testHandle = GloabalAlloc(GMEM_MOVEABLE | GMEM_NONDISCARD,
- (strlen(sampleString) + 1) * sizeof(char));
-
- stringPointer = (LPSTR) GlobalLock(testHandle);
- strcpy(stringPointer, sampleString);
- GlobalUnlock(testHandle);
-
- } /* foo */
-
- I have encountered no problemes with the preceding memory management scheme. I
- have used to it create multi-MB sized linked lists.
-
- I recommend that your friend uses the malloc/free fuctions at the early stage
- of the developement cycle in order to make sure that the logic of his code
- is correct. Only then should he switch to global memory allocation functions.
-
- Hope that helps,
-
- GULCU Ceki
- gc@lbdsun6.epfl.ch
-
- ps: Allow me mention that OS/2 lets you simply use malloc() and free() to
- access upto 512 MB of memory. Also, as Windows and PM are very similar
- from the GUI programmers view, maybe your friend should try OS/2.
- Personally, I rather program for OS/2 but my boss does not see it the
- same way... <-- EOW (End of whining)
-
-