?
Solved

Quick help with a mistake I made.

Posted on 2006-03-23
6
Medium Priority
?
204 Views
Last Modified: 2013-11-20
Ok, heres the deal I've been working on this problem that ive had to other questions open on and to be honest I had the code working from some links provided to me by another expert, however I made the mistake of leaving the only code for it on a pen drive that got ruined today at work (*yay for coffee). Because I'm like many people that dont back things up often enough I had to rewrite my code, now I cant get the code working again and I dont know why.

Here is the code segment im using to load a picture from file and get the HGLOBAL of the DIB; the only problem is when I try to GlobalLock or GlobalSize the HGLOBAL I get 0 for size and no handle from GlobalLock.

//Code Segment
WCHAR wpath[MAX_PATH];
MultiByteToWideChar(CP_ACP, 0, szPath, -1, wpath, MAX_PATH);

HBITMAP hPic      = NULL;
DIBSECTION info;
IPicture *pic;
OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture, (LPVOID *)&pic);
pic->get_Handle((UINT *)&hPic);
HGLOBAL hDib = cDib.BitmapToDIB(hPic);
GetObject(hPic, sizeof(DIBSECTION), &info);
                                          
pPtr = GlobalLock(&hDib);
nSize = GlobalSize(&hDib);

pic->Release();
//

Can anyone tell me what Im doing wrong here that is causing me to not get the size and other information? I've already verified that the image is being loaded and right now Im kicking myself for not backing up, especially when Im not good with C++.

Code segment for "BitmapToDib":
http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_20146392.html

Goto that link and scroll down to the code migel posted... now this is the code that saved me last time but for the life of me I cant figure out what Im missing now that Im forced to recreate it.

I need to get the size of the DIB in memory so I can store the handle and size of the DIB in a vector, which is what im attempting to do.
0
Comment
Question by:rushtheweb
  • 3
  • 2
6 Comments
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16277776
have you tried it with BitmapToDIB() function from this link==> http://www.cs.colorado.edu/~main/cs1300/bgi/dibutil.c 

MAHESH
0
 
LVL 22

Expert Comment

by:mahesh1402
ID: 16277868
also try something like this for size etc info :

OLE_HANDLE h = NULL;
DIBSECTION info;
IPicture *pic;

OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture, (LPVOID *)&pic);
pic->get_Handle(&h);

GetObject((HGDIOBJ)h, sizeof(DIBSECTION), &info);


//Now Access 'info' e.g. info.dsBm.bmBits

MAHESH
0
 

Author Comment

by:rushtheweb
ID: 16280645
Hey :)

I tried to use BitmapToDIB() from that link but after I added that code to my project and its headers I couldnt get my project to compile, it kept complaining about missing precombiled headers and also something about the debug pch.

I will try your second suggestion in a couple hours when I get home for lunch.. thanks.

I now backup the code to three different places. :)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rushtheweb
ID: 16284970
Mahesh, I tried your suggestion and then realized I dont understand how that will solve my problem because I still cant seem to get the size or handle of the DIB using globallock and globalsize.
0
 

Author Comment

by:rushtheweb
ID: 16285222
The function Im using to convert the bitmap to dib is returning the dib handle that was used with globalalloc... so shouldnt the above code work?
0
 
LVL 49

Accepted Solution

by:
DanRollins earned 2000 total points
ID: 16285399
rushtheweb,
Why not refer to your earlier question... which you verified had been answered completely:
    Get an HGLOBAL for a DIB.
    http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_21783312.html

-- Dan
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses
Course of the Month13 days, 20 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question