Jump to content
Sign in to follow this  
JohnOne

(Solved)LoadImage C++

Recommended Posts

JohnOne

Trying to use this API has been wrecking my head for hours.I can successfully use it to load a bmp from folder, but I'm trying to load a bmp from resource.All I get is error ERROR_RESOURCE_NAME_NOT_FOUND (1814)

int _tmain(int argc, _TCHAR* argv[]){
char c = '1';
HBITMAP hbitmap = NULL;
hbitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(1), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
//hbitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), (LPWSTR)L"test.bmp", IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
if ( !hbitmap ) 
{std::cout << "Fail" << std::endl << GetLastError() << std::endl; // 1814}
else {
std::cout << "Succeed" << std::endl;
}
std::cin >> c;
return 0;
}
Can anyone see what I'm doing wrong here?

EDIT:The resource bmp is in the same executable.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
trancexx

All I get is error ERROR_RESOURCE_NAME_NOT_FOUND (1814)

Did you check what that error means? It's not very descriptive, you should try googling.

What's with C style casting?

  • Like 1

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
JohnOne

I just thought the error was not finding the resource in the exe, it was what popped up in a search.

All the casting is just things I have been trying during the course of getting the function to return

what I expect.

I've got bleeding eyes from reading the msdn page for the func, I just cannot get my head around it.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
JohnOne

Solved

hbitmap = (HBITMAP)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(101), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
I has no Idea a resource would start at 101.

EDIT:

tags

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
wraithdu

I was just about to ask if you were sure your resource was really where you told the function to look....

Share this post


Link to post
Share on other sites
JohnOne

I was just about to ask if you were sure your resource was really where you told the function to look....

Cheers, I should have posted my woes earlier.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites
Valik

And you didn't learn your lesson which is don't use magic numbers. There's a reason symbolic names are defined for resources.

Share this post


Link to post
Share on other sites
Valik

What IDE are you using?

Share this post


Link to post
Share on other sites
Valik

Not sure why it's resource1.h, it should be resource.h. But yeah, that's the file.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.