1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #pragma once 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #ifdef _UWINAPI_ 31*cdf0e10cSrcweir # define _KERNEL32_ 32*cdf0e10cSrcweir # define _USER32_ 33*cdf0e10cSrcweir # define _SHELL32_ 34*cdf0e10cSrcweir #endif 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #ifndef _WINDOWS_ 37*cdf0e10cSrcweir #ifdef _MSC_VER 38*cdf0e10cSrcweir # pragma warning(push,1) /* disable warnings within system headers */ 39*cdf0e10cSrcweir #endif 40*cdf0e10cSrcweir # include <windows.h> 41*cdf0e10cSrcweir #ifdef _MSC_VER 42*cdf0e10cSrcweir # pragma warning(pop) 43*cdf0e10cSrcweir #endif 44*cdf0e10cSrcweir #endif 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #ifdef __MINGW32__ 47*cdf0e10cSrcweir #include <basetyps.h> 48*cdf0e10cSrcweir #ifdef _UWINAPI_ 49*cdf0e10cSrcweir #define WINBASEAPI 50*cdf0e10cSrcweir #endif 51*cdf0e10cSrcweir #endif 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir /** GetUserDomain 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir The GetUserDomain function retrieves the name of the NT domain the user is 56*cdf0e10cSrcweir logged in. 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir Parameters 59*cdf0e10cSrcweir @param lpBuffer 60*cdf0e10cSrcweir [out] Pointer to a buffer that receives a null-terminated string 61*cdf0e10cSrcweir containing the domain name. 62*cdf0e10cSrcweir @param nBufferSize 63*cdf0e10cSrcweir [in] Specifies the size, in TCHARs, of the buffer pointed to 64*cdf0e10cSrcweir by the lpBuffer parameter. 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir Return Values 68*cdf0e10cSrcweir @return 69*cdf0e10cSrcweir If the function succeeds, the return value is the number of TCHARs stored 70*cdf0e10cSrcweir into the buffer pointed to by lpBuffer, not including the terminating 71*cdf0e10cSrcweir null character. 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir If the domain name can't be retrieved, the return value is zero. 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir If the buffer pointed to by lpBuffer is not large enough, the return value 76*cdf0e10cSrcweir is the buffer size, in TCHARs, required to hold the value string and its 77*cdf0e10cSrcweir terminating null character. 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir Remarks 80*cdf0e10cSrcweir Windows 95/98/Me: If the user is not logged in onto a NT domain server 81*cdf0e10cSrcweir the name of the workgroup is returned. 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir Requirements 84*cdf0e10cSrcweir Windows NT/2000/XP: Included in Windows NT 4 and later. 85*cdf0e10cSrcweir Windows 95/98/Me: Included in Windows 95 and later. 86*cdf0e10cSrcweir Header: Declared in Uwinapi.h; include Uwinapi.h. 87*cdf0e10cSrcweir Library: Use Uwinapi.lib. 88*cdf0e10cSrcweir Unicode: Implemented as Unicode and ANSI versions on Windows 95/98/Me/NT/2000/XP. 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir See Also 91*cdf0e10cSrcweir @see 92*cdf0e10cSrcweir */ 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir EXTERN_C WINBASEAPI DWORD WINAPI GetUserDomainA( LPSTR lpBuffer, DWORD nBuffserSize ); 95*cdf0e10cSrcweir EXTERN_C WINBASEAPI DWORD WINAPI GetUserDomainW( LPWSTR lpBuffer, DWORD nBuffserSize ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir #ifdef UNICODE 98*cdf0e10cSrcweir #define GetUserDomain GetUserDomainW 99*cdf0e10cSrcweir #else 100*cdf0e10cSrcweir #define GetUserDomain GetUserDomainA 101*cdf0e10cSrcweir #endif 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir EXTERN_C WINBASEAPI DWORD WINAPI GetProcessId( HANDLE hProcess ); 104*cdf0e10cSrcweir 105*cdf0e10cSrcweir /* macro that calculates the count of elements of a static array */ 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir #define elementsof(buf) (sizeof(buf) / sizeof((buf)[0])) 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir #ifdef __cplusplus 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir inline bool IsValidHandle(HANDLE handle) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir return handle != INVALID_HANDLE_VALUE && handle != NULL; 114*cdf0e10cSrcweir } 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir #else /* __cplusplus */ 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir #define IsValidHandle(Handle) ((DWORD)(Handle) + 1 > 1) 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir #endif /* __cplusplus */ 121*cdf0e10cSrcweir 122