Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!sdd.hp.com!wuarchive!uunet!zephyr.ens.tek.com!uw-beaver!milton!sumax!polari!rwing!seaeast!sunbrk!Usenet From: Gary.Pianosi@sunbrk.FidoNet.Org (Gary Pianosi) Newsgroups: comp.windows.ms.programmer Subject: Problem Reading Bitmaps from Clipboard Message-ID: <675518012.5@sunbrk.FidoNet> Date: 28 May 91 00:44:25 GMT Sender: Usenet@sunbrk.FidoNet.Org Lines: 55 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 * Origin: Seaeast - Fidonet<->Usenet Gateway - sunbrk (1:343/15.0)