- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have managed to write a custom binary resource to a .exe file.
I want to access the resource when I run the program.
I have tried using FindResource(NULL, IDR_name, RT_RCDATA)
but I get a 0 handle. This also happens when I replace RT_RCDATA by
any 16 bit number.
What call should I use to access the resource?
I want to access the resource when I run the program.
I have tried using FindResource(NULL, IDR_name, RT_RCDATA)
but I get a 0 handle. This also happens when I replace RT_RCDATA by
any 16 bit number.
What call should I use to access the resource?
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Uh... been there once... let me see... yes, I got it on my disk. Well, the problem is that constant RT_RCDATA doesn't actually mean "any user-defined resource". The docs are rather unclear on that. Now, I don't recall the details about what the gotcha was, but the point is that you should "define" your resource type using an arbitrary ID (as with any control), store it to .rc file and use that ID instead of RT_RCDATA.
Here's the copy & paste of a simple app which stores its own source (ResExtract.f90) as a resource. It's a win32 app, though the principle is the same for any kind of application. Note that USERTYPE is a PARAMETER of arbitrary value (10); it's added to resource.h and resource.fd manually:
HTH
Jugoslav
Here's the copy & paste of a simple app which stores its own source (ResExtract.f90) as a resource. It's a win32 app, though the principle is the same for any kind of application. Note that USERTYPE is a PARAMETER of arbitrary value (10); it's added to resource.h and resource.fd manually:
INTEGER FUNCTION WinMain(hInst, hPrevInst, lpCmdLine, nCmdShow) !DEC$ATTRIBUTES STDCALL, ALIAS: "_WinMain@16":: WinMain USE DFWIN IMPLICIT NONE INCLUDE "Resource.fd" INTEGER:: hInst, hPrevInst, lpCmdLine, nCmdShow INTEGER:: hLGlobal, hResource, dwResourceSize, iSt !String buffer to retrieve the resource (this code) CHARACTER(LEN=1000):: sVoidData; POINTER(lpVoidData, sVoidData) !Obtain resource's handle: hResource = FindResource(NULL, MAKEINTRESOURCE(Resource0001), MAKEINTRESOURCE(USERTYPE)); dwResourceSize = SizeOfResource(NULL, hResource); iSt=GetLastError() !Load resource into memory: hlGlobal = LoadResource(NULL, hResource); !Obtain a pointer from a memory handle and use it as lpVoidData = LockResource(hlGlobal); WinMain=1 END FUNCTION WinMain !=8<=ResExtract.rc====================== // RT_RCDATA // Resource0001 USERTYPE "ResExtract.f90" !=8<=resource.h====================== #define Resource0001 100 #define USERTYPE 10
HTH
Jugoslav

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page