This is my first attempt at using a resource file. I have seen a lot of answers that apply to C# but not C. Any suggestions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you mean the method used by Sysinternals and others to carry the drivers or needed DLLs (or even the x64 version of the program itself) in the resource section of a program (e.g. Sysinternals’ Process Explorer), using Microsoft Visual C you can use this code:
This saves the given resource (
BinResName) of resource type (ResType) from the module (e.g. a DLL)Instanceto fileNewPath. Obviously if your C doesn’t understand__tryand__finallyyou’ll have to adjust the code accordingly.Taken from here (in
SIDT.rar) and adjusted for C. The code is under the liberal BSD license according to the website.Now if you wanted to get the pointer to the data (
ppRes) and its size (pwdResSize):Call like this:
Note, this also works for resources with integer IDs. You can detect these by using the macro
IS_INTRESOURCE.The resource script, e.g. myresources.rc, itself is trivial:
RCDATAinstead of sometype is a reasonable choice… in which case you would adjust the above call to be:
Complete example making use of
GetResourcePointerabove. Let’s say you have a pointer variablechar* bufand you know your resource is actual text, then you need to make sure that it is zero-terminated when used as a string, that’s all.Resource script:
The code accessing it
Unless, of course you meant to simply link a
.resfile which works by passing it to the linker command line.