|
MKoD - D Programming Language
Win32 API GetEnvironmentStrings() example in D - code-name getenvstr.d
Win32 API GetEnvironmentStrings() example:
// getenvstr.d - last tested with D v1.0
// Example from MSDN
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/getenvironmentstrings.asp
private import std.stdio;
private import std.c.windows.windows;
// function retrieves the environment variables for the current process.
extern( Windows ) LPVOID GetEnvironmentStringsA();
// function frees a block of environment strings.
extern( Windows ) BOOL FreeEnvironmentStringsA( /* IN */ LPTSTR lpszEnvironmentBlock);
// Function retrieves the calling thread's last-error code value
extern( Windows ) uint GetLastError();
int main()
{
LPSTR lpszVariable;
LPVOID lpvEnv;
// Get a pointer to the environment block.
lpvEnv = GetEnvironmentStringsA();
// If the returned pointer is NULL, exit.
if (lpvEnv == null)
{
writefln("GetEnvironmentStrings failed (%d)", GetLastError());
return 0;
}
// Variable strings are separated by NULL byte, and the block is
// terminated by a NULL byte.
for (lpszVariable = cast(LPTSTR)lpvEnv; *lpszVariable; lpszVariable++)
{
while (*lpszVariable)
putchar(*lpszVariable++);
putchar('\n');
}
FreeEnvironmentStringsA(cast(LPTSTR)lpvEnv);
return 0;
}
C:\dmd\MKOD_ex>..\bin\dmd getenv.d
C:\dmd\bin\..\..\dm\bin\link.exe getenv,,,user32+kernel32/noi;
C:\dmd\MKOD_ex>getenv
=::=::\
=C:=C:\dmd
=ExitCode=00000000
ALLUSERSPROFILE=C:\Documents and Settings\All Users
APPDATA=C:\Documents and Settings\SPOTTE~1\Application Data
CommonProgramFiles=C:\Program Files\Common Files
COMPUTERNAME=SPOTTEDTIGER
ComSpec=C:\WINDOWS\system32\cmd.exe
EDPATH=C:\watcom\EDDAT
FINCLUDE=C:\watcom\SRC\FORTRAN
FP_NO_HOST_CHECK=NO
GMAXLOC=C:\gmax\
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\SpottedTiger
INCLUDE=C:\watcom\H;C:\watcom\H\NT
LIB=C:\Program Files\Microsoft Visual Studio\VC98\mfc\lib;
C:\Program Files\Microsoft Visual Studio\VC98\lib;
C:\Program Files\Microsoft Visual Studio .NET\FrameworkSDK\Lib\
LOGONSERVER=\\SPOTTEDTIGER
MSDevDir=C:\Program Files\Microsoft Visual Studio\Common\MSDev98
NUMBER_OF_PROCESSORS=1
OS=Windows_NT
Path=C:\DM;C:\DMD;C:\UT2004\system;C:\watcom\BINNT;C:\watcom\BINW;
C:\Program Files\Borland\BDS\1.0\Bin;
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_IDENTIFIER=x86 Family 15 Model 1 Stepping 2, GenuineIntel
PROCESSOR_LEVEL=15
PROCESSOR_REVISION=0102
ProgramFiles=C:\Program Files
PROMPT=$P$G
SESSIONNAME=Console
SystemDrive=C:
SystemRoot=C:\WINDOWS
TEMP=C:\DOCUME~1\SPOTTE~1\LOCALS~1\Temp
TMP=C:\DOCUME~1\SPOTTE~1\LOCALS~1\Temp
tvdumpflags=10
USERDOMAIN=SPOTTEDTIGER
USERNAME=SpottedTiger
USERPROFILE=C:\Documents and Settings\SpottedTiger
VJSHARPTOOLS=C:\Program Files\Microsoft Visual J# .NET\Framework\Bin;
C:\WINDOWS\Microsoft Visual JSharp .NET\Framework\v1.0.4205;
VSCOMNTOOLS="C:\Program Files\Microsoft Visual Studio .NET\Common7\Tools\"
WATCOM=C:\watcom
windir=C:\WINDOWS
C:\dmd\MKOD_ex>
|