1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #define UNICODE 29 30 #ifdef _MSC_VER 31 #pragma warning(push,1) // disable warnings within system headers 32 #endif 33 #include <windows.h> 34 #ifdef _MSC_VER 35 #pragma warning(pop) 36 #endif 37 38 #include <string.h> 39 #include <malloc.h> 40 #include <stdio.h> 41 #include "strsafe.h" 42 43 #include <seterror.hxx> 44 45 //---------------------------------------------------------- 46 #ifdef DEBUG 47 inline void OutputDebugStringFormat( LPCTSTR pFormat, ... ) 48 { 49 TCHAR buffer[1024]; 50 va_list args; 51 52 va_start( args, pFormat ); 53 StringCchVPrintf( buffer, sizeof(buffer), pFormat, args ); 54 OutputDebugString( buffer ); 55 } 56 #else 57 static inline void OutputDebugStringFormat( LPCTSTR, ... ) 58 { 59 } 60 #endif 61 62 //---------------------------------------------------------- 63 void SetMsiErrorCode( int nErrorCode ) 64 { 65 const TCHAR sMemMapName[] = TEXT( "Global\\MsiErrorObject" ); 66 67 HANDLE hMapFile; 68 int *pBuf; 69 70 hMapFile = OpenFileMapping( 71 FILE_MAP_ALL_ACCESS, // read/write access 72 FALSE, // do not inherit the name 73 sMemMapName ); // name of mapping object 74 75 if ( hMapFile == NULL ) // can not set error code 76 { 77 OutputDebugStringFormat( TEXT("Could not open map file (%d).\n"), GetLastError() ); 78 return; 79 } 80 81 pBuf = (int*) MapViewOfFile( hMapFile, // handle to map object 82 FILE_MAP_ALL_ACCESS, // read/write permission 83 0, 84 0, 85 sizeof( int ) ); 86 if ( pBuf ) 87 { 88 *pBuf = nErrorCode; 89 UnmapViewOfFile( pBuf ); 90 } 91 else 92 OutputDebugStringFormat( TEXT("Could not map view of file (%d).\n"), GetLastError() ); 93 94 CloseHandle( hMapFile ); 95 } 96 97 98