1*9eab2a37SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9eab2a37SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9eab2a37SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9eab2a37SAndrew Rist * distributed with this work for additional information 6*9eab2a37SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9eab2a37SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9eab2a37SAndrew Rist * "License"); you may not use this file except in compliance 9*9eab2a37SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*9eab2a37SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*9eab2a37SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9eab2a37SAndrew Rist * software distributed under the License is distributed on an 15*9eab2a37SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9eab2a37SAndrew Rist * KIND, either express or implied. See the License for the 17*9eab2a37SAndrew Rist * specific language governing permissions and limitations 18*9eab2a37SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*9eab2a37SAndrew Rist *************************************************************/ 21*9eab2a37SAndrew Rist 22*9eab2a37SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #pragma once 25cdf0e10cSrcweir 26cdf0e10cSrcweir #ifdef _UWINAPI_ 27cdf0e10cSrcweir # define _KERNEL32_ 28cdf0e10cSrcweir # define _USER32_ 29cdf0e10cSrcweir # define _SHELL32_ 30cdf0e10cSrcweir #endif 31cdf0e10cSrcweir 32cdf0e10cSrcweir #ifndef _WINDOWS_ 33cdf0e10cSrcweir #ifdef _MSC_VER 34cdf0e10cSrcweir # pragma warning(push,1) /* disable warnings within system headers */ 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir # include <windows.h> 37cdf0e10cSrcweir #ifdef _MSC_VER 38cdf0e10cSrcweir # pragma warning(pop) 39cdf0e10cSrcweir #endif 40cdf0e10cSrcweir #endif 41cdf0e10cSrcweir 42cdf0e10cSrcweir #ifdef __MINGW32__ 43cdf0e10cSrcweir #include <basetyps.h> 44cdf0e10cSrcweir #ifdef _UWINAPI_ 45cdf0e10cSrcweir #define WINBASEAPI 46cdf0e10cSrcweir #endif 47cdf0e10cSrcweir #endif 48cdf0e10cSrcweir 49cdf0e10cSrcweir /** GetUserDomain 50cdf0e10cSrcweir 51cdf0e10cSrcweir The GetUserDomain function retrieves the name of the NT domain the user is 52cdf0e10cSrcweir logged in. 53cdf0e10cSrcweir 54cdf0e10cSrcweir Parameters 55cdf0e10cSrcweir @param lpBuffer 56cdf0e10cSrcweir [out] Pointer to a buffer that receives a null-terminated string 57cdf0e10cSrcweir containing the domain name. 58cdf0e10cSrcweir @param nBufferSize 59cdf0e10cSrcweir [in] Specifies the size, in TCHARs, of the buffer pointed to 60cdf0e10cSrcweir by the lpBuffer parameter. 61cdf0e10cSrcweir 62cdf0e10cSrcweir 63cdf0e10cSrcweir Return Values 64cdf0e10cSrcweir @return 65cdf0e10cSrcweir If the function succeeds, the return value is the number of TCHARs stored 66cdf0e10cSrcweir into the buffer pointed to by lpBuffer, not including the terminating 67cdf0e10cSrcweir null character. 68cdf0e10cSrcweir 69cdf0e10cSrcweir If the domain name can't be retrieved, the return value is zero. 70cdf0e10cSrcweir 71cdf0e10cSrcweir If the buffer pointed to by lpBuffer is not large enough, the return value 72cdf0e10cSrcweir is the buffer size, in TCHARs, required to hold the value string and its 73cdf0e10cSrcweir terminating null character. 74cdf0e10cSrcweir 75cdf0e10cSrcweir Remarks 76cdf0e10cSrcweir Windows 95/98/Me: If the user is not logged in onto a NT domain server 77cdf0e10cSrcweir the name of the workgroup is returned. 78cdf0e10cSrcweir 79cdf0e10cSrcweir Requirements 80cdf0e10cSrcweir Windows NT/2000/XP: Included in Windows NT 4 and later. 81cdf0e10cSrcweir Windows 95/98/Me: Included in Windows 95 and later. 82cdf0e10cSrcweir Header: Declared in Uwinapi.h; include Uwinapi.h. 83cdf0e10cSrcweir Library: Use Uwinapi.lib. 84cdf0e10cSrcweir Unicode: Implemented as Unicode and ANSI versions on Windows 95/98/Me/NT/2000/XP. 85cdf0e10cSrcweir 86cdf0e10cSrcweir See Also 87cdf0e10cSrcweir @see 88cdf0e10cSrcweir */ 89cdf0e10cSrcweir 90cdf0e10cSrcweir EXTERN_C WINBASEAPI DWORD WINAPI GetUserDomainA( LPSTR lpBuffer, DWORD nBuffserSize ); 91cdf0e10cSrcweir EXTERN_C WINBASEAPI DWORD WINAPI GetUserDomainW( LPWSTR lpBuffer, DWORD nBuffserSize ); 92cdf0e10cSrcweir 93cdf0e10cSrcweir #ifdef UNICODE 94cdf0e10cSrcweir #define GetUserDomain GetUserDomainW 95cdf0e10cSrcweir #else 96cdf0e10cSrcweir #define GetUserDomain GetUserDomainA 97cdf0e10cSrcweir #endif 98cdf0e10cSrcweir 99cdf0e10cSrcweir EXTERN_C WINBASEAPI DWORD WINAPI GetProcessId( HANDLE hProcess ); 100cdf0e10cSrcweir 101cdf0e10cSrcweir /* macro that calculates the count of elements of a static array */ 102cdf0e10cSrcweir 103cdf0e10cSrcweir #define elementsof(buf) (sizeof(buf) / sizeof((buf)[0])) 104cdf0e10cSrcweir 105cdf0e10cSrcweir #ifdef __cplusplus 106cdf0e10cSrcweir 107cdf0e10cSrcweir inline bool IsValidHandle(HANDLE handle) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir return handle != INVALID_HANDLE_VALUE && handle != NULL; 110cdf0e10cSrcweir } 111cdf0e10cSrcweir 112cdf0e10cSrcweir #else /* __cplusplus */ 113cdf0e10cSrcweir 114cdf0e10cSrcweir #define IsValidHandle(Handle) ((DWORD)(Handle) + 1 > 1) 115cdf0e10cSrcweir 116cdf0e10cSrcweir #endif /* __cplusplus */ 117cdf0e10cSrcweir 118