I came from a C # / Java background, so I'm trying to figure out how to create a C ++ dll that behaves similarly to a C # dll.
I experimented with __declspec(dllexport) and __declspec(dllimport) , but I managed to get it working with static methods. I am sure this is due to my limited understanding.
How can I export classes in C ++ (in full, including private members), and be able to create them at the end of the link, as with C #? Some pointers to online resources / tutorial will also do this.
I started using the MFC dll template, and frankly, I have no idea what 90% of them are and why I inherit CWinApp. I tried tagging the CCppPracticeLibraryApp class, but it will no longer compile.
// CppPracticeLibrary.h : main header file for the CppPracticeLibrary DLL // #pragma once #ifndef __AFXWIN_H__ #error "include 'stdafx.h' before including this file for PCH" #endif #include "resource.h" // main symbols #ifdef CCppPracticeLibraryApp_EXPORTS #define CCppPracticeLibraryApp_API __declspec(dllexport) #else #define CCppPracticeLibraryApp_API __declspec(dllimport) #endif // CCppPracticeLibraryApp // See CppPracticeLibrary.cpp for the implementation of this class // class CCppPracticeLibraryApp : public CWinApp { public: CCppPracticeLibraryApp(); static CCppPracticeLibraryApp_API void SayHelloWorld(); // Overrides public: virtual BOOL InitInstance(); DECLARE_MESSAGE_MAP() };
definition file:
//CppPracticeLibrary.cpp: Defines the initialization procedures for the DLL.
#include "stdafx.h" #include "CppPracticeLibrary.h" #ifdef _DEBUG #define new DEBUG_NEW #endif #define CCppPracticeLibraryApp_EXPORTS BEGIN_MESSAGE_MAP(CCppPracticeLibraryApp, CWinApp) END_MESSAGE_MAP()
Client / link method
// TestConsoleApplication.cpp : Defines the entry point for the console application. //
I would like to be able to uncomment the following lines in the above code:
source share