酌中志txt:How To Export Data from a DLL or an Application
来源:百度文库 编辑:九乡新闻网 时间:2024/05/17 01:51:10
http://support.microsoft.com/kb/90530
HOWTO: How To Export Data from a DLL or an Application
View products that this article applies to.This article was previously published under Q90530Expand all | Collapse allSUMMARY
It is possible for a Win32-based application to be able to address DLLglobal variables directly by name from within the executable. This is doneby exporting global data names in a way that is similar to the way youexport a DLL function name. Use the following steps to declare and utilizeexported global data.- Define the global variables in the DLL code. For example:
int i = 1; int *j = 2; char *sz = "WBGLMCMTP";
- Export the variables in the module-definition (DEF) file. With the 3.1 SDK linker, use of the CONSTANT keyword is required, as shown below:
EXPORTS i CONSTANT j CONSTANT sz CONSTANT
With the 3.5 SDK linker or the Visual C++ linker, use of the DATA keyword is required, as shown belowEXPORTS i DATA j DATA sz DATA
Otherwise, you will receive the warning warning LNK4087: CONSTANT keyword is obsolete; use DATA Alternately, with Visual C++, you can export the variables with:_declspec( dllexport ) int i; _declspec( dllexport ) int *j; _declspec( dllexport ) char *sz;
- If you are using the 3.1 SDK, declare the variables in the modules that will use them (note that they must be declared as pointers because a pointer to the variable is exported, not the variable itself):
extern int *i; extern int **j; extern char **sz;
If you are using the 3.5 SDK or Visual C++ and are using DATA, declare the variables with _declspec( dllimport ) to avoid having to manually perform the extra level of indirection:_declspec( dllimport ) int i; _declspec( dllimport ) int *j; _declspec( dllimport ) char *sz;
- If you did not use _declspec( dllimport ) in step 3, use the values by dereferencing the pointers declared:
printf( "%d", *i ); printf( "%d", **j ); printf( "%s", *sz );
It may simplify things to use #defines instead; then the variables can be used exactly as defined in the DLL:#define i *i #define j *j #define sz *sz extern int i; extern int *j; extern char *sz; printf( "%d", i ); printf( "%d", *j ); printf( "%s", sz );
How To Export Data from a DLL or an Application
How to Create an HTML Editor Application
How To Use ADO with Excel Data from Visual Ba...
To Be an Individual Or to Be in a Body?
How To Make a Youtube Video Into an Animated GIF
How to Select a Company or Product Name
How to be an expert
How to Create an HTML Editor Application1
An introduction to Excel and XML data files
To abolish the treaty or to ally for China an...
Data From Raid Links Bin Laden to Newer Terro...
How to complicate a deal
How to Write a Rebuttal
How to read a book!!!
How To Become A Hacker
How to See What DLL Files are used by Programs
How To Build an Add-in (XLL) for Excel Using ...
Getting a CF_DIB or CF_METAFILEPICT from the ...
MT4 gurus: How do I access an indicator of a ...
英文电影 How to complicate a deal
How to Treat a Cold During Pregnancy?
How to implement a scrollable child dialog
How to Landscape on a Small Budget
How to Write a Rebuttal Essay