Well I tried this but I get link errors.
DLL.h
Printer.hCode:#pragma once #ifdef DLL_EXPORT # undef DLL_EXPORT # define DLL_EXPORT __declspec(dllexport) #else # define DLL_EXPORT __declspec(dllimport) #endif
Printer.cppCode:#pragma once #include <iostream> #include <string> #include "DLL.h" class Printer { public: std::string m_msg; public: Printer(std::string message); ~Printer(); void print(); }; DLL_EXPORT Printer *CreatePrinter(std::string message);
Code:#include "Printer.h" Printer::Printer(std::string message) : m_msg(message) { } Printer::~Printer() { } void Printer::print() { std::cout << m_msg << std::endl; } Printer *CreatePrinter(std::string message) { return new Printer(message); }
Client.cpp
Code:#include <Printer.h> int main() { Printer *p = CreatePrinter("Skata melata"); p->print(); delete p; return 0; }
Link Errors:
I don't really understand what you mean. Can you make me an example to see it? Maybe i'll understand this way.Code:1>Source.obj : error LNK2019: unresolved external symbol "public: __thiscall Printer::~Printer(void)" (??1Printer@@QAE@XZ) referenced in function "public: void * __thiscall Printer::`scalar deleting destructor'(unsigned int)" (??_GPrinter@@QAEPAXI@Z) 1>Source.obj : error LNK2019: unresolved external symbol "public: void __thiscall Printer::print(void)" (?print@Printer@@QAEXXZ) referenced in function _main




Reply With Quote
