Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ranthalion

help with loading a resource

This topic is 5315 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Does anyone see any reason why LoadResource would return NULL in this code? I''m using MSVC++ 6.0. I''m just trying to load a custom resource, but it always fails. For some reason, it can''t find the resource. I inserted the resource by going to Insert|Resource, clicked custom and typed in TEXT. Then it automatically created IDR_TEXT1. Then I just typed the test string into the resource, using the resource editor. I saved all files, and compiled. Am I missing something in adding and loading a custom resource?
INT WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance,
				   LPSTR lpCmdLine, int nCmdShow)
{
	hInstance=hInst;
	hResource = LoadResource (hInstance,
				FindResource (hInstance, "TEXT",
				MAKEINTRESOURCE (IDR_TEXT1))) ;

	if (hResource==NULL){MessageBox(NULL,"hResource is NULL","Status", MB_OK);}

	DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1),
	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));

	return FALSE;
}
resource.h:
//{{NO_DEPENDENCIES}}

// Microsoft Developer Studio generated include file.

// Used by Script1.rc

//

#define IDD_DIALOG1                     101
#define IDR_MENU1                       102
#define IDR_TEXT1                       103
#define FILE_POPUP                      40001
#define ID_FILE_EXIT                    40002
#define FILE_EXIT                       40002

// Next default values for new objects

// 

#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        104
#define _APS_NEXT_COMMAND_VALUE         40003
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
This is in my resource script: IDR_TEXT1 TEXT DISCARDABLE "text1.bin"

Share this post


Link to post
Share on other sites
Advertisement
After a quick look at MSDN, "TEXT" is not listed as a Resource Type that FindResource() will accept. Obviously it may take more but my first glance shows that as a potential problem.

Also, not to doubt you, but you do have a text file named the same as in your code?

Ace

Share this post


Link to post
Share on other sites
TEXT isn''t going to be listed as a resource type that FindResource is going to accept because it is a custom type, instead of a standard resource type.

Good question about the actual file being there. It was there.
On closer inspection of FindResource, it seems that I may have had the parameters flipped. Instead of :
FindResource (hInstance, "TEXT", MAKEINTRESOURCE (IDR_TEXT1))
I think I should have:
FindResource (hInstance, MAKEINTRESOURCE (IDR_TEXT1), "TEXT")

When I do it that way, I no longer get error 1812 when I call GetLastError, but now I get error 6 which means that the handle is invalid...

Any other thoughts on this?

Share this post


Link to post
Share on other sites
If I''m not going crazy, GetLastError is most likely the error being returned by LoadResource(). Could you break FindResource() out onto it''s own seperate line and check what error, if any, is being returned?

Share this post


Link to post
Share on other sites
When I split it, GetLastError still returns error 6, but if I ignore that, then it seems to work just fine now. Thanks for pointing me back to MSDN. I''ve looked over FindResource so many times, and I still don''t know why I had the arguments flip flopped...

Now, I can load my data into memory. Now I just have to figure out how to break it apart into different strings. I''m planning to use strtok.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!