Quick help with a mistake I made.

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
MultiByteToWideChar(CP_ACP, 0, szPath, -1, wpath, MAX_PATH);

HBITMAP hPic      = NULL;
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);


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":

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

also try something like this for size etc info :

IPicture *pic;

OleLoadPicturePath(wpath, NULL, NULL, NULL, IID_IPicture, (LPVOID *)&pic);

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

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

rushthewebAuthor Commented:
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. :)
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

rushthewebAuthor Commented:
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.
rushthewebAuthor Commented:
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?
Why not refer to your earlier question... which you verified had been answered completely:
    Get an HGLOBAL for a DIB.

-- Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.