Re: SysAllocString
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Thu, 29 Nov 2007 08:39:20 -0500
"George" <George@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:61889BD3-EB97-4556-915C-E076085E31B5@xxxxxxxxxxxxx
1. Windows API is more compatible, since we use some version Windows
API (and related SDK) and it is supposed to work with another version
of Windows API (runtime);
You don't build with a specific version of Windows API. Your executable
just mentions API functions by name. The implementation of the API
functions is part of the operating system, and is installed when Windows
is installed. When the executable runs, it uses whatever implementation
of the API functions (again, bound by name) exists on the machine it is
running on.
Yes, Microsoft goes to great lengths to ensure that a particular named
function behaves the same on all Windows versions it is supported on.
That's how you can run the same binary on different OS versions without
having to recompile.
2. CRT (do you man C Runtime Library? :-)) is less compatible
compared with Windows API? For example, you mentioned if we build
with one version CRT (compiler/SDK) and if we run it with another
version CRT runtime, it is not supposed to work well 100%?
You generally can't do that. When you build with a particular CRT
version, you have to ship this version with your application (a CRT is
not part of the OS, you shouldn't expect it to be installed and ready
for your application). If you link to CRT statically, a copy of the CRT
is physically embedded in your binary (which also naturally leads to
your shipping the CRT with your application).
The problems begin when you have multiple modules (binaries) running in
your process (an EXE and several DLLs), each with its own version of the
CRT or using no CRT at all. A pair of complementary CRT functions (e.g.
malloc/free, fopen/fclose) works together when both functions come from
the same CRT instance, but generally doesn't work if the two functions
come from different copies of the CRT (even if the same version). This
means that you cannot, in general, allocate memory with malloc in one
module, pass the pointer to another, and successfully deallocate it with
free in that other module. Or fopen a file in one module, pass FILE*
pointer to the other, and fclose it there. On the other hand, you can
happily open a file with CreateFile, pass HANDLE to another module, and
CloseHandle there, because CreateFile and CloseHandle are Windows APIs
and all the modules in the process (and indeed, all processes on the
machine) use the same copy of the API.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- Follow-Ups:
- Re: SysAllocString
- From: George
- Re: SysAllocString
- References:
- Re: SysAllocString
- From: Igor Tandetnik
- Re: SysAllocString
- From: Igor Tandetnik
- Re: SysAllocString
- From: George
- Re: SysAllocString
- From: Norbert Unterberg
- Re: SysAllocString
- From: George
- Re: SysAllocString
- From: Tim Roberts
- Re: SysAllocString
- From: Igor Tandetnik
- Re: SysAllocString
- From: Norbert Unterberg
- Re: SysAllocString
- From: Igor Tandetnik
- Re: SysAllocString
- From: George
- Re: SysAllocString
- Prev by Date: Where do I find XML error codes?
- Next by Date: BackupWrite skipping NTFS Change Journal
- Previous by thread: Re: SysAllocString
- Next by thread: Re: SysAllocString
- Index(es):
Relevant Pages
|