Ejemplo n.º 1
0
STDMETHODIMP CCoAutoRun::ReadINF(BSTR section, BSTR key, VARIANT defaultValue, BSTR* retValue)
{
	TCHAR moduleDir[MAX_PATH] = {0};
	// Get the autorun.exe's path
	ATLENSURE( ::GetModuleFileName(NULL, moduleDir, MAX_PATH) );
	::PathRemoveFileSpec(moduleDir);

	TCHAR autoRunInfPath[MAX_PATH] = {0};
	ATLENSURE_SUCCEEDED( ::StringCchCopy(autoRunInfPath, MAX_PATH, moduleDir) );
	::PathAppend(autoRunInfPath, _T("AUTORUN.INF"));

	CComVariant vDefaultValue(defaultValue);
	ATLENSURE_SUCCEEDED(vDefaultValue.ChangeType(VT_BSTR));

	// Read [HTML] HTML=...
	TCHAR value[255] = {0};
	GetPrivateProfileString(
		COLE2CT(section), COLE2CT(key), COLE2CT(vDefaultValue.bstrVal), 
		value, 255, autoRunInfPath);

	CComBSTR bstrValue(value);
	*retValue = bstrValue.Detach();

	return S_OK;
}
Ejemplo n.º 2
0
STDMETHODIMP CCoAutoRun::ShellExec(BSTR verb, BSTR program, VARIANT parameter, int* ret)
{
	CComVariant vParam(parameter);
	ATLENSURE_SUCCEEDED( vParam.ChangeType(VT_BSTR) );

	HINSTANCE sret = ::ShellExecute(
		hWndMainFrame, COLE2CT(verb), COLE2CT(program), COLE2CT(vParam.bstrVal), NULL, SW_NORMAL);
	*ret = reinterpret_cast<int>(sret);
	return S_OK;
}
bool CRemoteGraphForm::SpyDoPropertyFrameModal(IMoniker* pMoniker)
{
	ATLASSERT(pMoniker);
	_ATLTRY
	{
		CComPtr<IRunningObjectTable> pRunningObjectTable;
		ATLENSURE_SUCCEEDED(GetRunningObjectTable(0, &pRunningObjectTable));
		CComPtr<IBindCtx> pBindCtx;
		ATLENSURE_SUCCEEDED(CreateBindCtx(0, &pBindCtx));
		CComPtr<IUnknown> pUnknown;
		ATLENSURE_SUCCEEDED(pRunningObjectTable->GetObject(sel_graph.moniker, &pUnknown));
		// NOTE: Doing IDispatch::Invoke to not reference/import external TLB and be dependent from it while building
		class __declspec(uuid("6945711B-FE0F-4C54-965F-5B67969C28B7")) ISpy; // Alax.Info DirectShowSpy's ISpy
		const CComQIPtr<IDispatch, &__uuidof(ISpy)> pSpyDispatch = pUnknown;
		if(!pSpyDispatch)
			return false;
		ATLASSERT(pSpyDispatch);
		// [id(4)] HRESULT DoPropertyFrameModal([in] LONG nParentWindowHandle);
		CComVariant vParentWindowHandle((LONG) (LONG_PTR) m_hWnd);
		DISPPARAMS pParameters[1];
		ZeroMemory(pParameters, sizeof pParameters);
		pParameters[0].cArgs = 1;
		pParameters[0].rgvarg = &vParentWindowHandle;
		CComVariant vResult;
		// NOTE: https://support.microsoft.com/kb/248019/en?wa=wsignin1.0
		AfxOleGetMessageFilter()->EnableNotRespondingDialog(FALSE);
		const HRESULT nResult = pSpyDispatch->Invoke(4, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, pParameters, &vResult, NULL, NULL);
		AfxOleGetMessageFilter()->EnableNotRespondingDialog(TRUE);
		ATLENSURE_SUCCEEDED(nResult);
	}
	_ATLCATCHALL()
	{
		MessageBeep(MB_ICONERROR);
		return false;
	}
	return true;
}
Ejemplo n.º 4
0
LRESULT CMainFrame::OnCreate(LPCREATESTRUCT lpcs)
{
	hWndMainFrame = this->m_hWnd;

	TCHAR moduleDir[MAX_PATH] = {0};
	TCHAR fileurl[MAX_PATH] = _T("file://");
	LPTSTR pathpart = fileurl + ::lstrlen(fileurl);
	DWORD pathpartlen = MAX_PATH - ::lstrlen(fileurl);

	// Get the autorun.exe's path
	ATLENSURE( ::GetModuleFileName(NULL, moduleDir, MAX_PATH) );
	::PathRemoveFileSpec(moduleDir);

	TCHAR autoRunInfPath[MAX_PATH] = {0};
	ATLENSURE_SUCCEEDED( ::StringCchCopy(autoRunInfPath, MAX_PATH, moduleDir) );
	::PathAppend(autoRunInfPath, _T("AUTORUN.INF"));

	// Read [HTML] HTML=...
	TCHAR home[MAX_PATH] = {0};
	GetPrivateProfileString(_T("HTML"), _T("HOME"), _T(""),  home, MAX_PATH, autoRunInfPath);
	if (::lstrlen(home) == 0)
	{
		PostMessage(WM_CLOSE);
		::ShellExecute(NULL, _T("open"), _T("."), NULL, NULL, SW_SHOW);
		return TRUE;
	}


	LPCTSTR url = _T("");
	if (home[0] == _T('r') && 
		home[1] == _T('e') && 
		home[2] == _T('s') && 
		home[3] == _T(':') &&
		home[4] == _T('/') &&
		home[5] == _T('/'))
	{
		url = home;
	}
	else
	{
		::StringCchCopy(pathpart, pathpartlen, moduleDir);
		::PathAppend(pathpart, home);
		url = fileurl;
	}

	//TODO: Replace with a URL of your choice
	m_hWndClient = m_view.Create(
		m_hWnd, 
		rcDefault, 
		_T(""), 
		WS_BORDER | WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 
		0,
		0U, 
		const_cast<LPTSTR>(url));

	// register object for message filtering and idle updates
	CMessageLoop* pLoop = _Module.GetMessageLoop();
	ATLASSERT(pLoop != NULL);
	pLoop->AddMessageFilter(this);
	pLoop->AddIdleHandler(this);

	int width = GetPrivateProfileInt(_T("HTML"), _T("WIDTH"), 600, autoRunInfPath);
	int height = GetPrivateProfileInt(_T("HTML"), _T("HEIGHT"), 450, autoRunInfPath);

	if (width < 1) width = 600;
	if (height < 1) height = 450;

	ResizeClient(width, height);

	CenterWindow();

	return 0;
}