Jump to content
  • Advertisement


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


help with loading a resource

This topic is 5401 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?
				   LPSTR lpCmdLine, int nCmdShow)
	hResource = LoadResource (hInstance,
				FindResource (hInstance, "TEXT",

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

	          hWnd, reinterpret_cast<DLGPROC>(DlgProc));

	return FALSE;

// 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


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

Share this post

Link to post
Share on other sites
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?


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!