Jump to content

(Solved)LoadImage C++


JohnOne
 Share

Recommended Posts

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.

Link to comment
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.

Link to comment
Share on other sites

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.

Link to comment
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....

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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...