Click here to Skip to main content
11,570,750 members (44,859 online)
Click here to Skip to main content

Loading images with an undocumented API in PPC 2002

, 12 Aug 2002 CPOL 151.8K 25
Rate this:
Please Sign up or sign in to vote.
This article describes an undocumented API that enables you to load images (bmp, gif etc.) from files under Pocket PC 2002

Introduction

Loading images under windows can always be a painful process, especially if the image formats are like JPEG, GIF or PNG. There's always the Imgdecmp library, that does a good job, but its also a bit of a bother with the documentation being so thin and all that. The other day I was trying to load a bitmap from my device using LoadImage, but somehow I kept getting the dreaded "The handle is invalid" error. So I did a search on the MFC code that ships with the PPC SDK in hope of finding a piece of code that will help me solve the puzzle. 

One thing led to another. I suddenly came across HBITMAP SHLoadImageFile(LPCTSTR pszFileName) in aygshell.h. Bingo! I had suddenly uncovered an undocumented API! No trace of it in MSDN, a search in Google produced nothing!! Since then, I've tried this API with gif's and bmp's also and I guess it will work fine for jpeg's and png's too. Here's a code sample...

// assuming code is in the OnDraw method of a view....

CBitmap bitmap;

// Attach the bitmap object to the HBITMAP returned by SHLoadImageFile
bitmap.Attach(SHLoadImageFile(_T("/My Documents/mcdonalds.gif")));

BITMAP bmpInfo;
bitmap.GetBitmap(&bmpInfo);

CDC bitmapDC;
bitmapDC.CreateCompatibleDC(pDC);
CBitmap* pOldBitmap = bitmapDC.SelectObject(&bitmap);

pDC->BitBlt(0, 0, bmpInfo.bmWidth, bmpInfo.bmHeight, &bitmapDC, 
            0, 0, SRCCOPY);

bitmapDC.SelectObject(pOldBitmap);
bitmap.DeleteObject();

That's all for now.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Tanzim Husain
Web Developer
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralImages not in the Resource directory Pin
spret8514-Sep-09 23:34
memberspret8514-Sep-09 23:34 
Questionhow to load tiff file image from java or c Pin
mikerahul13-Oct-07 1:40
membermikerahul13-Oct-07 1:40 
Questionloading JPEG from stream? Pin
houari_id20-Mar-06 8:18
memberhouari_id20-Mar-06 8:18 
GeneralThe unanimation bug Pin
eagleanec20-Feb-06 21:15
membereagleanec20-Feb-06 21:15 
QuestionHow to show image from jpeg stream? Pin
robert101417-Sep-05 17:55
memberrobert101417-Sep-05 17:55 
Generalfriends, you solved my great problem Pin
jiang shanshan25-Aug-05 19:04
memberjiang shanshan25-Aug-05 19:04 
Generalworks on pocket pc 2003 as well Pin
Kang Jodhi7-Mar-05 20:56
sussKang Jodhi7-Mar-05 20:56 
GeneralWorks with JPG too Pin
Anonymous7-Feb-05 16:46
sussAnonymous7-Feb-05 16:46 
Questionhow about in eVB ? Pin
Anonymous16-Jan-04 1:50
sussAnonymous16-Jan-04 1:50 
QuestionUse SHLoadImageFile in dialog-based application? Pin
cwei_lim30-Dec-03 14:37
membercwei_lim30-Dec-03 14:37 
GeneralAbout SHLoadImageFile Pin
ALopatkin26-Oct-03 22:34
memberALopatkin26-Oct-03 22:34 
GeneralRe: About SHLoadImageFile Pin
Anonymous19-Nov-03 18:16
sussAnonymous19-Nov-03 18:16 
GeneralRe: About SHLoadImageFile Pin
LiptenSoup14-Jan-04 11:09
memberLiptenSoup14-Jan-04 11:09 
GeneralIt is in MSDN Pin
Anonymous26-Oct-03 0:06
sussAnonymous26-Oct-03 0:06 
GeneralRe: It is in MSDN Pin
Anonymous13-Feb-04 3:22
sussAnonymous13-Feb-04 3:22 
GeneralGive a hand pls~~^_^ Pin
wehaha10-Sep-03 2:19
memberwehaha10-Sep-03 2:19 
GeneralI couldnt compile.... Pin
Ramees10-May-03 21:14
memberRamees10-May-03 21:14 
GeneralRe: I couldnt compile.... Pin
Tanzim Husain30-May-03 19:11
memberTanzim Husain30-May-03 19:11 
GeneralRe: I couldnt compile.... Pin
Anonymous8-Jun-03 0:12
sussAnonymous8-Jun-03 0:12 
GeneraleVB Pin
Chetan Kapadia17-Jan-03 2:58
sussChetan Kapadia17-Jan-03 2:58 
QuestionHow to Images in WinCE4.1 - A Probable solution Pin
tanzim25-Sep-02 22:41
membertanzim25-Sep-02 22:41 
QuestionHow to Images in WinCE4.1 ? Pin
DrWatson1-Sep-02 23:12
sussDrWatson1-Sep-02 23:12 
AnswerRe: How to Images in WinCE4.1 ? Pin
tanzim2-Sep-02 22:19
membertanzim2-Sep-02 22:19 
GeneralRe: How to Images in WinCE4.1 ? Pin
DrWatson3-Sep-02 20:32
sussDrWatson3-Sep-02 20:32 
GeneralRe: How to Images in WinCE4.1 ? Pin
Houser7-Sep-02 23:28
sussHouser7-Sep-02 23:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150624.2 | Last Updated 13 Aug 2002
Article Copyright 2002 by Tanzim Husain
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid