Solved

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

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

Technology Partners: 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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Update (December 2011): Since this article was published, the things have changed for good for Android native developers. The Sequoyah Project (http://www.eclipse.org/sequoyah/) automates most of the tasks discussed in this article. You can even fin…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

734 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