petit ex detaillé vite fait:
----------------------
Dans la DLL: le . h
----------------------
- ifdef PRIMITIVES_EXPORTS
- define PRIMITIVES_API __declspec(dllexport)
- else
- define PRIMITIVES_API __declspec(dllimport)
- endif
class PRIMITIVES_API Toto
{
public:
Toto();
~Toto();
inline int Get() {return(i);}
private:
int i;
} T;
class PRIMITIVES_API Primitives
{
public:
Primitives(void);
inline Toto* Get() {return(&);}
private:
Toto T;
} P;
PRIMITIVES_API Toto* appel();
PRIMITIVES_API int Geti( Toto* objet );
-----------------------
le . cpp de la DLL
-----------------------
- include "stdafx.h"
- include "Primitives.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
Toto::Toto() : i(0) {}
Toto::~Toto(){}
Primitives::Primitives()
{
}
Toto* appel()
{
return( P.Get() );
}
int Geti( Toto* objet )
{
return( objet->Get() );
}
------------------------
Le . h du prog appelant
------------------------
- define PRIMITIVES_H
- include <stdio.h>
__declspec(dllimport) class Toto*appel();
__declspec(dllimport) int Geti( Toto*objet );
- endif
-------------------------------
Enfin le . cpp du prog appelant
-------------------------------
- include "stdafx.h"
- include "Primitives.h"
- pragma comment(lib,"Primitives.lib")
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
FILE* f = fopen("debug.txt","w");
Toto* T = NULL;
fprintf(f, "Adresse de T = %p\n", T);
T = appel();
fprintf(f, "Adresse de T = %p\n", T);
fprintf(f, "i = %i\n", Geti(T) );
fclose(f);
return 0;
}