[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 1998-06-21
3
Medium Priority
?
448 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 80 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

873 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