1*32b1fd08SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*32b1fd08SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*32b1fd08SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*32b1fd08SAndrew Rist  * distributed with this work for additional information
6*32b1fd08SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*32b1fd08SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*32b1fd08SAndrew Rist  * "License"); you may not use this file except in compliance
9*32b1fd08SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*32b1fd08SAndrew Rist  *
11*32b1fd08SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*32b1fd08SAndrew Rist  *
13*32b1fd08SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*32b1fd08SAndrew Rist  * software distributed under the License is distributed on an
15*32b1fd08SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*32b1fd08SAndrew Rist  * KIND, either express or implied.  See the License for the
17*32b1fd08SAndrew Rist  * specific language governing permissions and limitations
18*32b1fd08SAndrew Rist  * under the License.
19*32b1fd08SAndrew Rist  *
20*32b1fd08SAndrew Rist  *************************************************************/
21*32b1fd08SAndrew Rist 
22*32b1fd08SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #define UNICODE
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #ifdef _MSC_VER
27cdf0e10cSrcweir #pragma warning(push,1) // disable warnings within system headers
28cdf0e10cSrcweir #endif
29cdf0e10cSrcweir #include <windows.h>
30cdf0e10cSrcweir #ifdef _MSC_VER
31cdf0e10cSrcweir #pragma warning(pop)
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <string.h>
35cdf0e10cSrcweir #include <malloc.h>
36cdf0e10cSrcweir #include <stdio.h>
37cdf0e10cSrcweir #include "strsafe.h"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <seterror.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir //----------------------------------------------------------
42cdf0e10cSrcweir #ifdef DEBUG
OutputDebugStringFormat(LPCTSTR pFormat,...)43cdf0e10cSrcweir inline void OutputDebugStringFormat( LPCTSTR pFormat, ... )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	TCHAR    buffer[1024];
46cdf0e10cSrcweir 	va_list  args;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir 	va_start( args, pFormat );
49cdf0e10cSrcweir 	StringCchVPrintf( buffer, sizeof(buffer), pFormat, args );
50cdf0e10cSrcweir 	OutputDebugString( buffer );
51cdf0e10cSrcweir }
52cdf0e10cSrcweir #else
OutputDebugStringFormat(LPCTSTR,...)53cdf0e10cSrcweir static inline void OutputDebugStringFormat( LPCTSTR, ... )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir }
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir 
58cdf0e10cSrcweir //----------------------------------------------------------
SetMsiErrorCode(int nErrorCode)59cdf0e10cSrcweir void SetMsiErrorCode( int nErrorCode )
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     const TCHAR sMemMapName[] = TEXT( "Global\\MsiErrorObject" );
62cdf0e10cSrcweir 
63cdf0e10cSrcweir     HANDLE hMapFile;
64cdf0e10cSrcweir     int *pBuf;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir     hMapFile = OpenFileMapping(
67cdf0e10cSrcweir                     FILE_MAP_ALL_ACCESS,    // read/write access
68cdf0e10cSrcweir                     FALSE,                  // do not inherit the name
69cdf0e10cSrcweir                     sMemMapName );          // name of mapping object
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     if ( hMapFile == NULL )                 // can not set error code
72cdf0e10cSrcweir     {
73cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("Could not open map file (%d).\n"), GetLastError() );
74cdf0e10cSrcweir         return;
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     pBuf = (int*) MapViewOfFile( hMapFile,   // handle to map object
78cdf0e10cSrcweir                         FILE_MAP_ALL_ACCESS, // read/write permission
79cdf0e10cSrcweir                         0,
80cdf0e10cSrcweir                         0,
81cdf0e10cSrcweir                         sizeof( int ) );
82cdf0e10cSrcweir     if ( pBuf )
83cdf0e10cSrcweir     {
84cdf0e10cSrcweir         *pBuf = nErrorCode;
85cdf0e10cSrcweir         UnmapViewOfFile( pBuf );
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir     else
88cdf0e10cSrcweir         OutputDebugStringFormat( TEXT("Could not map view of file (%d).\n"), GetLastError() );
89cdf0e10cSrcweir 
90cdf0e10cSrcweir     CloseHandle( hMapFile );
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 
94