|
-
Dec 20th, 2004, 11:28 AM
#1
Thread Starter
Frenzied Member
LoadResource function
Hey to all,
I have a little c++ prog that is suppose to load a resource file into memory.
I have metafiles that I want to use in my program. Currently they reside on the hard drive, but I don't want to dstribute them anymore. instead I want to include them in the file itself (it's a dll file.). I created a new resource type Metafile and imported all teh metafiles there.
Code:
#include <windows.h>
#include <stdio.h>
LPTSTR Metas[3] = {"Graphic1", "JVEST01C", "JVEST01F"};
HRSRC reshandle;
void main()
{
printf("1st element: %s\n", Metas[0]);
printf("2nd element: %s\n", Metas[1]);
printf("3rd element: %s\n", Metas[2]);
reshandle = FindResource(NULL, Metas[0], "Metafile");
if (reshandle == NULL)
printf("Did not find resource.\n\n");
printf("Press any key to exit...\n");
getchar();
}
However, it is not returning the handle to teh resource.
Any ideas why?
Don't anthropomorphize computers -- they hate it
-
Dec 20th, 2004, 05:18 PM
#2
Thread Starter
Frenzied Member
Re: LoadResource function
Hey,
I have this so far.
Code:
#include <windows.h>
#include <stdio.h>
#include "resource.h"
int Metas[3] = {Graphic1, JVEST01C, JVEST01F};
HRSRC reshandle;
HMODULE hexe;
HGLOBAL hglobal;
char *lock;
void main()
{
printf("1st element: %d\n", Metas[0]);
printf("2nd element: %d\n", Metas[1]);
printf("3rd element: %d\n", Metas[2]);
hexe = GetModuleHandle(NULL);
reshandle = FindResource(hexe, MAKEINTRESOURCE(Metas[0]), "Metafile");
if (reshandle == NULL)
printf("Did not find resource.\n");
else
printf("reshandle: %d\n", reshandle);
hglobal = LoadResource(hexe, reshandle);
if (hglobal == NULL)
printf("Did not load resource\n");
else
printf("hglobal: %d\n", hglobal);
lock = (char*) LockResource(hglobal);
if (lock == NULL)
printf("could not lock resource\n");
else
printf("lock: %d\n", lock);
printf("Press any key to exit...\n");
getchar();
UnlockResource(hglobal);
}
I need to be able to convert the resource into an istream type. How would I go about doing that? I realize that right now, it is being read into a char data type but it is just for testing. I am fairly new to C++ so any help would be greatly appreciated.
Thanks in advance,
Don't anthropomorphize computers -- they hate it
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|