Click here to Skip to main content
15,902,938 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionFinding if a pc has n/w connection Pin
Smith#19-Nov-06 22:13
Smith#19-Nov-06 22:13 
AnswerRe: Finding if a pc has n/w connection Pin
Michael Dunn19-Nov-06 22:34
sitebuilderMichael Dunn19-Nov-06 22:34 
QuestionRe: Finding if a pc has n/w connection Pin
Smith#19-Nov-06 23:08
Smith#19-Nov-06 23:08 
QuestionHiding private members of Class with DLLs Pin
uusheikh19-Nov-06 22:10
uusheikh19-Nov-06 22:10 
AnswerRe: Hiding private members of Class with DLLs Pin
Cedric Moonen19-Nov-06 22:50
Cedric Moonen19-Nov-06 22:50 
AnswerRe: Hiding private members of Class with DLLs Pin
Mr.Brainley19-Nov-06 23:28
Mr.Brainley19-Nov-06 23:28 
AnswerRe: Hiding private members of Class with DLLs Pin
Maximilien20-Nov-06 1:49
Maximilien20-Nov-06 1:49 
AnswerRe: Hiding private members of Class with DLLs [modified] Pin
cmk20-Nov-06 3:39
cmk20-Nov-06 3:39 
The problem is that the header defines not only the object interface, but also the size.

By building the dll with one header (with private members) and building an exe with another (no private members) you are using a different a sized object in the exe. At best you will experience what you have - runs with error at end. Most likely the program would be corrupting data everywhere.

uus831 wrote:
Any suggestion how i can hide the private members (users cant modify them anyway, they are private!).


This isn't true, all non-const data can be modified, private is just the class developer attempting to create a contract with other developers who use the class. Another developer can just mod your header and replace private with public, now they can compile/link without warnings/errors and modify the (originally) private members however they want.

So, your choices:

1. Include a dummy private variable (byte array) that is the same size as all your private/protected members (including padding due to alignment). This can be tricky and is not recommended.

2. Export as an interface, as others have suggested.

3. Export with full header, as most people do/suggest.

[EDIT]
4. As Maximilien suggested, or even easier, just have a pointer to a private state struct.
e.g.
// In Header:
struct Apvt;
class  A {
    Apvt  *pvt;
public:
    A( void );
    ~A( void );
    ...
};
 
// In Source
typedef  struct Apvt {
  ...  // private members
} Apvt;
 
A:: A( void ) { pvt = new Apvt; }
A::~A( void ) { if(pvt)  delete pvt;  pvt = NULL; }
This is actually a fairly common method that i've seen and used before.
[/EDIT]


...cmk

Save the whales - collect the whole set

GeneralRe: Hiding private members of Class with DLLs Pin
uusheikh20-Nov-06 22:55
uusheikh20-Nov-06 22:55 
GeneralConvert Date to COleDateTime Pin
Monty219-Nov-06 21:51
Monty219-Nov-06 21:51 
GeneralAnd the answer is .. Pin
Monty219-Nov-06 21:54
Monty219-Nov-06 21:54 
QuestionAdding treeviewCtrl to a combobox Pin
Nagaraju_Focus19-Nov-06 21:33
Nagaraju_Focus19-Nov-06 21:33 
AnswerRe: Adding treeviewCtrl to a combobox Pin
Steve Echols19-Nov-06 21:52
Steve Echols19-Nov-06 21:52 
QuestionScoket. Pin
Abbas Murad19-Nov-06 21:11
Abbas Murad19-Nov-06 21:11 
AnswerRe: Scoket. Pin
Mark Salsbery20-Nov-06 5:58
Mark Salsbery20-Nov-06 5:58 
GeneralRe: Scoket. Pin
Abbas Murad20-Nov-06 17:41
Abbas Murad20-Nov-06 17:41 
QuestionSerial I/O in Non-Overlapped mode .... Pin
Mohammd Bilal19-Nov-06 21:08
Mohammd Bilal19-Nov-06 21:08 
AnswerRe: Serial I/O in Non-Overlapped mode .... Pin
Roger Stoltz19-Nov-06 21:36
Roger Stoltz19-Nov-06 21:36 
AnswerRe: Serial I/O in Non-Overlapped mode .... Pin
CPallini20-Nov-06 2:24
mveCPallini20-Nov-06 2:24 
QuestionHow to draw the window border by myself ? Pin
samfromcn19-Nov-06 21:08
samfromcn19-Nov-06 21:08 
QuestionHow to get mouse selected text? thanks ... Pin
tiaozi19-Nov-06 20:46
tiaozi19-Nov-06 20:46 
AnswerRe: How to get mouse selected text? thanks ... Pin
Rajesh R Subramanian19-Nov-06 23:20
professionalRajesh R Subramanian19-Nov-06 23:20 
Answerchildfrm Pin
Programm3r20-Nov-06 4:47
Programm3r20-Nov-06 4:47 
AnswerMainfrm Pin
Programm3r20-Nov-06 4:48
Programm3r20-Nov-06 4:48 
Questionset transparent to slidercontrol background... Pin
klvin19-Nov-06 19:53
klvin19-Nov-06 19:53 

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.