Jump to content
Che

[C++] Cum ar trebui sa fie header-ul dll-ului ?

Recommended Posts

Posted

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++)

si

Basic C++ Win32 DLL - CodeProject

Vad 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)
#endif

Si 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 !

Posted (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 by Erase
Posted
#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:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...