Article View: borland.public.cppbuilder.nativeapi
Article #4301Re: GetEnvironmentVariable
From: Alan Bellingham
Date: Wed, 08 Feb 2006 16:30
Date: Wed, 08 Feb 2006 16:30
36 lines
2647 bytes
2647 bytes
"Joanne" <jo.bullock@tiscali.co.uk> wrote: >Still no joy. I notice that the linker error references >GetEnvironmentVariableA whereas my code calls >GetEnvironmentVariable - I don't understand this? That's Microsoft, I'm afraid. There is no Win32 API GetEnvironmentVariable function. Instead, there is a pair of functions, GetEnvironmentVariableA and GetEnvironmentVariableW, for the Ascii and Wide character versions of the same function, and deep within the Windows.h include file (or a file it includes) is a macro definition that does '#define GetEnvironmentVariable GetEnvironmentVariableA' (or ...W) depending on whether you have UNICODE defined or not. What it means is that any function or variable that is actually called GetEnvironmentVariable in the source will be seen by the compiler as GetEnvironmentVariableA (or ...W, depending). Any normal programmer that did this sort of thing would be fired on the spot. Sadly, because it's Microsoft doing it, they get away with it. Not only that, but programmers see Microsoft doing it, and think it's acceptable behaviour. (And they wonder why Microsoft products were so flaky for so long ...) You might be able to sort out the problem with a judicious "#undef GetEnvironmentVariable" after the "#include <windows.h>". >I can use the Win API version of the function, so it is no >hassle, but interesting why it doesn't work! Because you're dealing with Microsoft :-( Alan Bellingham -- ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK
Technical Details
Message-ID:
<bg6ku15tdka0e3rn706stctmqaq48j4ja8@4ax.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<43e73992$1@newsgroups.borland.com> <cv5fu1d1ie53p85obhag3mhcojeo0qlpct@4ax.com> <43e872ec$1@newsgroups.borland.com> <43e89e85$1@newsgroups.borland.com> <43e9b3ee$1@newsgroups.borland.com> <43ea0320$1@newsgroups.borland.com> <43ea18ba$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,de09e7ac5120cd9c X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: Alan Bellingham <alanb@episys.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: GetEnvironmentVariable Date: Wed, 08 Feb 2006 16:30:03 +0000 Reply-To: alanb@episys.com Message-ID: <bg6ku15tdka0e3rn706stctmqaq48j4ja8@4ax.com> References: <43e73992$1@newsgroups.borland.com> <cv5fu1d1ie53p85obhag3mhcojeo0qlpct@4ax.com> <43e872ec$1@newsgroups.borland.com> <43e89e85$1@newsgroups.borland.com> <43e9b3ee$1@newsgroups.borland.com> <43ea0320$1@newsgroups.borland.com> <43ea18ba$1@newsgroups.borland.com> X-Newsreader: Forte Agent 3.1/32.783 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 193.129.251.253 X-Trace: newsgroups.borland.com 1139415984 193.129.251.253 (8 Feb 2006 08:26:24 -0700) Lines: 36 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!fu-berlin.de!newsfeed.cw.net!cw.net!news-FFM2.ecrc.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail