Solved

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

Posted on 1998-06-21
3
440 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

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…
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 …
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

696 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