Solved

String tables in VC++ 5 Console/MFC prog?

Posted on 1998-06-21
3
438 Views
Last Modified: 2013-12-14
I am writing a console program in VC++ 5.0 which uses MFC 4.21. My question is this: Can I, and how do I, use the Visual Studio string tables in my project? If this is possible then I am looking for a one-liner that shows how I access the strings in the table.

Thank you.
0
Comment
Question by:MaDdUCK
  • 2
3 Comments
 

Accepted Solution

by:
mattyg102096 earned 20 total points
ID: 1166388
I assume you mean the string table resource type.  To use these, you need to put your strings in a resource file (*.RC).  The easiest way to do this is using the resource editor of Visual C++.  Each resource will be identified by a unique number, which is in turn is #defined using identifier (i.e. IDS_ERROR_STRING)

Strings from a resource string table are loaded with the Windows API function LoadString.  There is a LoadString member function in the CString class which initializes a CString with a resource string... however, it doesn't always work with console mode apps.

But of course, just because you are using MFC doesn't mean you can't call standard Win32 APIs.  Just prefix them with :: to clarify you want the standard API... both to the compiler, and to you.  The format is LoadString(HINSTANCE, UINT, LPTSTR, int) where the parameters are:

HINSTANCE - Represents the module (DLL/EXE where the string table is)
UINT - the ID of the string you want
LPTSTR - points to a buffer to receive a copy of the string
int - the size of the buffer in parameter 3

So, the call would be like this:

TCHAR errorString[80];
::LoadString(::GetModuleHandle(NULL), IDS_ERROR_STRING,
     {LPTSTR)errorString, 80);

GetModuleHandle(NULL) returns the handle of the current module containing the code calling LoadString.  So, this assumes that this calling code is from the same executable file that contains the string table.

The great thing about using string tables, of course, is that you can provide multiple versions of your string table in different languages, and the LoadString call will select the appropriate string for the language settings of the user's computer.
0
 
LVL 8

Author Comment

by:MaDdUCK
ID: 1166389
Thank you,

can I come back to you (via this thread) if I have any more questions about this issue?

//madduck
0
 

Expert Comment

by:mattyg102096
ID: 1166390
Sure.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question