Solved

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

Posted on 1998-06-21
3
430 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.
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.

705 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now