Cpp dll export function or class _ stdcall

Source: Internet
Author: User

_ Stdcall is the standard for Windows function calls. Pascal and winapi are the same.

The default call Convention for C is _ cdecl.

DLL project:

 
// Mydll. h # ifdef mydll_header # else # define mydll_header extern "C" _ declspec (dllimport) # endifmydll_header int _ stdcall add (int A, int B ); mydll_header int _ stdcall substract (int A, int B);/* class mydll_header point {public: Point (int A, int B): X (A), y (B) {} void output (); Private: int X, Y ;}; */////////////////////////////////////// //////////////////////////////////////// /// // mydll. CPP # define mydll_header extern "C" _ declspec (dllexport) # include "mydll. H "# include" windows. H "# include" stdio. H "int _ stdcall add (int A, int B) {return a + B;} int _ stdcall substract (int A, int B) {return a-B ;} /* member function void point: output () {hwnd handle = getforegroundwindow (); HDC Dc = getdc (handle); char Buf [20]; sprintf (BUF, "x = % d, y = % d", this-> X, this-> Y); textout (DC, 0, 0, Buf, strlen (BUF); releasedc (handle, DC );}*/

Caller:

 // client. CPP # include "mydll. H "//... void cmydlltestdlg: onbuttonadd () {cstring STR; Str. format ("5 + 3 = % d", add (5, 3); MessageBox (STR);} void cmydlltestdlg: onbuttonsubstract () {cstring STR; Str. format ("5-3 = % d", substract (5, 3); MessageBox (STR);} void cmydlltestdlg: onbuttonoutput () {// point Pt (11, 3222 ); // PT. output () ;}

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.