Referencing "internal" resources in MFC
-
Hi ! The topic states it pretty well, but let me specify a little. I am building an application which uses a HTML template (mailbase.html) to send e-mail. Now, I currently have the CFile constructor to find & open this file from the same folder as the executable. However, I would like to reduce the number of files visible to the end user. So, the necessity would be to include the HTML file to the project's resources, and use the CFile to open this "resource file" instead. Question is, what must I write for the first parameter of the constructor (filename) in order to have it search inside the executable instead of the directory where the executable is ? Or, if the CFile isn't an appropriate solution, what should I do ? The idea is that the software opens the HTML file, copies it to CString, finds comment spots there and replaces them with appropriate information. So, a "standard" way to use a HTML template :) I am using version 2003 of MS Visual Studio, but all tips/tricks, including those for older versions, will be helpful. Greets, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
-
Hi ! The topic states it pretty well, but let me specify a little. I am building an application which uses a HTML template (mailbase.html) to send e-mail. Now, I currently have the CFile constructor to find & open this file from the same folder as the executable. However, I would like to reduce the number of files visible to the end user. So, the necessity would be to include the HTML file to the project's resources, and use the CFile to open this "resource file" instead. Question is, what must I write for the first parameter of the constructor (filename) in order to have it search inside the executable instead of the directory where the executable is ? Or, if the CFile isn't an appropriate solution, what should I do ? The idea is that the software opens the HTML file, copies it to CString, finds comment spots there and replaces them with appropriate information. So, a "standard" way to use a HTML template :) I am using version 2003 of MS Visual Studio, but all tips/tricks, including those for older versions, will be helpful. Greets, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
Read up on the APIs for accessing resources: FindResource, LoadResource, LockResource --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!
-
Hi ! The topic states it pretty well, but let me specify a little. I am building an application which uses a HTML template (mailbase.html) to send e-mail. Now, I currently have the CFile constructor to find & open this file from the same folder as the executable. However, I would like to reduce the number of files visible to the end user. So, the necessity would be to include the HTML file to the project's resources, and use the CFile to open this "resource file" instead. Question is, what must I write for the first parameter of the constructor (filename) in order to have it search inside the executable instead of the directory where the executable is ? Or, if the CFile isn't an appropriate solution, what should I do ? The idea is that the software opens the HTML file, copies it to CString, finds comment spots there and replaces them with appropriate information. So, a "standard" way to use a HTML template :) I am using version 2003 of MS Visual Studio, but all tips/tricks, including those for older versions, will be helpful. Greets, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.
Maybe I'm totally missing the point here, but if you want to read the file, and then copy it into a
CString
, why not just include it as a string resource and useCString::LoadString
to load it:confused:
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!
-
Maybe I'm totally missing the point here, but if you want to read the file, and then copy it into a
CString
, why not just include it as a string resource and useCString::LoadString
to load it:confused:
[
](http://www.canucks.com)Sonork 100.11743 Chicken Little "You're obviously a superstar." - Christian Graus about me - 12 Feb '03 Within you lies the power for good - Use it!
Thank you both for a swift response. Mike's suggestion yielded a working solution. Using a string resource might have worked as well, but pushing 3 kb of HTML code into a string resource just didn't sound nice. If nothing else, it would look ugly in the String Table :) I'll post the code snippet here in case someone wants to utilize it. I must say though, it looks like a SERIOUS hack :suss: Note that you need to check the resource integer number for FindResource() manually from 'resource.h'
// Load the HTML file char* ptrChar = (char*)LockResource(LoadResource(NULL, FindResource(NULL, "#130" ,RT_HTML))); // Construct a CString from the resource CString HTMLFile(ptrChar);
Greetings, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible. -
Thank you both for a swift response. Mike's suggestion yielded a working solution. Using a string resource might have worked as well, but pushing 3 kb of HTML code into a string resource just didn't sound nice. If nothing else, it would look ugly in the String Table :) I'll post the code snippet here in case someone wants to utilize it. I must say though, it looks like a SERIOUS hack :suss: Note that you need to check the resource integer number for FindResource() manually from 'resource.h'
// Load the HTML file char* ptrChar = (char*)LockResource(LoadResource(NULL, FindResource(NULL, "#130" ,RT_HTML))); // Construct a CString from the resource CString HTMLFile(ptrChar);
Greetings, Antti Keskinen ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.Antti Keskinen wrote: Note that you need to check the resource integer number for FindResource() manually from 'resource.h' No, just use
MAKEINTRESOURCE
:FindResource ( NULL, MAKEINTRESOURCE(IDR_YOUR_HTML), RT_HTML );
And some error-handling would be good too. ;) --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!
-
Antti Keskinen wrote: Note that you need to check the resource integer number for FindResource() manually from 'resource.h' No, just use
MAKEINTRESOURCE
:FindResource ( NULL, MAKEINTRESOURCE(IDR_YOUR_HTML), RT_HTML );
And some error-handling would be good too. ;) --Mike-- Ericahist | Homepage | RightClick-Encrypt | 1ClickPicGrabber Ericahist updated (again) Sep 6!
Well, now it's a complete haxor :) Greetings, Antti ---------------------------------------------- The definition of impossible is strictly dependant on what we think is possible.