Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <stdio.h>
- #include "TestInterface.h"
- // I have put the logOneLine as a global to this file for clarity's sake, and simplified it.
- void logOneLine (const char *caller, const char *msg) {
- static FILE *log = 0;
- log = fopen("TestDLL.log", log ? "at" : "wt");
- fprintf (log, "%s: %s\n", caller, msg);
- fclose (log);
- }
- // Macro logging to ease reading the code.
- #define Log(x) logOneLine(__func__, (x));
- // I added a constructor to TestInterface, visible in the log.
- TestInterface::TestInterface () {
- Log ("...");
- }
- TestInterface::~TestInterface() {
- Log ("...");
- }
- // You have to tell the compiler that you are exporting this class too (see the DECLSPEC definition in the header).
- class DECLSPEC Test : public TestInterface {
- public:
- /**/ Test (const bool, const int);
- virtual ~Test ();
- virtual bool get (bool &flag, int &num);
- virtual bool set (const bool flag, const int num);
- private:
- bool f_flag;
- int f_num;
- };
- // You don't need to re-specify the calling convention nor the declspec here, as it is implicitelly done in the above.
- Test::Test (const bool flag, const int num)
- // Also, attention, you have to initialize your parent class and your members, in that order:
- : TestInterface(), f_flag(flag), f_num(num) {
- Log ("...");
- char buff [255];
- sprintf (buff, "flag=%s, num=%d", flag ? "true" : "false", num);
- Log (buff);
- }
- Test::~Test () {
- Log ("...");
- }
- // Accessors.
- bool Test::get (bool &flag, int &num) {
- flag = f_flag;
- num = f_num;
- return true;
- }
- bool Test::set (const bool flag, const int num) {
- f_flag = flag;
- f_num = num;
- return true;
- }
- // Factory stuff.
- TestInterface* Instanciate (const bool flag, const int num) {
- Log ("...");
- return new Test(flag, num);
- }
- void Destroy (TestInterface *f) {
- Log ("...");
- delete f;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement