Exemple #1
0
void CATLDrawView::DisconnectSink(REFIID iid, DWORD dwCookie)
{
	if (dwCookie == 0)
		return;

	ASSERT(m_pDrawServ != NULL);

	LPCONNECTIONPOINTCONTAINER pConnPtCont;

	if ((m_pDrawServ != NULL) &&
		SUCCEEDED(m_pDrawServ->QueryInterface(IID_IConnectionPointContainer,
			(LPVOID*)&pConnPtCont)))
	{
		ATLENSURE(pConnPtCont != NULL);
		LPCONNECTIONPOINT pConnPt = NULL;

		if (SUCCEEDED(pConnPtCont->FindConnectionPoint(iid, &pConnPt)))
		{
			ATLENSURE(pConnPt != NULL);
			pConnPt->Unadvise(dwCookie);
			pConnPt->Release();
		}

		pConnPtCont->Release();
	}
}
Exemple #2
0
BOOL CATLDrawView::ConnectSink(REFIID iid, LPUNKNOWN punkSink)
{
	BOOL    bRC = FALSE;
	ASSERT(m_pDrawServ != NULL);

	LPCONNECTIONPOINTCONTAINER pConnPtCont;

	if ((m_pDrawServ != NULL) &&
		SUCCEEDED(m_pDrawServ->QueryInterface(IID_IConnectionPointContainer,
			(LPVOID*)&pConnPtCont)))
	{
		ATLENSURE(pConnPtCont != NULL);
		LPCONNECTIONPOINT pConnPt = NULL;

		HRESULT hRes = pConnPtCont->FindConnectionPoint(iid, &pConnPt);
		ASSERT(hRes == S_OK);
		if (SUCCEEDED(hRes))
		{
			ATLENSURE(pConnPt != NULL);
			hRes = pConnPt->Advise(punkSink, &m_dwDrawServ);
			if (FAILED(hRes))
			{
				TCHAR buf[32];
				wsprintf(buf, _T("%x"), hRes);
				AfxMessageBox(buf);
				return FALSE;
			}
			AfxMessageBox(_T("Connected"));
			bRC = TRUE;
			pConnPt->Release();
		}
		pConnPtCont->Release();
	}
	return bRC;
}
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;
}
Exemple #4
0
void pwerror()
{
	PWSTR msg;
	ATLENSURE(FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, nullptr, GetLastError(), 0, reinterpret_cast<PWSTR>(&msg), 0, nullptr));
	fputws(msg, stderr);
	_CrtDbgBreak();
	LocalFree(msg);
}
Exemple #5
0
// TODO: make sure ATLENSURE is a way that throws an exception
CBinRes::CBinRes( UINT nIDRes, PCTSTR type )
{
	DWORD dwSizeRes;
	HGLOBAL hResLoaded; //not a real HGLOBAL as stated in LoadResource() documentation
	HRSRC hRsrc;
	
	hRsrc = ::FindResource( ModuleHelper::GetResourceInstance(),
							MAKEINTRESOURCE(nIDRes), type );
	ATLENSURE( hRsrc );

	hResLoaded = ::LoadResource( ModuleHelper::GetResourceInstance(), hRsrc );
	dwSizeRes = ::SizeofResource( ModuleHelper::GetResourceInstance(), hRsrc );
	ATLENSURE( hResLoaded && dwSizeRes );

	m_resAdrr = ::LockResource( hResLoaded );
	m_size = dwSizeRes;
	ATLENSURE( m_resAdrr );
}
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;
}
Exemple #7
0
STDMETHODIMP CConsoleService::WriteLine(BSTR bstr)
{
	CComPtr<IFormManager> pFormManager;
	RETURN_IF_FAILED(GetFormManager(&pFormManager));

	RETURN_IF_FAILED(OpenConsole());
	CComPtr<IControl> pConsoleForm;
	RETURN_IF_FAILED(pFormManager->FindForm(CONTROL_LOG, &pConsoleForm));
	CComQIPtr<ILogFormView> pLogFormView = pConsoleForm;
	ATLENSURE(pLogFormView);
	RETURN_IF_FAILED(pLogFormView->WriteLine(bstr));
	return S_OK;
}
Exemple #8
0
STDMETHODIMP COpenDumpCommand::Invoke(REFGUID guidId)
{
	UNREFERENCED_PARAMETER(guidId);
	CFileDialog dlg(TRUE);
	if (dlg.DoModal() != IDOK)
		return HRESULT_FROM_WIN32(ERROR_CANCELLED);

	CComQIPtr<IServiceProvider> pServiceProvider = m_pControl;
	ATLASSERT(pServiceProvider);

	CWaitCursor w;

	CComPtr<IViewDebugEngineService> pViewDebugEngineService;
	RETURN_IF_FAILED(pServiceProvider->QueryService(SERVICE_VIEW_DEBUG_SESSION_SERVICE, IID_IViewDebugEngineService, (LPVOID*)&pViewDebugEngineService));
	RETURN_IF_FAILED(pViewDebugEngineService->OpenSession());

	CComPtr<IConsoleService> pConsoleService;
	RETURN_IF_FAILED(pServiceProvider->QueryService(SERVICE_CONSOLE, &pConsoleService));
	RETURN_IF_FAILED(pConsoleService->OpenConsole());

	ATLENSURE(pViewDebugEngineService);
	RETURN_IF_FAILED(pViewDebugEngineService->ExecuteCommandSimpleAsync(DBGCOMMAND_OPENDUMP, &CComVar(dlg.m_ofn.lpstrFile)));
	return S_OK;
}
Exemple #9
0
int __cdecl wmain(int argc, PWSTR argv[])
{
	setlocale(LC_ALL, "");
	for (int i = 1; i < argc; i++)
	{
		_putws(argv[i]);
		ATL::CHandle h(CreateFileW(argv[i], 0, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, 0, nullptr));
		if (h == INVALID_HANDLE_VALUE)
		{
			pwerror();
			h.Detach();
			continue;
		}
		ULONG fs_flags;
		ATLENSURE(GetVolumeInformationByHandleW(h, nullptr, 0, nullptr, nullptr, &fs_flags, nullptr, 0));
		if (!(fs_flags & FILE_SUPPORTS_BLOCK_REFCOUNTING))
		{
			SetLastError(ERROR_NOT_CAPABLE);
			pwerror();
			continue;
		}
		puts("                 VCN           Contiguous   RefCount                  LCN");
		STARTING_VCN_INPUT_BUFFER Vcn = {};
		union
		{
			RETRIEVAL_POINTERS_AND_REFCOUNT_BUFFER refcount_buf;
			BYTE buf[offsetof(RETRIEVAL_POINTERS_AND_REFCOUNT_BUFFER, Extents) + sizeof(RETRIEVAL_POINTERS_AND_REFCOUNT_BUFFER::Extents) * 128];
		};
		ULONG junk;
		for (;;)
		{
			BOOL ret = DeviceIoControl(h, FSCTL_GET_RETRIEVAL_POINTERS_AND_REFCOUNT, &Vcn, sizeof Vcn, &refcount_buf, sizeof buf, &junk, nullptr);
			ULONG err = GetLastError();
			if (ret || err == ERROR_MORE_DATA)
			{
				printf(
					"% 20llu % 20llu % 10lu % 20llu\n",
					refcount_buf.StartingVcn.QuadPart,
					refcount_buf.Extents[0].NextVcn.QuadPart - refcount_buf.StartingVcn.QuadPart,
					refcount_buf.Extents[0].ReferenceCount,
					refcount_buf.Extents[0].Lcn.QuadPart
				);
				if (refcount_buf.ExtentCount > 1)
				{
					for (ULONG j = 1; j < refcount_buf.ExtentCount; j++)
					{
						printf(
							"% 20llu % 20llu % 10lu % 20llu\n",
							refcount_buf.Extents[j - 1].NextVcn.QuadPart,
							refcount_buf.Extents[j].NextVcn.QuadPart - refcount_buf.Extents[j - 1].NextVcn.QuadPart,
							refcount_buf.Extents[j].ReferenceCount,
							refcount_buf.Extents[j].Lcn.QuadPart
						);
					}
				}
				Vcn.StartingVcn = refcount_buf.Extents[refcount_buf.ExtentCount - 1].NextVcn;
			}
			else
			{
				if (err != ERROR_HANDLE_EOF)
				{
					pwerror();
				}
				break;
			}
		}
	}
}
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;
}