You receive a C4226 or a C4236 error message when you compile code to contain the keyword in 32-bit Visual C++(ZZ)

You receive a C4226 or a C4236 error message when you compile code to contain the keyword in 32-bit Visual C++

Article ID:107501
Last Review:April 28, 2005
Revision:3.0
This article was previously published under Q107501

SUMMARY

The __export keyword provided with the Visual C++ for Windows compiler is obsolete with the Microsoft Visual C++ 32-bit compiler. The equivalent functionality for WIN32 can be achieved by using the keyword __declspec with the dllexport attribute. With Visual C++ 32-bit Edition, version 4.0, compiling code containing the __export (or _export) keyword results in either of the following warnings:
C4236: nonstandard extension used : '__export' is an obsolete keyword, see documentation for __declspec(dllexport)
- or -
C4226: nonstandard extension used : '__export' is an obsolete keyword
Compiling code containing the __export (or _export) keyword with 32-bit Visual C++, versions 1.0 and 2.x, results in the C4226 warning.

MORE INFORMATION

The __declspec construct is not supported by the tools supplied with Microsoft Win32 Software Development Kit (SDK).

When porting DLL source code from Windows to Win32, replace each instance of __export with __declspec( dllexport ). The __declspec(dllexport) keyword can be used to export data, functions, classes, or class member functions. For example:
   /* exported function */
   __declspec( dllexport ) void func();

   /* exported data */
   __declspec( dllexport ) int i;

   // exported class
   class __declspec( dllexport ) DLLClass
   {
      ...
   };

   class DLLClass
   {
   public:
       // exported member function
       __declspec( dllexport ) void MemberFunction( void );
   };
				
The sample code below demonstrates exporting classes and class member functions from a DLL using the __declspec( dllexport ) and __declspec( dllimport ) storage class attributes in the DLL and EXE, respectively.

Sample Code

   /* DLL Sample: TESTDLL.CPP
   /* Compile options needed: /D"_X86" /MT TESTDLL.CPP /link
   /*                  /DLL /OUT:testdll.dll /implib:testdll.lib
   */

   #include <stdio.h>

   class DLLClass
       {
       public:
        // exported member function
        __declspec( dllexport ) void functionA( void ) {
            printf("/nIn Function A of the exported function");
        }
       };

   // exported class
   class __declspec( dllexport) ExportDLLClass
       {
       public:
        void functionB(void) {
           printf("/nIn Function B of the exported class");
        }
       };

   // exported instance of the DLLClass
   __declspec(dllexport) DLLClass test;


   /* Source that calls the DLL Sample: CALLDLL.CPP
   /* Compile options needed: /D"_X86" /D"_CONSOLE" /ML CALLDLL.CPP
   /*                  TESTDLL.LIB
   */

   #include <stdio.h>

   class DLLClass
       {
       public:
        // imported member function
        __declspec( dllimport ) void functionA( void );
       };

   class __declspec( dllimport) ExportDLLClass
       {
       public:
        void functionB(void);
       };

   __declspec( dllimport ) DLLClass test;

   void main(void)
   {
      ExportDLLClass TestClass;

      test.functionA();
      TestClass.functionB();
   }
				

REFERENCES

For more information on exporting, query on the following words in the Microsoft Knowledge Base:
__export and def and prolog and dllexport
For more information creating DLLs for WIN32 or on the dllexport and dllimport storage class attributes, refer to Chapter 4 of the "Programming Techniques" manual that ships with Visual C++ 32-bit Edition, or search for dllexport or dllimport or export in the Visual C++ Books Online. >From within the Visual Workbench, select Help and choose Keyword Search.

APPLIES TO
Microsoft Visual C++ 1.0 Professional Edition
Microsoft Visual C++ 2.0 Professional Edition
Microsoft Visual C++ 4.0 Standard Edition
Microsoft Visual C++ 5.0 Enterprise Edition
Microsoft Visual C++ 6.0 Enterprise Edition
Microsoft Visual C++ 5.0 Professional Edition
Microsoft Visual C++ 6.0 Professional Edition
Microsoft Visual C++ 6.0 Standard Edition
Keywords: 
kblangc KB107501
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值