SOL9 2.0 Class: SWbemQueryPropertiesLoader

 SOL9 C++ Class Library  SOL9 Samples  SOL9 Tutorial  SOL9 FAQ  SOL9 ClassTree 

Source code

/*
 * SWbemQueryPropertiesLoader.h 
 * Copyright (c) 2012 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED. 
 */


// SOL9

#pragma once

#include <sol/Exception.h>
#include <sol/wmi/SWbemQueryProperties.h>


namespace SOL {

class    SWbemQueryPropertiesLoader: public Object {

public:
    SWbemQueryPropertiesLoader()
    {

    }


public:

    bool load(__out SWbemQueryProperties& properties,
                    __in_opt const TCHAR* propertiesFile=NULL)
    {
        bool rc = false;
        TCHAR filePath[1024];
        memset(filePath, (TCHAR)0, SizeOf(filePath));

        const TCHAR* DEFAULT_PROPERTIES_FILE_NAME = _T("Query.properties"); 
        if (propertiesFile == NULL) {
            TCHAR module[_MAX_PATH];
            memset(module, (TCHAR)0, SizeOf(module));
            GetModuleFileName(NULL, module, _MAX_PATH);
            TCHAR* dot = strrchr(module, '.');
            if (dot) {
                *dot = '\0';    //NULL terminated hered
            }
            _stprintf(filePath, _T("%s.%s"), module, DEFAULT_PROPERTIES_FILE_NAME);
            
            if (GetFileAttributes(filePath) == 0xffffffff) {
                _bstr_t bstring = filePath;
                throw Exception(E_INVALIDARG, "File not found:\"%s\" %s",  (const char*)bstring, __FUNCTION__); 
            }
        } else {
            _stprintf(filePath, _T("%s"), propertiesFile);
        }
        if (GetFileAttributes(filePath) == 0xffffffff) {
            _bstr_t bstring = filePath;

            throw Exception(E_INVALIDARG, "Filenot found:\"%s\" %s",  (const char*)bstring,  __FUNCTION__); 
        } else {
            rc = properties.load(filePath);
        }
        return rc;
    }

};

}

Last modified: 1 Apr 2012

Copyright (c) 2009-2012 Antillia.com ALL RIGHTS RESERVED.