Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!mips!news.cs.indiana.edu!maytag!csg.uwaterloo.ca!garyp From: garyp@csg.uwaterloo.ca (Gary Pianosi) Newsgroups: comp.windows.ms.programmer Subject: Problem Reading Bitmaps from Clipboard Message-ID: <1991May27.194425.8797@maytag.waterloo.edu> Date: 27 May 91 19:44:25 GMT Sender: news@maytag.waterloo.edu (News Owner) Organization: University of Waterloo Lines: 52 Originator: garyp@csg.uwaterloo.ca I am trying to write a program that will read a bitmap from the clipboard and save it out in another format. However, the handle returned from GetClipboardData() is sometimes invalid in the sense that a GlobalLock() of that handle fails. Also, the handle returned is often not listed by Heap-Walker, or is labelled as being a handle to an existing resource (menu, string, etc). Following the example in the "Guide to Programming" (section 13.1.3), I modified the CLIPTEXT sample to paste bitmaps instead of text from the clipboard. The pertinent code is as follows: > case IDM_PASTE: > if (OpenClipboard(hWnd)) { > if (!(hClipData = GetClipboardData(CF_BITMAP))) { > CloseClipboard(); > break; > } > if (!(lpClipData = GlobalLock(hClipData))) { > OutOfMemory(); /* <--- usually fails here */ > CloseClipboard(); > break; > } > /* > * ... do something with data at lpClipData ... > */ > GlobalUnlock(hClipData); > CloseClipboard(); > } Sometimes the GlobalLock() works but usually it fails. With a given content in the clipboard it either always succeeds or always fails. Miscellaneous info: - I'm using a 386 clone with 8 Meg of memory (also occurs using a PS/2 Model 80 with 2 Meg of memory). - I have tried both Microsoft C 6.00 and Borland Turbo C 2.0 - occurs in 386-enhanced, Standard, and Real modes - occurs with both Windows 3.0 and Windows 3.00a In an attempt to solve my problem by side-stepping it, I tried using the GetBitmapBits() function to copy the bitmap data to a buffer. It seems to work (even when the bitmap handle appears to be invalid!). I guess I'm a little worried about leaving my problem unsolved since the SDK suggests using GlobalLock() to look at the bitmap data. Thanks in advance for any advice. - Gary Pianosi. -- -- E-mail: garyp@csg.UWaterloo.CA Phone: (519) 888-4678 Computer Systems Group, University of Waterloo, Waterloo, Ontario, Canada