You are here:

C++/Using custom resources in windows programs


Right, I understand how to parse an actual string, but I don't have a string.  I have a custom resource loaded into memory.  For example:

HGLOBAL hResource;
char * pText;

        hResource=LoadResource(hInst,FindResource (hInstance, TEXT"Text"),MAKEINTRESOURCE (IDR_TEXT1)));
  pText=(char *)LockResource(hResource);

Now, I have a pointer to my data, but I don't know how to put it into strings or manipulate it.  strtok() takes a string as a parameter, but again, that is part of the problem.  I only have a pointer to a chunk of memory.  

The included resource is a text file.  Here is a sample content.
This is a string.
This is another string.

What I would like is to be able use those as strings or even character arrays in my program.  Do you know how to take a pointer to a chunk of memory that contains this data and turn it into useable strings?

Followup To
Question -
Hi, my name is Mike Lane and I hope you can help me.  I am trying to learn about using custom resources in windows programming with c++.  I have a text file that I'm including in my .exe as a custom resource, but the problem is that I don't know how to access it.  The text file has strings separated by a newline.  How do I put these strings into an array from memory like that?

I know about LoadResource, LockResource, and FreeResource, but once the data is in memory, I don't know how to traverse it and put it in my own strings.  Could you help me?
Answer -
Mike , Thank you for your question.

There are many ways your program can scan a character string with embedded NL characters and return each such string.

You can use the C runtime library function 'strtok', for example. Examples of using this function are in many textbooks and probably in tutorials online.

David Spector

Mike, I don't understand your problem. You have obtained a pointer, pText, to the data of your custom resource. Since the resource is a character string, pText will point to it.

Important note: When you create the text file that will become the custom resource, be sure to include a final NUL (zero character).



All Answers

Answers by Expert:

Ask Experts


David Spector


Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.


I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 All rights reserved.