RE: [xml] Creating Win32 wrapper function for exported variables



Hi there.

Actually, I will.  This applies to reading or writing to 
variables.  For
example, if you
link against the C runtime as a .dll, errno gets mapped to a 
function since
the actual variable 
(int errno) is stored within the c runtime .dll.  If you 
staticly link to
the c runtime (the c runtime code is 
dumped into your program), then it can simply use 'extern int errno;'

Not true. The issue is multithreading, not static or dynamic link. MS
has two C runtime libraries. One is single-threaded (not thread safe)
and the other is multithreaded (thread safe). The fomer is available
only as a static library. If you link the C runtime dynamically, then
you are forced to use the multithreaded version.

errno is mapped to a function, but only in the thread-safe version of
the C runtime. The function is a way to allow multiple threads to access
errno. This has nothing to do with the ability to export variables from
a dynamic library.

-- From the c runtime --
#if (defined (_MT) || defined (_DLL)) && !defined (_MAC)
_CRTIMP extern int * __cdecl _errno(void);
#define errno   (*_errno())
#else  /* (defined (_MT) || defined (_DLL)) && !defined (_MAC) */
_CRTIMP extern int errno;
#endif  /* (defined (_MT) || defined (_DLL)) && !defined (_MAC) */

As it says, #if defined (_MT) || defined (_DLL), which means either you
are using  multithreaded version statically linked, or you link
dynamically (in which case you certainly use a multithreaded version of
the C runtime).

Ciao
Igor




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