Assume the following situation:
A dll exports the following class for the Customer Code
Class _ declspec (dllexport) ctest
{
Public:
Void print1 ()
{
Printf ("print1 ");
C [1023] = 0 xeeeeeeee;
}
Void print2 ()
{
Printf ("print2 ");
}
Int M_a;
};
When the client uses this DLL, the following statement
Class _ declspec (dllimport) ctest
{
Public:
Void print1 ();
Void print2 ();
Int M_a;
};
In this case, the client can use this DLL to export the class.
For function upgrade, assume that the DLL export class has changed:
Class _ declspec (dllexport) ctest
{
Public:
Void print1 ()
{
Printf ("print1 ");
Midata [1023] = 0 xeeeeeeee;
}
Void print2 ()
{
Printf ("print2 ");
}
PRIVATE:
Int M_a;
Int midata [1024];
};
After a new version of DLL is used to directly replace the old version of DLL that the client is using, the client application will encounter an error (Memory access violation).
The reason is: in the client's exe, The ctest is allocated 4 bytes of space. After the DLL is directly replacedEXE ModuleThe code for allocating heap space is unchanged.4Bytes. In this casePrint1 will inevitably encounter memory access errors.
To solve the above problem, dll can only export interface classes, and the Code for creating objects must be completed in the DLL module. The client only accesses the provided interfaces.