help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Win32 Exporting API functions


From: Izo
Subject: Re: Win32 Exporting API functions
Date: Tue, 10 Aug 2004 14:14:18 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4) Gecko/20030624 Netscape/7.1



JKop wrote:
I'm writing a Win32 executable. While I want this program to be a ".exe" file that I can execute, I also want to export functions (and maybe classes) as does a DLL.


How can you export/link symbols from program ? You should create the DLL / shared object and link your executable(s) against it, anyway.

Could someone please tell me what I have to do to my actual code, eg. to export the following function:


#if defined(WIN32)
# ifdef MY_DLL_EXPORTS
#  define MY_DLL_API __declspec(dllexport)
# else
#  define MY_DLL_API __declspec(dllimport)
# endif
#else /* some other platform, e.g. gcc on some UNIX which does not need this mess, fortunately */
# define MY_DLL_API
#endif


int Blah()

goes to:

MY_DLL_API int Blah() { ... }


And if possible the following class:

class Cow

goes to

class MY_DLL_API Cow { .... }

or

class Cow {
public:
        int method1 (...);
        MY_DLL_API char method2 (...);
....
....
}

But I am not quite sure for that one - I have forgotten that a little bit already.

>
> And also what command line switches do I need to provide
> when compiling it?

You use -D MY_DLL_EXPORTS as precompiler option in the project generating dll, while omit it in dll importing project. Do not forget to use different switches for different DLLs which make dependency tree otherwise you get the symbol mess ! You use -D WIN32 (I just do not remember if it is already provided by MS C++ compiler or not) to indicate that we are working the stuff on top of the WIN32 or somewhere else and that we need the dllexport/dllimport specifiers or we need them not..


Thanks,


You're welcome

-JKop

Izo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]