Click here to Skip to main content
15,918,343 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Windows Message Pin
Miszou10-Jun-03 7:33
Miszou10-Jun-03 7:33 
GeneralRe: Windows Message Pin
Nick Parker10-Jun-03 7:44
protectorNick Parker10-Jun-03 7:44 
GeneralRe: Windows Message Pin
basementman10-Jun-03 8:33
basementman10-Jun-03 8:33 
GeneralCView And CSpliterWnd Pin
MinhHai10-Jun-03 5:44
MinhHai10-Jun-03 5:44 
GeneralRe: CView And CSpliterWnd Pin
valikac10-Jun-03 6:45
valikac10-Jun-03 6:45 
GeneralShipping .h files for .DLL classes Pin
Theopulus10-Jun-03 5:16
Theopulus10-Jun-03 5:16 
GeneralRe: Shipping .h files for .DLL classes Pin
Nemanja Trifunovic10-Jun-03 6:07
Nemanja Trifunovic10-Jun-03 6:07 
GeneralRe: Shipping .h files for .DLL classes Pin
Peter Weyzen10-Jun-03 20:21
Peter Weyzen10-Jun-03 20:21 
If you want to ship .H files with a DLL, without giving away any information about what's really in there, the "PIMPL" thing does the trick. Though it's slightly more involved than just shipping a header.

You end up creating 2 headers:
(1) An interface. A header for the public name of your class and public API's in this class. It describes the structure without the meat.
(2) The actual class header, which defines all the stuff, the data, other public and private methods, yada yada yada. This class header also subclasses the interface class. This is referred to as the "implementation".

You must also create a factory method to create your class. It's not acceptable to let the consumer of your DLL do a "new MyClass". This is because the header that you ship him represents only an interface to the class that get's instantiated, and not the actual class.

You must also create a mechanism of destruction. Since the class was created with a factory, and possibly from a different heap than yours -- YOU MUST tell the class to destroy itself. My favorite easy way is to put a virtual "DeleteThis()" method on it.

Here's a quick sample -- in one possible way. (this doesn't match PIMPL exactly -- what an awful name!) But it shows some of the details:

MyClass.H
------------------
class __declspec(dllexport) MyClass<br />
{<br />
public:<br />
  virtual int Function1() = 0;<br />
  virtual int Function2() = 0;<br />
  <br />
  virtual void DeleteThis() = 0;<br />
  static void MyClass* New();<br />
};

------------------

MyClassImpl.H
---------------------
class __declspec(dllexport) MyClassImpl : public MyClass<br />
{<br />
public:<br />
  virtual int Function1() { do something; }<br />
  virtual int Function2() { do something else; }<br />
  virtual void DeleteThis() {delete this;}<br />
  int m_MagicDataThatNoOneCanSee;<br />
  <br />
  int MagicFunction();<br />
};

---------------------

MyClassImpl.CPP
---------------------
MyClass *MyClass::New()<br />
{<br />
  return new MyClassImpl;<br />
}<br />
.....//more stuff 

---------------
---------------------

The gist of this -- is that you hand out interfaces ONLY. The guts that implement the interface can change at will.

This is also one of the foundations of how COM stuff is implemented. They export everything in COM the same way..... With the use of COM you can even play tricks, like creating implementations that actually serve up multiple interfaces.... but's that's another story.

This way of doing things is great. It offers you a lot of flexibility and safety in creating API's!

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />
Peter Weyzen<br />
Staff Engineer<br />
Santa Cruz Networks

GeneralMix casing a name field Pin
Bryster10-Jun-03 4:13
Bryster10-Jun-03 4:13 
GeneralRe: Layered window problem Pin
Bedas10-Jun-03 4:11
Bedas10-Jun-03 4:11 
GeneralRe: Layered window problem Pin
Ryan Binns10-Jun-03 4:26
Ryan Binns10-Jun-03 4:26 
Questionhow to size an app to fit a PC's display size Pin
johnstonsk10-Jun-03 4:06
johnstonsk10-Jun-03 4:06 
AnswerRe: how to size an app to fit a PC's display size Pin
Florin Ochiana10-Jun-03 4:17
Florin Ochiana10-Jun-03 4:17 
GeneralRe: how to size an app to fit a PC's display size Pin
Ryan Binns10-Jun-03 4:37
Ryan Binns10-Jun-03 4:37 
AnswerRe: how to size an app to fit a PC's display size Pin
Ryan Binns10-Jun-03 4:35
Ryan Binns10-Jun-03 4:35 
GeneralRe: how to size an app to fit a PC's display size Pin
johnstonsk10-Jun-03 7:43
johnstonsk10-Jun-03 7:43 
GeneralOleCreateFromFile Pin
Florin Ochiana10-Jun-03 3:56
Florin Ochiana10-Jun-03 3:56 
GeneralCRichEditCtrl FormatRange Bounding Rectangle Pin
Larry J. Siddens10-Jun-03 3:48
Larry J. Siddens10-Jun-03 3:48 
GeneralRe: CRichEditCtrl FormatRange Bounding Rectangle Pin
Larry J. Siddens11-Jun-03 2:36
Larry J. Siddens11-Jun-03 2:36 
GeneralCatch the "enter" Pin
Woltan10-Jun-03 3:34
Woltan10-Jun-03 3:34 
GeneralRe: Catch the &quot;enter&quot; Pin
Maximilien10-Jun-03 3:44
Maximilien10-Jun-03 3:44 
GeneralRe: Catch the &quot;enter&quot; Pin
Mike Dimmick10-Jun-03 6:12
Mike Dimmick10-Jun-03 6:12 
GeneralRe: Catch the &quot;enter&quot; Pin
Florin Ochiana10-Jun-03 4:15
Florin Ochiana10-Jun-03 4:15 
Generalget_innerText Pin
Majid Shahabfar10-Jun-03 3:26
Majid Shahabfar10-Jun-03 3:26 
GeneralRe: get_innerText Pin
David Crow10-Jun-03 6:58
David Crow10-Jun-03 6:58 

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.