Export global variables in DLL

Source: Internet
Author: User

1. Def File

1 exports2 3 g_ntest data; export global variable 4 5 getglobalvar; export Function

2. Call

1 extern int g_ntest; // declare 2 3 int main (INT argc, char * argv []) 4 {5 * (int *) g_ntest = 1; // note the previous conversions 6 7 return 0; 8}

Note that using extern int g_ntest to declare that the imported global variable is not the DLL's global variable itself, but its address. The application must use the global variable in the DLL through forced pointer conversion. This is from

* (Int *) g_ntest.

3. Better call

1 extern int _ declspec (dllimport) g_ntest; // use _ declspec (dllimport) to import 2 int main (INT argc, char * argv []) 3 {4 g_ntest = 1; // can be directly used without converting 5 6 RETURN 0; 7}

The _ declspec (dllimport) method is used to import the global variable itself, instead of its address.

Export global variables in DLL

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.