Che Posted December 28, 2014 Report Posted December 28, 2014 Am gasit pe net aceste doua tutoriale despre cum sa faci un dll si cum sa-l folosesti in aplicatia ta:Walkthrough: Creating and Using a Dynamic Link Library (C++)siBasic C++ Win32 DLL - CodeProjectVad ca la cel de pe MSDN headerul e de forma urmatoare:// MathFuncsDll.h#ifdef MATHFUNCSDLL_EXPORTS#define MATHFUNCSDLL_API __declspec(dllexport) #else#define MATHFUNCSDLL_API __declspec(dllimport) #endifSi zice ca:When the MATHFUNCSDLL_EXPORTS symbol is defined, the MATHFUNCSDLL_API symbol will set the __declspec(dllexport) modifier in the member function declarations in this code. This modifier enables the function to be exported by the DLL so that it can be used by other applications. When MATHFUNCSDLL_EXPORTS is undefined—for example, when the header file is included by an application—MATHFUNCSDLL_API defines the __declspec(dllimport) modifier in the member function declarations. This modifier optimizes the import of the function in an application. In celalalt tutorial headerul e de forma urmatoare:namespace MyWin32DLL{ class MyWin32ClassOne { private: int varone; public: __declspec(dllexport) MyWin32ClassOne();//constructor __declspec(dllexport) void Setvar(int val); __declspec(dllexport) int Getvar(); };} 1. Cum e mai bine sa fie headerul construit: ca in prima situatie sau ca in a doua ?2. Daca ar fi sa transformi headerul al doilea asa de felul cum arata cel de primul, cum ar trebui sa arate ? Ma poate ajuta cineva cu chestia asta ?Multumesc mult ! Quote
Erase Posted January 3, 2015 Report Posted January 3, 2015 (edited) #define este o directiva sau un macro catre preprocesor. Diferenta dintre cele doua este ca in al doilea cod nu e definita acea directiva.Daca ar fi sa aplicam modificarile din primul cod ar arata cam asa:#ifdef MATHFUNCSDLL_EXPORTS#define MATHFUNCSDLL_API __declspec(dllexport) #else#define MATHFUNCSDLL_API __declspec(dllimport) #endif namespace MyWin32DLL{ class MyWin32ClassOne { private: int varone; public: MATHFUNCSDLL_API MyWin32ClassOne(); //si asa mai departe si cu celelalte };} De citit in continuare referinta msdn. Edited January 3, 2015 by Erase Quote
Che Posted January 3, 2015 Author Report Posted January 3, 2015 #define este o directiva sau un macro catre preprocesor. Diferenta dintre cele doua este ca in al doilea cod nu e definita acea directiva.Daca ar fi sa aplicam modificarile din primul cod ar arata cam asa:#ifdef MATHFUNCSDLL_EXPORTS#define MATHFUNCSDLL_API __declspec(dllexport) #else#define MATHFUNCSDLL_API __declspec(dllimport) #endif namespace MyWin32DLL{ class MyWin32ClassOne { private: int varone; public: MATHFUNCSDLL_API MyWin32ClassOne(); //si asa mai departe si cu celelalte };} De citit in continuare referinta msdn.Si de chemat dll-ul in programul tau cum e mai bine/mai corect sa-l chemi, asa: sau asa: Quote
Erase Posted January 3, 2015 Report Posted January 3, 2015 Cel mai bine e sa-l incarci doar cand ai nevoie de el. Quote