Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MFC extension DLL calling STL

Posted on 1999-07-15
23
Medium Priority
?
388 Views
Last Modified: 2013-12-14
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 ?
0
Comment
Question by:benny_czarny
[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
  • 12
  • 11
23 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 1200323
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!
0
 

Author Comment

by:benny_czarny
ID: 1200324
// 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
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200325
>>How can I avoid that

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

0
Independent Software Vendors: 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!

 
LVL 86

Expert Comment

by:jkr
ID: 1200326
BTW: You don't have to reject answers if you need some clarification...
0
 

Author Comment

by:benny_czarny
ID: 1200327
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


0
 

Author Comment

by:benny_czarny
ID: 1200328
Adjusted points to 140
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200329
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'
0
 

Author Comment

by:benny_czarny
ID: 1200330
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
)
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200331
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?
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200332
BUT: What about placing the STL code in a separate (Win32) DLL that is used by your extension DLL?
0
 

Author Comment

by:benny_czarny
ID: 1200333
Thanks for the workaround
But still we cannot separate this dll
Benny

0
 

Author Comment

by:benny_czarny
ID: 1200334
Adjusted points to 180
0
 

Author Comment

by:benny_czarny
ID: 1200335
Adjusted points to 280
0
 

Author Comment

by:benny_czarny
ID: 1200336
Why do you want to get rid of it ?
Well I do not want the MSVCr*.dll depedency
Benny
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200337
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...
0
 

Author Comment

by:benny_czarny
ID: 1200338
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.

0
 
LVL 86

Expert Comment

by:jkr
ID: 1200339
>> 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...
0
 

Author Comment

by:benny_czarny
ID: 1200340
Thanks

Yep But I export extended" derive classes from this dll
0
 
LVL 86

Expert Comment

by:jkr
ID: 1200341
Hmm, don't be bothered, but I fear you have to get used to the idea of using msvcrt.dll ;-)
0
 

Author Comment

by:benny_czarny
ID: 1200342
Thanks
But stil why

0
 
LVL 86

Expert Comment

by:jkr
ID: 1200343
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...)
0
 

Author Comment

by:benny_czarny
ID: 1200344
Thanks
How can I deliver you the points ?
0
 
LVL 86

Accepted Solution

by:
jkr earned 1200 total points
ID: 1200345
This way ;-)

Thanx for your patience, and sorry that' it is not a fully satisfying answer - but it's simply not possible...
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying 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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

715 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