Advertisement
mechanicker

Help with implicit linking a dll to another dll

May 20th, 2018
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.94 KB | None | 0 0
  1.     // Shape.h -- this would be A.dll
  2.     #pragma once
  3.  
  4.     // Notice the conditional
  5.     #ifdef SHAPE_EXPORTS
  6.     #define SHAPE_API __declspec(dllexport)
  7.     #else
  8.     #define SHAPE_API __declspec(dllimport)
  9.     #endif
  10.  
  11.     class SHAPE_API Shape /*: public IShape*/
  12.     {
  13.     public:
  14.         Shape();
  15.         Shape(int sides, int sideLength, int apothem);
  16.         ~Shape();
  17.  
  18.         int Perimeter();
  19.         double Area();
  20.     private:
  21.         int sides;
  22.         int sideLength;
  23.         int apothem;
  24.     };
  25.  
  26.     // Shape.cpp
  27.  
  28.     // Do it before including the header to get dllexport
  29.     #define SHAPE_EXPORTS
  30.  
  31.     #include "stdafx.h"
  32.     #include "Shape.h"
  33.  
  34.     Shape::Shape() : sides(0), sideLength(0), apothem(0)
  35.     {
  36.     }
  37.  
  38.     Shape::Shape(int sides, int sideLength, int apothem) : sides(sides), sideLength(sideLength), apothem(apothem)
  39.     {
  40.     }
  41.  
  42.     Shape::~Shape()
  43.     {
  44.     }
  45.  
  46.     double Shape::Area()
  47.     {
  48.         if (sides == 1 || sides == 2)
  49.         {
  50.             return -1;
  51.         }
  52.  
  53.         return .5 * Perimeter() * apothem;
  54.     }
  55.  
  56.     int Shape::Perimeter()
  57.     {
  58.         return sideLength * sides;
  59.     }
  60.  
  61.     // ShapesTester.h - this would be B.dll
  62.     #include "../TestHarness/ITest.h"
  63.  
  64.     class ShapesTester : ITest
  65.     {
  66.     public:
  67.         ShapesTester();
  68.         ~ShapesTester();
  69.  
  70.         bool Test() override;
  71.         ShapesTester & ShapesTesterFactory();
  72.  
  73.     private:
  74.     };
  75.  
  76.     // ShapesTester.cpp
  77.     #include "stdafx.h"
  78.     #include "ShapesTester.h"
  79.     #include "Shape.h"
  80.  
  81.     ShapesTester::ShapesTester()
  82.     {
  83.     }
  84.  
  85.  
  86.     ShapesTester::~ShapesTester()
  87.     {
  88.     }
  89.  
  90.     bool ShapesTester::Test()
  91.     {
  92.         Shape myShape = Shape(3, 9, 5); // error here; Cannot resolve symbol 'Shape'
  93.  
  94.         return myShape.Area() == 67.5;
  95.     }
  96.  
  97.     ShapesTester & ShapesTesterFactory()
  98.     {
  99.         ShapesTester * tester = new ShapesTester();
  100.  
  101.         return *tester;
  102.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement