When I write the C + + (except MFC) program under VS2005, I don't like the few subordinate files "stdafx.h" and "stdafx.cpp" that the wizard generates. Because if you put your code on another compiler, you need to change a lot of things. I am now accustomed to using a header file I wrote "Start.h", each time manually introduced.
The same is true today when making DLLs in C + +, generating a project name of MyTest, and then manually defining the introduction of the DLL (this is just an example)
#ifndef MYDLL # ifdef mydll_exports # define MYDLL __declspec (dllexport) # Else # define MYDLL __declspec (dllimport) # End If #endif
Use as follows:
MyTest.h extern MYDLL int nmytest; MYDLL int fnmytest (void); MyTest.cpp MYDLL int nmytest=0; This is a example of an exported function. MYDLL int fnmytest (void) {return 0;}
2 errors were reported at the time of the final compilation.
Error C2491: ' nmytest ': definition of dllimport function not allowed
Error C2491: ' fnmytest ': definition of dllimport function not allowed
Then it was completely silent, and later on MSDN, there was an article about it.
#define MYDLL __declspec (dllimport) is a useful statement when it is found to be predefined.
Then I add a pre-defined above, define MYDLL __declspec (dllexport), this can compile the past, but how to look like the lily. Finally, a C + + auto-generated DLL was introduced to make a comparison, and finally found:
The original is a predefined macro is not set to, I built the project name is MyClass, the system on the custom generated myclass_exports such a macro, and then I manually changed to Mydll_exports to compile successfully.
Here's where the compiler resets the predefined macros, I use the VS2005 English version:
Preprocessor, Project--XX property Pages, C + +;
Change the wizard-generated DLL in the properties of the preprocessor definitions to your own definition.
In this example, the myclass_exports is changed to Mydll_exports.
Summary: VS is really strong enough for you to fix everything. I still ungrateful .... Ha ha
Due to the level of limited, what is the problem, please crossing, thank you.