mfc >> static lib that has string resources

by Tom Jones » Sat, 29 Nov 2003 04:23:01 GMT

Per a previous question I had a dll project that I have converted to a
static library. The dll (now a static lib) uses MFC to reference string
resources. For example, in the DLL I could do something like this:

CString s;
s.LoadString(IDS_STRING_DEFINED_IN_MY_DLL);

Now that my dll is a static lib, I can no longer seem to get to these string
resources (the strings always come back empty).

What is the correct way to include the string resources required by a static
library into an exe that links to that static library?

Thanks!
TJ





mfc >> static lib that has string resources

by Mihai N. » Sat, 29 Nov 2003 06:55:20 GMT




Include the .rc of the library in the .rc of the module using it.

But in general a library should be designed without UI (as much as possible).


--
Mihai
-------------------------
Replace _year_ with _ to get the real email



mfc >> static lib that has string resources

by Tom Jones » Sat, 29 Nov 2003 08:07:06 GMT

Thank you for the reply Mihai.

I want to be sure I understand what you are saying regarding "But in general
a library should be designed without UI."

My static library has error strings that will be localized. My static
library does NOT display any type of UI; that is up to the exe that
eventually consumes it.

Should I not be using a string resource to define these strings?

BTW, when you say, "Include the .rc of the library in the .rc of the module
using it." do you mean to physically include it (i.e. #include) or pull it
into the exe's project another way?

Thank you again for your reply!

TJ



possible).




static lib that has string resources

by Mihai N. » Sat, 29 Nov 2003 16:03:32 GMT

> I want to be sure I understand what you are saying regarding "But in
Yes, this is my idea of a library.
I would expect a library to return numeric error codes, and the developer
will decide to show a dialog message, print to the console, log without
any UI, or ignore (good or bad, is his decision).
This is what I call a flexible library.
What if I develop a command-line application and your library pops a dialog?
I don't think I would like it.

In the resource editor right-click then select "Resource Includes"
You can add there
#include "LibRC.rc"
and the content will be nicely included when the application's RC is compiled
(if it is in the include path).
The above description is for Dev. Studio 2003 (.NET), but I think for Dev.
Studio 6 is pretty close (if not the same).

Mihai
-------------------------
Replace _year_ with _ to get the real email


static lib that has string resources

by Tom Jones » Sat, 29 Nov 2003 16:22:26 GMT

Thanks again for your response Mihai.

Unfortunately, I cannot include a rc file directly - it won't compile.

If the exe that uses my static library has its main file setup like this
(just as an example):

#include "stdafx.h"
#include "..\lib2\lib2.h" // function prototypes for my static
library
#include "..\lib2\lib2.rc" // string resources needed by my static
library

CWinApp theApp;
using namespace std;
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
// MFC initialization stuff...

int i = foo(); // foo lives in my static library

return 0;
}

This won't compile:

compiling...
Test.cpp
f:\Dev\DllToLib\Lib2\Lib2.rc(20) : error C2143: syntax error : missing ';'
before 'constant'
f:\Dev\DllToLib\Lib2\Lib2.rc(20) : error C2501: 'LANGUAGE' : missing
storage-class or type specifiers
f:\Dev\MS\Mine\DllToLib\Lib2\Lib2.rc(21) : warning C4068: unknown pragma

Do you mean that I SHOULD be able to include it directly?

Thanks,
TJ



dialog?
compiled




static lib that has string resources

by Mihai N. » Sun, 30 Nov 2003 15:53:17 GMT

> If the exe that uses my static library has its main file setup like this

THIS IS BAD!!!

Don't include the RC of ther library in your C/CPP code. Include it in the RC
of the application.

This is what I said first:

Second time:


So, you include the lib's RC file in the application's RC, using the
resource editor.
Should I send you some sample project?

Mihai


Similar Threads

1. why vc alwayys links kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib

I wonder why the linker is always searching these libraries, and where I 
can switch that off.

I can imagine why kernel32 is linked, but what do I need gdi for in a dos 
app and odbc and so on?

cheers
Ingo

2. Problem with DLL, static LIB and static data

3. Linking to a static field in a static lib

I can't seem to find out how to put static fields in static libs
without linker errors. If I move the definition (here:
static int missing;) out of the class, it links fine, but it
seems a bit awkward I can't put it in the class. I can't find
the magic words that give a static field the same kind of
linking as a global variable.

I have this boiled-down "solution" with projects P and Q.

P is a static library, Q is a console app that depends on P.

The files are:

P\MyClass.h:

    class MyClass
    {
    public:
        static int missing;
        static void initialize(void);
    };

P\MyClass.ccp:

    #include "MyClass.h"
    void MyClass::initialize(void)
    {
        missing = 0;
    }


Q\Q.cpp:

    #include "stdafx.h"
    #include "..\P\MyClass.h"

    int _tmain(int argc, _TCHAR* argv[])
    {
        MyClass::initialize();
        return 0;
    }

and the linker error message is:

p.lib(MyClass.obj) : error LNK2019: unresolved external symbol
    "public: static int MyClass::missing"
    (?missing@MyClass@@2HA)
referenced in function
    "public: static void __cdecl MyClass::initialize(void)"
    (?initialize@MyClass@@SAXXZ)


4. Having to manually include lib for component - Borland C++ Builder VCL Components

5. Problem in using c# dll having resources(forms) in VC++

Dear All,

I have created a c# dll having resource files. I am trying to use this
dll in VC++ project. I have done following steps:

1. Convert the dll to .tlb file using regasm tool provided by .NET
2. Through Project-->AddClass Menu created classes from type library
and added in the project.
3. When we compile the project it gives following errors:


Error	1	error C2146: syntax error : missing ';' before identifier
'GetType'	d:\classlibrary3\vc++app\debug\class3.tlh	62
Error	2	error C4430: missing type specifier - int assumed. Note: C++
does not support
default-int	d:\classlibrary3\vc++app\debug\class3.tlh	62
Error	3	error C4430: missing type specifier - int assumed. Note: C++
does not support
default-int	d:\classlibrary3\vc++app\debug\class3.tlh	62
Error	5	error C2143: syntax error : missing ';' before
'_Class1::GetType'	d:\classlibrary3\vc++app\debug\class3.tli	35
Error	6	error C2433: '_TypePtr' : 'inline' not permitted on data
declarations	d:\classlibrary3\vc++app\debug\class3.tli	35
Error	7	error C4430: missing type specifier - int assumed. Note: C++
does not support
default-int	d:\classlibrary3\vc++app\debug\class3.tli	35
Error	8	error C4430: missing type specifier - int assumed. Note: C++
does not support
default-int	d:\classlibrary3\vc++app\debug\class3.tli	35
Error	9	error C2064: term does not evaluate to a function taking 2
arguments	d:\classlibrary3\vc++app\debug\class3.tli	39

Can somebody help me in resolving this issue.

Thanks In Advance
Rajani

6. Having trouble with multiple threads and a shared resource - CSharp/C#

7. having problem enumerating resources [syntax error: '__stdcall']

Hi,

I am having problem with line 13. It gives me syntax error saying
'__stdcall'. I am trying to find all the bitmap resource that current
application uses. I can't find a good doc. or relevant posting that
discussed this. Please let me know what I'm doing wrong. Thanks in advance.

Rajib

01.    BOOL CALLBACK MyDlg::BitmapEnumProc(HMODULE hModule, LPCSTR lpszType,
02.    LPSTR lpszName, LONG_PTR lParam)
03.    {
04.      AfxMessageBox(lpszName);
05.      return TRUE;
06.    }
07.
08.    void MyDlg::OnAboutApp()
09.    {
10.      CAboutDlg aboutDlg;
11.      LONG_PTR lParam=0;
12.      //////// getting error on this function call
13.      EnumResourceNames(NULL, RT_BITMAP, (CALLBACK*
ENUMRESNAMEPROCA)BitmapEnumProc, lParam);
14.      aboutDlg.DoModal();
15.    }


8. Two resource files having same identifier value