Click here to Skip to main content
15,921,351 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Unix crypt() under windows. Pin
Franz Granlund12-Jul-02 1:31
Franz Granlund12-Jul-02 1:31 
GeneralRe: Unix crypt() under windows. Pin
Martin Ziacek12-Jul-02 1:46
Martin Ziacek12-Jul-02 1:46 
GeneralRe: Unix crypt() under windows. Pin
Franz Granlund12-Jul-02 2:00
Franz Granlund12-Jul-02 2:00 
GeneralRe: Unix crypt() under windows. Pin
Martin Ziacek12-Jul-02 2:33
Martin Ziacek12-Jul-02 2:33 
GeneralRe: Unix crypt() under windows. Pin
Chris Losinger12-Jul-02 3:20
professionalChris Losinger12-Jul-02 3:20 
GeneralRe: Unix crypt() under windows. Pin
Ravi Bhavnani12-Jul-02 13:50
professionalRavi Bhavnani12-Jul-02 13:50 
GeneralNeed HTML Syntax Hilighting Class Pin
Alex Cramer11-Jul-02 21:03
Alex Cramer11-Jul-02 21:03 
GeneralUser defined C++ template implementations in Windows DLLs using implicit linking Pin
tgeraldino11-Jul-02 18:23
tgeraldino11-Jul-02 18:23 
I would like to ask two technical questions on a problem that I have bumped into and it is the following:

First Question:

Can you build a Windows DLL from implementations that are resident in a .hpp/.h file[ NOT corresponding .cpp dll implementation files like Jeffrey Richter assumes ], where the implementation is a template<> class and/or collection of template<> classes?

The concern is that I am building a middleware backend that has classes designed preliminarily with templates and parameterized polymorphic class types and of course all its implementation is in the header file, but Jeffrey Richter, the author of the well known Microsoft Systems Programming books has his samples on building DLLs using a classical non template classes where the header files do this:

//->DLL_Lib.h
#if !defined _DLL_LIB_H
#define DLL_LIB_H

#if defined DLL_LIB_INTER
//->the #define for the extern “C” __declspec( dllexport ) is in .cpp file
#else
#define DLL_LIB_INTER extern “C” __declspec( dllimport )
#endif //->DLL_LIB_INTER

#include <string> //->includes STL std::string

//->Define exported/imported( if DLL_LIB.h not in .cpp file function prototypes now
DLL_LIB_INTER void foo( std::string& token );
DLL_LIB_INTER void fooBar( std::string& token );
DLL_LIB_INTER void fooBarFoo( std::string& token );
DLL_LIB_INTER void fooBarFooBoo( std::string& token );

//->Define exported C++ class type definitions
DLL_LIB_INTER class Foo_ed { … }; //->DLL_LIB_INTER the class members also?
DLL_LIB_INTER class FooBar_ed { … };
DLL_LIB_INTER class FooBarFooBoo_ed { … };

#endif //->_DLL_LIB_H

and the corresponding source files are as below for example:

#include <iostream>
#include <windows.h>

#define DLL_LIB_INTER extern “C” __declspec( dllexport )

//->Now include the DLL_Lib.h header file to read the #define up top
#include “DLL_Lib.h”

//->DLL_LIB_INTER omitted from class member function and non-class functions //->This is OK. Windows compiler records DLL_LIB_INTER macro flag from the
//->DLL_Lib.h header file.

void foo( std::string& token ) { /* Impl */ }
void fooBar( std::string& token ) { /* Impl */ }
void fooBarFoo( std::string& token ) { /* Impl */ }
void fooBarFooBoo( std::string& token ) { /* Impl */ }

//->Define exported C++ class type definitions
Foo_ed::Foo_ed() { /* Impl */ }
~Foo_ed::Foo_ed() { /* Impl */ }
Foo_ed::Foo_ed( const Foo_ed& rhs ) { /* Impl */ }
bool Foo_ed::interpolate( std::string& tokenBlock ) { /* Impl */ }
//->Foo_ed:: member functions defined

FooBar_ed::FooBar_ed() { /* Impl */ }
~FooBar_ed::FooBar_ed() { /* Impl */ }
FooBar_ed::FooBar_ed( const FooBar_ed& rhs ) { /* Impl */ }
bool FooBar_ed::interpolate( std::string& tokenBlock ) { /* Impl */ }
//->FooBar_ed:: member functions defined

FooBarFooBoo_ed:: FooBarFooBoo_ed () { /* Impl */ }
~FooBarFooBoo_ed:: FooBarFooBoo_ed () { /* Impl */ }
FooBarFooBoo_ed:: FooBarFooBoo_ed ( const FooBarFooBoo& rhs ) { /* Impl */ }
bool FooBarFooBoo_ed::interpolate( std::string& tokenBlock ) { /* Impl */ }
//->FooBarFooBoo_ed:: member functions defined

But, with templates, the C++ export keyword to separate the C++ template interfaces in the .hpp/.h header file from a secluded and hidden support implementation in the .cpp SOURCE IS NOT supported globally yet, especially with the compiler the project I am working on, which has firmly decided on, Visual C++ 6.0 with Service Pack 5 OR even Visual C++ 7.0 .NET( at least not yet: if Lippman and Sutter have anything to say about it ).

Question: If I cannot use the export templates model to separate class templates intefaces from their implemenations, how CAN I BUILD Windows DLLS from solely C++ template header implementations or from a combination of C++ templates .hpp/.h files and auxillary .cpp files? CAN THIS BE ACCOMPLISHED?
Does the DLL NEED a corresponding .cpp file assuming all DLL implementations are in a templates class?

You help would be greatly needed and appreciated for my own learning.

LAST QUESTION:

When building C++ templates in their .hpp/.h files, and I say have a SINGLETON class that itself is a templatized version of the Singleton, where does the static class data members get initialized?

a) Outside the template Singleton class, but in the same .hpp/.h header file as the template class itself ?

OR

b) like non-template classes holding static data members outside the class definition( unless it is an integral type ).h header file and into the .cpp file at the top of the file, before its use?

AS A SIDE QUESTION?
*Do I need to extern “C” __declspec( dllimport/dllimport ) the individual C++ member functions, static functions, static data variables, and class data instance variables?

Thank You for help,
GeneralRe: User defined C++ template implementations in Windows DLLs using implicit linking Pin
Joaquín M López Muñoz11-Jul-02 20:32
Joaquín M López Muñoz11-Jul-02 20:32 
GeneralRe: User defined C++ template implementations in Windows DLLs using implicit linking Pin
Anonymous11-Jul-02 21:13
Anonymous11-Jul-02 21:13 
GeneralRe: User defined C++ template implementations in Windows DLLs using implicit linking Pin
tgeraldino11-Jul-02 21:16
tgeraldino11-Jul-02 21:16 
GeneralRe: User defined C++ template implementations in Windows DLLs using implicit linking Pin
tgeraldino11-Jul-02 21:19
tgeraldino11-Jul-02 21:19 
QuestionWhat should I do when I want add OLE server to my MDI software? Pin
neilxp11-Jul-02 17:43
neilxp11-Jul-02 17:43 
General2 Dialog box problem Pin
Solero11-Jul-02 16:54
Solero11-Jul-02 16:54 
GeneralRe: 2 Dialog box problem Pin
Chris Losinger11-Jul-02 18:06
professionalChris Losinger11-Jul-02 18:06 
GeneralMacro doesn't work =\ Pin
Vitaly Belman11-Jul-02 16:36
Vitaly Belman11-Jul-02 16:36 
GeneralRe: Macro doesn't work =\ Pin
Chris Losinger11-Jul-02 16:52
professionalChris Losinger11-Jul-02 16:52 
GeneralRe: Macro doesn't work =\ Pin
Vitaly Belman12-Jul-02 2:12
Vitaly Belman12-Jul-02 2:12 
GeneralRe: Macro doesn't work =\ Pin
Chris Losinger12-Jul-02 3:15
professionalChris Losinger12-Jul-02 3:15 
GeneralAppending Wave files Pin
Brakanjan11-Jul-02 15:53
Brakanjan11-Jul-02 15:53 
GeneralRe: Appending Wave files Pin
KaЯl12-Jul-02 3:59
KaЯl12-Jul-02 3:59 
GeneralRe: Appending Wave files Pin
Jh313-Jul-02 22:35
Jh313-Jul-02 22:35 
QuestionHow to let childWindow have same focus as parent ? Pin
bisserke11-Jul-02 13:20
bisserke11-Jul-02 13:20 
AnswerRe: How to let childWindow have same focus as parent ? Pin
Nish Nishant11-Jul-02 14:51
sitebuilderNish Nishant11-Jul-02 14:51 
QuestionDo I need the latest Platform SDK? Pin
BigCaot11-Jul-02 12:40
sussBigCaot11-Jul-02 12:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.