Filter Library Camera Interface Physics

GetInstallPath.cpp

00001 /*
00002  * GetInstallPath.cpp -
00003  *
00004  * Compile: cl -GX -Ox -MT GetInstallPath.cpp
00005  */
00006 
00007 // #include <afx.h>
00008 // #include <windows.h>
00009 // 
00010 // #include <stdio.h>              // for FILENAME_MAX
00011 // #include <iostream>
00012 
00013 #include "stdafx.h"                     // for common (pre-compiled) headers
00014 //#include <cfl/stdafx.h>                 // for common (pre-compiled) headers
00015 
00016 /**
00017  * obtain the Camera installation directory from the registry.
00018  */
00019 CString GetInstallPath()
00020 {
00021    const char* LPMCamera   = "Software\\LPMCamera";
00022    const char* InstallPath = "InstallPath";
00023 
00024    static unsigned char *path = NULL;
00025 
00026    /*
00027     * return cached value, if available:
00028     */
00029    if ( 0 != path )
00030    {
00031       return path;
00032    }
00033 
00034    /*
00035     * open the registry key HKCU\Software\LPMCamera:
00036     */
00037    HKEY regKey;
00038 
00039    if ( 0 != RegOpenKey(
00040       HKEY_CURRENT_USER,        // handle to open key
00041       LPMCamera,                // address of name of subkey to open
00042       &regKey                   // address of handle to open key
00043    ) )
00044    {
00045       return "[error opening registry key]";
00046    }
00047 
00048    /*
00049     * query the length of registry value InstallPath:
00050     */
00051    DWORD valType;
00052    DWORD valLength;
00053 
00054    if ( 0 != RegQueryValueEx(
00055      regKey,                    // handle to key to query
00056      InstallPath,               // address of name of subkey to open
00057      NULL,                      // reserved
00058      &valType,                  // address of buffer for value type
00059      NULL,                      // address of data buffer
00060      &valLength                 // address of data buffer size
00061    ) )
00062    {
00063       return "[error reading registry value]";
00064    }
00065 
00066    /*
00067     * allocate space; valLength includes trailing '\0':
00068     */
00069    if ( 0 == ( path = new unsigned char[ valLength ] ) )
00070    {
00071       return "[memory allocation error]";
00072    }
00073 
00074    /*
00075     * query the contents of registry value InstallPath:
00076     */
00077    if ( 0 != RegQueryValueEx(
00078      regKey,                    // handle to key to query
00079      InstallPath,               // address of name of subkey to open
00080      NULL,                      // reserved
00081      &valType,                  // address of buffer for value type
00082      (unsigned char*)path,      // address of data buffer
00083      &valLength                 // address of data buffer size
00084    ) )
00085    {
00086       return "[error reading registry value]";
00087    }
00088 
00089    /*
00090     * close the registry key:
00091     */
00092    if ( 0 != RegCloseKey(
00093      regKey                     // handle to key to close
00094    ) )
00095    {
00096       return "[error closing registry key]";
00097    }
00098 
00099    return path;
00100 }
00101 
00102 /*
00103  * end of file
00104  */
00105 

Camera Filter Library documentation © 2004-2007 by Leiden Probe Microscopy