wave-windows.cpp

Go to the documentation of this file.
00001 /*
00002  * wave-windows.cpp
00003  *
00004  * Copyright (C) 2010  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  *
00008  * Redistribution and use in source and binary forms, with or without
00009  * modification, are permitted provided that the following conditions are met:
00010  *     * Redistributions of source code must retain the above copyright
00011  *       notice, this list of conditions and the following disclaimer.
00012  *     * Redistributions in binary form must reproduce the above copyright
00013  *       notice, this list of conditions and the following disclaimer in the
00014  *       documentation and/or other materials provided with the distribution.
00015  *     * Neither the name of the <organization> nor the
00016  *       names of its contributors may be used to endorse or promote products
00017  *       derived from this software without specific prior written permission.
00018  *
00019  * THIS SOFTWARE IS PROVIDED BY THOMAS A. VAUGHAN ''AS IS'' AND ANY
00020  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00021  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00022  * DISCLAIMED. IN NO EVENT SHALL THOMAS A. VAUGHAN BE LIABLE FOR ANY
00023  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00024  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00025  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00026  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00027  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00028  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029  *
00030  *
00031  * Helpful functions for Windows APIs.  See wave-windows.h
00032  */
00033 
00034 // includes --------------------------------------------------------------------
00035 #include "wave-windows.h"               // always include our own header first!
00036 
00037 
00038 
00039 
00040 ////////////////////////////////////////////////////////////////////////////////
00041 //
00042 //      static helper methods
00043 //
00044 ////////////////////////////////////////////////////////////////////////////////
00045 
00046 
00047 ////////////////////////////////////////////////////////////////////////////////
00048 //
00049 //      public API
00050 //
00051 ////////////////////////////////////////////////////////////////////////////////
00052 
00053 #define RPC_VALUE(token) case token : DPRINTF("   ...%s", #token );
00054 
00055 
00056 void
00057 checkRpcStatus
00058 (
00059 IN RPC_STATUS rpc
00060 )
00061 {
00062         DPRINTF("Checking Windows RPC status code 0x%08x = %ld ...", rpc, rpc);
00063 
00064         switch (rpc) {
00065         RPC_VALUE(RPC_S_OK)
00066         default:
00067                 DPRINTF("  ...unrecognized RPC status code!");
00068         }
00069 }
00070 
00071 
00072 #define HR_VALUE(token) case token : DPRINTF("  ...%s", #token ); break;
00073 
00074 void
00075 checkHresult
00076 (
00077 IN HRESULT hr
00078 )
00079 {
00080         DPRINTF("Checking Windows HRESULT code 0x%08x = %ld...", hr, hr);
00081 
00082         switch (hr) {
00083         HR_VALUE(E_ACCESSDENIED)
00084         HR_VALUE(E_HANDLE)
00085         HR_VALUE(E_POINTER)
00086         HR_VALUE(S_FALSE)
00087         HR_VALUE(S_OK)
00088         default:
00089                 DPRINTF("  ...unrecognzed HRESULT code!");
00090         }
00091 }
00092 
00093 
00094 
00095 void
00096 writeGuid
00097 (
00098 IO std::ostream& stream,
00099 IN const GUID& guid
00100 )
00101 {
00102         const int bufsize = 64;
00103         char buffer[bufsize];
00104         stream << getGuidString(guid, buffer, bufsize);
00105 }
00106 
00107 
00108 const char *
00109 getGuidString
00110 (
00111 IN const GUID& guid,
00112 IO char * buffer,
00113 IN int bufsize
00114 )
00115 {
00116         ASSERT(buffer, "null");
00117         ASSERT(bufsize > 0, "bad buffer size: %d", bufsize);
00118 
00119         unsigned char * value = NULL;
00120         RPC_STATUS retval = UuidToString(&guid, &value);
00121         RPC_VERIFY(RPC_S_OK == retval && value, retval,
00122             "Failed to call UuidToString()");
00123         // DPRINTF("value = '%s'", value);
00124         strncpy(buffer, (const char *) value, bufsize);
00125         retval = RpcStringFree(&value);
00126         RPC_VERIFY(RPC_S_OK == retval, retval,
00127             "Failed to free RPC string after UuidToString call");
00128 
00129         // return string as a convenience
00130         return buffer;
00131 }