Link to home
Start Free TrialLog in
Avatar of benny_czarny
benny_czarny

asked on

MFC extension DLL calling STL

Hi all
I am Trying to create an MFC extension DLL calling an STL  : list
which will not take MSVCR*.DLL  as on of it's dependants

Can I do that ?
If yes Then How ?
Avatar of jkr
jkr
Flag of Germany image

You can do it - STL (as a template library) does not use any MS DLL (this is the nature of templates - they don't need external libraries/DLLs, as the implementation is the template expansion in your source code)

Simply include 'lit' and make sure that you're using the correct namespace:

// STL
#include <list>
using namespace std;

Feel free to ask if you encounter any problems!
Avatar of benny_czarny
benny_czarny

ASKER

// STL
#include <list>
using namespace std;

Yes but when I do that in an MFC extention DLL I immediately get
MSVC*.dll linked to this DLL
How can I avoid that
Thanks
Benny
>>How can I avoid that

Simple answer: Do not use MFC or link the MFC libs  statically...

BTW: You don't have to reject answers if you need some clarification...
sorry about that  i'll find a way to deliver points

But still I want to use MFC dinamically and use the Stl as I said

thank
Benny


Adjusted points to 140
Ooops, sorry, now I understand your problem ;-)

STL needs the C runtime (CRT) which is contained in this DLL(s). To overcome this, go to the Project Settings, choose the 'C++' tab, select 'Code Generation' from the combo box and change 'Use run-time library' to the appropriate setting (single/multi-threaded, eventually debug, depending on debug/relese) that does NOT use the DLL (or specify /ML(d) in the makefile), so the DLL will be linked to 'libc(m)(d).lib'
Thanks

Yes I've tried all of the 'Code Generation' options - (I am using a multithreaded dll )
But still MSVC*.dll are depenents
( I cannot use MTd option I get
#error :  Please use the /MD switch for _AFXDLL builds
because my of my AFXDLL usage
)
Hmm, it seems that MFC insists on using the DLL version of the C runtime (which usually isn't too bad either) - as an MFC extension DLL (I don't use them too often) requires using this particular DLL anyway, why do you want to get rid of it?
BUT: What about placing the STL code in a separate (Win32) DLL that is used by your extension DLL?
Thanks for the workaround
But still we cannot separate this dll
Benny

Adjusted points to 180
Adjusted points to 280
Why do you want to get rid of it ?
Well I do not want the MSVCr*.dll depedency
Benny
What about using a 'regular' MFC DLL instead of an extension DLL? According to the header files (afxver_.h), an #error directive is issued when you try to get rid of this DLL...
Thanks again but I have to export function in this dll
The problem seems to be that the compiler always Produce an import library for applications using the DLL to link with.

>> but I have to export function in this dll

That's also possible from a regular MFC DLL. The import library doesn't matter at all...
Thanks

Yep But I export extended" derive classes from this dll
Hmm, don't be bothered, but I fear you have to get used to the idea of using msvcrt.dll ;-)
Thanks
But stil why

MFC extension DLLs rely on the dynamically linked version of the CRT:

(see afxver_.h)

/////////////////////////////////////////////////////////////////////////////
// For target version (one of)
//   _CUSTOM   : for custom configurations (causes afxv_cfg.h to be included)
//
// Additional build options:
//  _DEBUG              debug versions (full diagnostics)
//  _AFXDLL             use shared MFC DLL
//  _AFXEXT             extension DLL version, implies _AFXDLL
//  _USRDLL             create regular DLL (_AFXDLL is valid too)
//

#ifndef _DEBUG
      #define _AFX_ENABLE_INLINES
#endif

#define _AFX_NO_NESTED_DERIVATION

/////////////////////////////////////////////////////////////////////////////
// Special configurations

// _AFXEXT implies _AFXDLL
#if defined(_AFXEXT) && !defined(_AFXDLL)
      #define _AFXDLL
#endif

#if defined(_AFXDLL) && !defined(_DLL)
      #error Please use the /MD switch for _AFXDLL builds
#endif

#ifndef _MAC
#if defined(_AFXDLL) && !defined(_MT)
      #error Please use the /MD switch (multithreaded DLL C-runtime)
#endif
#endif

This means, when a configuration different from /MT is specified, the #error directive is emitted causing the compilation to abort (specifying /MT on the command line causes the compiler to internally '#define _MT'). So , you're out of luck, as this header will not compile when you're not using 'multithreaded DLL' (I would _not_ advise to #define _MT manually - who knows about the ramifications of the MFC codebase - but this would be the last resort...)
Thanks
How can I deliver you the points ?
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial