Beispiel #1
0
/**  Open link object
 *
 *	 @param[in] lpszPath path to .lnk file
 *
 *   @returns pointer to @b IShellLink interface of link object on success,
 *		      else NULL.
 */
HRESULT CFileIterator::OpenLink(LPCTSTR	lpszPath, IShellLink** ppiLink) const
{
	HRESULT hr = CoCreateInstance(CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, 
                            IID_IShellLink, (LPVOID*)ppiLink);
	if (SUCCEEDED(hr))
	{
		BOOL bLoaded = FALSE;
		// try loading this file - it'll fail if it's not a .lnk, right?
		IPersistFile* piFile;
		hr = (*ppiLink)->QueryInterface(IID_IPersistFile, (void**) &piFile);
        if (SUCCEEDED(hr))
		{
			_bstr_t	bstrPath(lpszPath);
			hr = piFile->Load(bstrPath, 0);
			piFile->Release();
		}
		if (FAILED(hr))
		{
			// couldn't load this file, so return NULL
			(*ppiLink)->Release();
			*ppiLink = NULL;
		}

	}

	return hr;
}
STDMETHODIMP CCoAutoRun::get_AutoRunPath(BSTR* path)
{
	TCHAR moduleDir[MAX_PATH] = {0};
	// Get the autorun.exe's path
	ATLENSURE( ::GetModuleFileName(NULL, moduleDir, MAX_PATH) );
	::PathRemoveFileSpec(moduleDir);

	CComBSTR bstrPath(moduleDir);
	*path = bstrPath.Detach();
	return S_OK;
}
/**
 * Public method implementation.
 * @param
 * @return
 */
STDMETHODIMP VFSExplorer::COMGETTER(Path)(BSTR *aPath)
{
    if (!aPath)
        return E_POINTER;

    AutoCaller autoCaller(this);
    if (FAILED(autoCaller.rc())) return autoCaller.rc();

    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);

    Bstr bstrPath(m->strPath);
    bstrPath.cloneTo(aPath);

    return S_OK;
}
Beispiel #4
0
void Connection::open(const tstring& host, const tstring& login, const tstring& password, const tstring& nmspace)
{
	ASSERT(!isOpen());

	// Format the full connection path.
	tstring path = host + nmspace;

	if (path.compare(0, 2, TXT("\\\\")) != 0)
		path = TXT("\\\\") + path;

	// Create the connection.
	IWbemServicesPtr	services;
	IWbemLocatorPtr		locator(CLSID_WbemLocator);
	WCL::ComStr			bstrPath(path);
	WCL::ComStr			bstrAuth(TXT(""));
	HRESULT				result;

	if (login.empty())
	{
		result = locator->ConnectServer(bstrPath.Get(), nullptr, nullptr, nullptr, 0,
										bstrAuth.Get(), nullptr, AttachTo(services));
	}
	else
	{
		WCL::ComStr	bstrLogin(login);
		WCL::ComStr	bstrPassword(password);

		result = locator->ConnectServer(bstrPath.Get(), bstrLogin.Get(), bstrPassword.Get(), nullptr, 0,
										bstrAuth.Get(), nullptr, AttachTo(services));
	}

	if (FAILED(result))
		throw Exception(result, locator, Core::fmt(TXT("Failed to connect to the WMI provider on '%s'"), host.c_str()).c_str());

	// Enable impersonation on the connection.
    result = ::CoSetProxyBlanket(services.get(), RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_DEFAULT, nullptr,
									RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE,
									nullptr, EOAC_NONE);

	if (FAILED(result))
		throw Exception(result, locator, TXT("Failed to enable impersonation on the WMI connection"));

	// Update state.
	m_locator  = locator;
	m_services = services;
}
Beispiel #5
0
/*
	Function name	: CXML::GetNodesList
	Description	    : retrieves the list of nodes with the given name
	Return type		: bool 
	Argument        : CString csPathToNode
	Argument        : bool bCurrentNodeAsBase
*/
bool CXML::GetNodesList(CString csPathToNode,bool bCurrentNodeAsBase)
{
	CString csPath;
	IXMLDOMNode *pBaseNode = NULL;
	
	if(bCurrentNodeAsBase)
	{
		if(!m_pICurrentNode) return false;

		pBaseNode = m_pICurrentNode;
		pBaseNode->AddRef();
		csPath.Format("./%s",csPathToNode);
	}
	else
	{
		if(!m_pIRootNode) return false;
		pBaseNode = m_pIRootNode;
		pBaseNode->AddRef();
		csPath.Format("/%s",csPathToNode);
	}

	_bstr_t bstrPath(csPath);

	if(m_pNodeList)
	{
		m_pNodeList->Release();
		m_pNodeList = NULL;
	}

	m_hr = pBaseNode->selectNodes(bstrPath,&m_pNodeList);
	pBaseNode->Release();
	if(!SUCCEEDED(m_hr) || !m_pNodeList)
		return false;

	return true;
}
Beispiel #6
0
HRESULT 
AsdkSheetSet::create(char* name,		
					 char* path,		
					 char* description,
					 char* templPath,
					 char* defSheetLoc)
{
	BOOL  bAlwaysCreate = TRUE;
	CComBSTR bstrSSName(name);	 // Sheet set name
	HRESULT hr;
	
	// If sheet set manager doesnt exist, create one
	if(!m_pSSetMgr.p)
	{
		if (FAILED(m_pSSetMgr.CoCreateInstance(CLSID_AcSmSheetSetMgr)))
		{
			acutPrintf("\n Error Cannot get sheet set manager!!");	
			return E_FAIL;
		}
	}
	 
	char fullPath[255];
	strcpy(fullPath, path);

	// If no trailing backslash entered, add it
	if (strcmp("\\" , &fullPath[strlen(fullPath)-1]) != 0)
		strcat(fullPath, "\\");

	// check if folder exists
	if(_access(fullPath,0))
	{
		acutPrintf("\n Error: Folder does not exist. Specify another folder!!!");
		return E_FAIL;
	}

	if(!strstr(name,".dst"))
		strcat(name, ".dst");	

	strcat(fullPath, name);
	
	CComBSTR bstrPath(fullPath);
	AcSmLockStatus lockStatus;
	
	// check if file exists 
	// If so, ask the user whether to overwrite or open existing
	if(!_access(fullPath,0))
	{
	   if(!getYorN("\n File exists!! Overwrite existing?"))
	   {
	    	// Don't overwrite existing
			// Just open the file
			// 2nd parameter = FALSE means don't fail if already open
			if(FAILED(m_pSSetMgr->OpenDatabase(bstrPath, FALSE, &m_pDb)))
			{
				acutPrintf("\n Error: Cannot open database!!");
				return E_FAIL;
			}
			
			// get the sheet set from the database.
			if (FAILED(m_pDb->GetSheetSet(&m_pSheetSet)))
			{  
				acutPrintf("\n Error: Cannot get sheet set");
				return E_FAIL;
			}
			
			return E_ABORT;
		}
	}  
	
	// create the database for the sheet set
	// bAlwaysCreate lets you override the existing file if it's set to true
	if (FAILED(hr = m_pSSetMgr->CreateDatabase(bstrPath, NULL, bAlwaysCreate, &m_pDb)))
	{
		acutPrintf("\nError: Cannot create database!");
		if (E_INVALIDARG == hr)
			acutPrintf("\n File name invalid!");		
		return E_FAIL;
	}

	
	 // lock the the database first before doing any operation on it
    if (FAILED(LockDatabase()))
	{
		acutPrintf("\n Error: Database lock failed!");
        return E_FAIL;
	}

	CComBSTR bstrDesc(description);
	
	// set the sheet set db name, description = sheet set name, description
	 if (FAILED(m_pDb->SetName(bstrSSName)))
	 {
		acutPrintf("\n Error: Cannot set database name");
		return E_FAIL;
	 }
	 
	 if (FAILED(m_pDb->SetDesc(bstrDesc)))
	 {
		acutPrintf("\nError: Cannot set database description!");
		return E_FAIL;
	 }
	
	    // get the sheet set from the database.
    if (FAILED(m_pDb->GetSheetSet(&m_pSheetSet)))
	{  
		acutPrintf("\n Error: Cannot get sheet set");
        return E_FAIL;
	}

	// set the name and description to the sheet set
	if (FAILED(m_pSheetSet->SetName(bstrSSName)))
	{
		acutPrintf("\nError: Cannot set name!");
        return E_FAIL;
	}


    if (FAILED(m_pSheetSet->SetDesc(bstrDesc)))
	{
		acutPrintf("\nError: Cannot set description!");
        return E_FAIL;
	}

	if(isValid(templPath))
	{
		// set default template for layout at sheet set level
		overrideDefaultDWTLayout(templPath, m_pSheetSet);
	}

	if(isValid(defSheetLoc))
	{
		// set default sheet location
		setNewSheetLocation(defSheetLoc, m_pSheetSet);
	}

	if (FAILED(UnlockDatabase())) 
	{
		acutPrintf("\n Cannot unlock database");
        return E_FAIL;
	}
    else
		acutPrintf("\n Sheet set %s created", fullPath);
	
	return S_OK;

}
// CConnect
STDMETHODIMP CConnect::OnConnection(IDispatch *pApplication, AddInDesignerObjects::ext_ConnectMode /*ConnectMode*/, IDispatch *pAddInInst, SAFEARRAY ** /*custom*/)
{
	char BERTXLL[32] = "";
	
	char RBin[MAX_PATH];
	char Home[MAX_PATH];

	char Install[MAX_PATH];
	char XLLPath[MAX_PATH];

	if (!CRegistryUtils::GetRegExpandString(HKEY_CURRENT_USER, RBin, MAX_PATH - 1, REGISTRY_KEY, REGISTRY_VALUE_R_HOME, true))
		ExpandEnvironmentStringsA(DEFAULT_R_HOME, RBin, MAX_PATH - 1);

	if (!CRegistryUtils::GetRegExpandString(HKEY_CURRENT_USER, Home, MAX_PATH - 1, REGISTRY_KEY, REGISTRY_VALUE_R_USER, true))
		ExpandEnvironmentStringsA(DEFAULT_R_USER, Home, MAX_PATH - 1);

	if (!CRegistryUtils::GetRegString(HKEY_CURRENT_USER, Install, MAX_PATH - 1, REGISTRY_KEY, REGISTRY_VALUE_INSTALL_DIR))
		sprintf_s(Install, MAX_PATH, "");

	int len = strlen(RBin);
	if (len > 0)
	{
		if (RBin[len - 1] != '\\') strcat_s(RBin, MAX_PATH - 1, "\\");
	}

	// DERP

#ifdef _WIN64
	strcat_s(RBin, MAX_PATH, "bin\\x64;");
#else
	strcat_s(RBin, MAX_PATH, "bin\\i386;");
#endif

	// set path

	int elen = ::GetEnvironmentVariableA("PATH", 0, 0);
	int blen = strlen(RBin);

	char *buffer = new char[blen + elen + 1];
	strcpy_s(buffer, blen + elen + 1, RBin);
	if (elen > 0)
	{
		::GetEnvironmentVariableA("PATH", &(buffer[blen]), elen);
	}

	::SetEnvironmentVariableA("PATH", buffer);
	::SetEnvironmentVariableA("HOME", Home);

	delete[] buffer;

	// load xll

#ifdef _DEBUG 
#ifdef _WIN64
	sprintf_s(BERTXLL, 32, "BERT64D.xll");
#else
	sprintf_s(BERTXLL, 32, "BERT32D.xll");
#endif
#else
#ifdef _WIN64
	sprintf_s(BERTXLL, 32, "BERT64.xll");
#else
	sprintf_s(BERTXLL, 32, "BERT32.xll");
#endif
#endif

	pApplication->QueryInterface(__uuidof(IDispatch), (LPVOID*)&m_pApplication);
	pAddInInst->QueryInterface(__uuidof(IDispatch), (LPVOID*)&m_pAddInInstance);

	::PathAddBackslashA(Install);
	::PathCombineA(XLLPath, Install, BERTXLL);

	CComQIPtr<Excel::_Application> app = m_pApplication;
	if (app){

		int rslt = SetCOMPtrs((void*)m_pApplication.p, (void*)this);
		if (!rslt){
			ATLTRACE("Already registered\n");
		}
		else if (rslt && strlen(XLLPath))
		{
			_bstr_t bstrPath(XLLPath);
			VARIANT_BOOL vb = VARIANT_FALSE;
			HRESULT hr = app->RegisterXLL(bstrPath, 1033, &vb);
			if (SUCCEEDED(hr)){
				if (vb) {
					SetCOMPtrs((void*)m_pApplication.p, (void*)this);
					// ATLTRACE("Loaded xll OK");
				}
				else {
					// ATLTRACE("Succeeded but load returned false\n");
				}
			}
			else {
				// ATLTRACE("Failed with 0x%x\n", hr);
			}
		}
	}

	return S_OK;
}