DLL export class must export interface

Source: Internet
Author: User
Tags export class

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.