Sign in to follow this  
Followers 0
JohnOne

(Solved)LoadImage C++

12 posts in this topic

#1 ·  Posted (edited)

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



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?

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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

#4 ·  Posted (edited)

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

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

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

What IDE are you using?

Share this post


Link to post
Share on other sites

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  
Followers 0