bool CSelectCoordSysActionDlg::PrepareResult()
{
// Selektierten Eintrag holen
HTREEITEM hItem = m_tvCoordSystems.GetSelectedItem();

	if (NULL == hItem || m_tvCoordSystems.ItemHasChildren (hItem)) 
		return false;		// nur Childs behandeln

CCoordSystemItem *pItemData = (CCoordSystemItem *)m_tvCoordSystems.GetItemData (hItem);

	if (NULL == pItemData) 
		return false;

// Koordinatensystem am Parent setzen
CString strTcfName = pItemData->GetTcfName();

	COM_TRY {
	CComQIPtr<ITRiASCS, &IID_ITRiASCS> CS;

		THROW_FAILED_HRESULT(CS.CoCreateInstance(CLSID_TRIASCS));
		THROW_FAILED_HRESULT(CS -> LoadFromFile(CComBSTR(strTcfName)));

		m_CS = CS;		// store result coordsystem

	} COM_CATCH_OP_RETURN(CantLoadCS(strTcfName), false);
	return true;
}
Example #2
0
void GenericDocument::elementDone(IDOMElement* element)
{
	BSTR btagName;
	element->get_tagName(&btagName);
	_bstr_t tagName = _bstr_t(btagName);
	if (!wcsicmp(tagName, L"style"))
	{
		CComQIPtr<IDOMNode> child;
		element->get_firstChild(&child);

		CComQIPtr<IDOMText> text = child;
		if (text)
		{
			BSTR btextdata;
			text->get_data(&btextdata);
			_bstr_t textdata = _bstr_t(btextdata, false);

			CComQIPtr<IDOMCSSStyleSheet> stylesheet;
			stylesheet.CoCreateInstance(CLSID_DOMCSSStyleSheet);

			CComQIPtr<IDocumentStyle> documentStyle = GetControllingUnknown();
			if (documentStyle)
			{
				CComQIPtr<IStyleSheetList> stylesheetList;
				documentStyle->get_styleSheets(&stylesheetList);

				stylesheetList->append(stylesheet);

				CComQIPtr<IHTMLStyleSheet> htmlstylesheet = stylesheet;
				htmlstylesheet->set_cssText(textdata);	// The stylesheet will parse the text
			}
		}
	}
}
Example #3
0
static 
HRESULT EnableActiveDesktop(bool enable)
{
	CoInitialize(NULL);
	CComQIPtr<IActiveDesktop, &IID_IActiveDesktop>	pIActiveDesktop;
	
	HRESULT		hr;

	hr = pIActiveDesktop.CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER);
	if (!SUCCEEDED(hr))
		return hr;

	COMPONENTSOPT	opt;

	opt.dwSize = sizeof(opt);
	opt.fActiveDesktop = opt.fEnableComponents = enable;
    hr = pIActiveDesktop->SetDesktopItemOptions(&opt, 0);
    if (!SUCCEEDED(hr))
	{
		CoUninitialize();
		return hr;
	}

	hr = pIActiveDesktop->ApplyChanges(AD_APPLY_REFRESH);
	CoUninitialize();
	return hr;
}
Example #4
0
STDMETHODIMP CWebSite::ShowViews()
{
	CComQIPtr<IWebEditorFrame> frame;
	gApp->get_frame(&frame);

	CComQIPtr<IUIContextManager> uiManager;
	gApp->get_uiManager(&uiManager);

	{
		CComQIPtr<IUIMDIChild> child;
		child.CoCreateInstance(CLSID_UIMDIChild);

		// Files
		{
			CComQIPtr<ISiteFilesView> filesView;
			filesView.CoCreateInstance(CLSID_SiteFilesView);
			filesView->Create(uiManager, L"Files", (IID*)&CLSID_SiteFilesView, NULL);
			filesView->put_webSiteDocument(this);
			child->AddView(filesView, NULL);
		}

		// Links
		{
			CComQIPtr<ISiteLinksView> linksView;
			linksView.CoCreateInstance(CLSID_SiteLinksView);
			linksView->Create(uiManager, L"Links", (IID*)&CLSID_SiteFilesView, NULL);
			linksView->put_document(this);
			child->AddView(linksView, NULL);
		}

		// FTP
		{
			CComQIPtr<ISiteFTPView> ftpView;
			ftpView.CoCreateInstance(CLSID_SiteFTPView);
			ftpView->Create(uiManager, L"FTP", (IID*)&CLSID_SiteFilesView, NULL);
			ftpView->put_document(this);
			child->AddView(ftpView, NULL);
		}

		child->CreateMDIChild(frame, NULL);
		child.Detach();	// Keep it open
	}

	return S_OK;
}
Example #5
0
void CUse3Dlg::OnBnClickedButton6()		// 智能指针的释放
{
	::CoInitialize( NULL );		// 如果在这里进行 COM 初始化,要注意智能指针的释放

	CComQIPtr < IFun, &IID_IFun > spFun;

	HRESULT hr = spFun.CoCreateInstance( CLSID_Fun );
	ASSERT( SUCCEEDED( hr ) );
	// 为了简单起见,不再使用 if 判断 HRESULT 了。IFun::Add() 也没有调用

	CComBSTR s1( "Hello" ), s2( " world" ), s3;
	hr = spFun->Cat( s1, s2, &s3 );
	ASSERT( SUCCEEDED( hr ) );
	CString sMsg( s3 );
	AfxMessageBox( sMsg );

//	spFun->Release();	// 大错特错!!!
	spFun.Release();	// 正解

	::CoUninitialize();
}
Example #6
0
LRESULT CSQLTableWnd::OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
	POINT point;
	point.x = (short)LOWORD(lParam);
	point.y = (short)HIWORD(lParam);

	if (!(wParam & MK_SHIFT))
	{
		for (int i = 0; i < m_columns.GetSize(); i++)
		{
			m_columns[i]->m_bSelected = false;
		}
	}

	long index = point.y/16;

	if (index >= 0 && index < m_table->Columns->Count)
	{
		m_columns[index]->m_bSelected = true;

		Invalidate();
		UpdateWindow();

		CComQIPtr<ILDOMDocument> document;
		document.CoCreateInstance(CLSID_LDOMDocument);

		VARIANT_BOOL success;
		document->loadXML(L"<columns/>", &success);

		CComQIPtr<ILDOMElement> documentElement;
		document->get_documentElement(&documentElement);

		documentElement->setAttribute(L"fromtable", m_table->Name);

		for (long i = 0; i < m_columns.GetSize(); i++)
		{
			if (m_columns[i]->m_bSelected)
			{
				CComQIPtr<ILDOMElement> element;
				document->createElement(L"column", &element);
				element->setAttribute(L"name", m_table->Columns->Item[_variant_t(index)]->Name);
				documentElement->appendChild(element, NULL);
			}
		}

		BSTR text;
		document->saveXML(NULL, &text);
		int len = SysStringLen(text);

		HGLOBAL hData = GlobalAlloc(GMEM_MOVEABLE, (len+1)*2);

		if (hData)
		{
			WCHAR* p = (WCHAR*)GlobalLock(hData);
			CopyMemory(p, text, (len+1)*2);
			GlobalUnlock(hData);

			CMyDropSource*  dropSource = new CMyDropSource;
			CMyDataObject* dataObject = new CMyDataObject;

			STGMEDIUM	stg = {0};
			stg.tymed = TYMED_HGLOBAL;
			stg.hGlobal = hData;
			stg.pUnkForRelease = NULL;
			
			FORMATETC	etc = {0};
			etc.cfFormat = CF_UNICODETEXT;//CF_UNICODETEXT;//49285;//RegisterClipboardFormat(CFSTR_SHELLURL);//CF_TEXT;
			etc.tymed = TYMED_HGLOBAL;
			etc.ptd = NULL;
			etc.dwAspect = DVASPECT_CONTENT;
			etc.lindex = -1;

			dataObject->SetData(&etc, &stg, TRUE);

			DWORD dropEffect = 0;
			HRESULT hr = ::DoDragDrop(dataObject, dropSource, DROPEFFECT_LINK | DROPEFFECT_COPY | DROPEFFECT_MOVE, &dropEffect);

			if (hr == DRAGDROP_S_DROP)
			{
				if (dropEffect/* & DROPEFFECT_MOVE*/)
				{
				}
			}

			GlobalFree(hData);

		//	delete dataObject;
		//	delete dropSource;

#if 0
			COleDataSource source;
			source.CacheGlobalData(CF_HDROP, hData, NULL);

			if (source.DoDragDrop(DROPEFFECT_COPY | DROPEFFECT_MOVE, NULL, NULL) == DROPEFFECT_COPY)
			{
			}

			source.Empty();
#endif
		}

		SysFreeString(text);
	}
	else
	{
		Invalidate();
	}

	return 0;
}
Example #7
0
BOOL CSaveDlg::OnInitDialog()
{
	CCmdUIDialog::OnInitDialog();

	//m_anim.Open(IDR_AVI_FILECOPY);
	//m_anim.Play(0, -1, -1);

	CString str, in = m_in, out = m_out;
	if(in.GetLength() > 60) in = in.Left(17) + _T("..") + in.Right(43);
	if(out.GetLength() > 60) out = out.Left(17) + _T("..") + out.Right(43);
	str.Format(_T("%s\r\n%s"), in, out);
	m_fromto.SetWindowText(str);

	m_progress.SetRange(0, 100);

	if(FAILED(pGB.CoCreateInstance(CLSID_FilterGraph)) || !(pMC = pGB) || !(pME = pGB) || !(pMS = pGB)
	|| FAILED(pME->SetNotifyWindow((OAHWND)m_hWnd, WM_GRAPHNOTIFY, 0)))
	{
		m_report.SetWindowText(_T("Error"));
		return FALSE;
	}

	HRESULT hr;

	CStringW fnw = m_in;
	CComPtr<IFileSourceFilter> pReader;

	if(!pReader && m_in.Mid(m_in.ReverseFind('.')+1).MakeLower() == _T("cda"))
	{
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)new CCDDAReader(NULL, &hr);
		if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
			pReader.Release();
	}

	if(!pReader)
	{
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)new CCDXAReader(NULL, &hr);
		if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
			pReader.Release();
	}

	if(!pReader /*&& ext == _T("ifo")*/)
	{
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)new CVTSReader(NULL, &hr);
		if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
			pReader.Release();
		else
		{
			CPath pout(m_out);
			pout.RenameExtension(_T(".ifo"));
			CopyFile(m_in, pout, FALSE);
		}
	}

	if(!pReader)
	{
		hr = S_OK;
		CComPtr<IUnknown> pUnk;
		pUnk.CoCreateInstance(CLSID_AsyncReader);
		if(FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL)))
			pReader.Release();
	}

	if(!pReader)
	{
		hr = S_OK;
		CComPtr<IUnknown> pUnk;
		pUnk.CoCreateInstance(CLSID_URLReader);
		if(CComQIPtr<IBaseFilter> pSrc = pUnk) // url reader has to be in the graph to load the file
		{
			pGB->AddFilter(pSrc, fnw);
			if(FAILED(hr) || !(pReader = pUnk) || FAILED(hr = pReader->Load(fnw, NULL)))
			{
				pReader.Release();
				pGB->RemoveFilter(pSrc);
			}
		}
	}

	CComQIPtr<IBaseFilter> pSrc = pReader;
	if(FAILED(pGB->AddFilter(pSrc, fnw)))
	{
		m_report.SetWindowText(_T("Sorry, can't save this file, press cancel"));
		return FALSE;
	}

	CComQIPtr<IBaseFilter> pMid = new CStreamDriveThruFilter(NULL, &hr);
	if(FAILED(pGB->AddFilter(pMid, L"StreamDriveThru")))
	{
		m_report.SetWindowText(_T("Error"));
		return FALSE;
	}

	CComQIPtr<IBaseFilter> pDst;
	pDst.CoCreateInstance(CLSID_FileWriter);
	CComQIPtr<IFileSinkFilter2> pFSF = pDst;
	pFSF->SetFileName(CStringW(m_out), NULL);
	pFSF->SetMode(AM_FILE_OVERWRITE);
	if(FAILED(pGB->AddFilter(pDst, L"File Writer")))
	{
		m_report.SetWindowText(_T("Error"));
		return FALSE;
	}

	hr = pGB->Connect(
		GetFirstPin((pSrc), PINDIR_OUTPUT), 
		GetFirstPin((pMid), PINDIR_INPUT));

	hr = pGB->Connect(
		GetFirstPin((pMid), PINDIR_OUTPUT), 
		GetFirstPin((pDst), PINDIR_INPUT));

pMS = pMid;

	pMC->Run();

	m_nIDTimerEvent = SetTimer(1, 1000, NULL);

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL CSaveDlg::OnInitDialog()
{
	CCmdUIDialog::OnInitDialog();

	AppSettings& s = AfxGetAppSettings();

	CString str, in = m_name, out = m_out;

	if (m_in.Find(_T("http://")) != -1 || m_in.Find(_T("ftp://")) != -1) {
		m_anim.SendMessage(ACM_OPEN, (WPARAM)AfxGetInstanceHandle(), (LPARAM)IDR_AVI_WEB_FILECOPY);
	} else {
		m_anim.SendMessage(ACM_OPEN, (WPARAM)AfxGetInstanceHandle(), (LPARAM)IDR_AVI_FILECOPY);
	}
	m_anim.Play(0, (UINT)-1, (UINT)-1);

	if (in.GetLength() > 60) {
		in = in.Left(17) + _T("..") + in.Right(43);
	}

	if (out.GetLength() > 60) {
		out = out.Left(17) + _T("..") + out.Right(43);
	}

	str.Format(_T("%s\r\n%s"), in, out);
	m_fromto.SetWindowText(str);

	m_progress.SetRange(0, 100);

	if (OpenImageCheck(m_in) && s.strSnapShotExt != _T(".*")) {
		OpenImageDIB(m_in, m_out, s.iThumbQuality, 0);
		EndDialog(IDOK);
		return TRUE;
	}

	if (FAILED(pGB.CoCreateInstance(CLSID_FilterGraph)) || !(pMC = pGB) || !(pME = pGB) || !(pMS = pGB)
			|| FAILED(pME->SetNotifyWindow((OAHWND)m_hWnd, WM_GRAPHNOTIFY, 0))) {
		m_report.SetWindowText(_T("Error"));
		return FALSE;
	}

	HRESULT hr;

	CStringW fnw = m_in;
	CComPtr<IFileSourceFilter> pReader;

	if (!pReader && m_in.Mid(m_in.ReverseFind('.')+1).MakeLower() == _T("cda")) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)DNew CCDDAReader(NULL, &hr);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		}
	}

	if (!pReader) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)DNew CCDXAReader(NULL, &hr);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		}
	}

	if (!pReader /*&& ext == _T("ifo")*/) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)DNew CVTSReader(NULL, &hr);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		} else {
			CPath pout(m_out);
			pout.RenameExtension(_T(".ifo"));
			CopyFile(m_in, pout, FALSE);
		}
	}

	if (!pReader) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk;
		hr = pUnk.CoCreateInstance(CLSID_AsyncReader);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		}
	}

	if (!pReader) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk;
		hr = pUnk.CoCreateInstance(CLSID_URLReader);

		if (CComQIPtr<IBaseFilter> pSrc = pUnk) {
			hr = pGB->AddFilter(pSrc, fnw);

			if (FAILED(hr) || !(pReader = pUnk) || FAILED(hr = pReader->Load(fnw, NULL))) {
				pReader.Release();
				pGB->RemoveFilter(pSrc);
			}
		}
	}

	CComQIPtr<IBaseFilter> pSrc = pReader;

	if (FAILED(pGB->AddFilter(pSrc, fnw))) {
		m_report.SetWindowText(_T("Sorry, can't save this file, press cancel"));

		return FALSE;
	}

	CComQIPtr<IBaseFilter> pMid = DNew CStreamDriveThruFilter(NULL, &hr);

	if (FAILED(pGB->AddFilter(pMid, L"StreamDriveThru"))) {
		m_report.SetWindowText(_T("Error"));

		return FALSE;
	}

	CComQIPtr<IBaseFilter> pDst;
	pDst.CoCreateInstance(CLSID_FileWriter);
	CComQIPtr<IFileSinkFilter2> pFSF = pDst;
	pFSF->SetFileName(CStringW(m_out), NULL);
	pFSF->SetMode(AM_FILE_OVERWRITE);

	if (FAILED(pGB->AddFilter(pDst, L"File Writer"))) {
		m_report.SetWindowText(_T("Error"));

		return FALSE;
	}

	hr = pGB->Connect(
			 GetFirstPin((pSrc), PINDIR_OUTPUT),
			 GetFirstPin((pMid), PINDIR_INPUT));

	if (FAILED(hr)) {
		m_report.SetWindowText(_T("Error Connect pSrc / pMid"));
		return FALSE;
	}

	hr = pGB->Connect(
			 GetFirstPin((pMid), PINDIR_OUTPUT),
			 GetFirstPin((pDst), PINDIR_INPUT));
	if (FAILED(hr)) {
		m_report.SetWindowText(_T("Error Connect pMid / pDst"));
		return FALSE;
	}

	pMS = pMid;

	pMC->Run();

	m_nIDTimerEvent = SetTimer(1, 500, NULL);

	return TRUE;
}
HRESULT CSaveTaskDlg::InitFileCopy()
{
	AppSettings& s = AfxGetAppSettings();

	if (OpenImageCheck(m_in) && s.strSnapShotExt != _T(".*")) {
		OpenImageDIB(m_in, m_out, s.iThumbQuality, 0);
		return S_OK;
	}

	if (FAILED(pGB.CoCreateInstance(CLSID_FilterGraph)) || !(pMC = pGB) || !(pME = pGB) || !(pMS = pGB)) {
		SetFooterIcon(MAKEINTRESOURCE(IDI_ERROR));
		SetFooterText(ResStr(IDS_AG_ERROR));
		return S_FALSE;
	}

	HRESULT hr;

	CStringW fnw = m_in;
	CComPtr<IFileSourceFilter> pReader;

	if (!pReader && m_in.Mid(m_in.ReverseFind('.')+1).MakeLower() == _T("cda")) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)DNew CCDDAReader(NULL, &hr);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		}
	}

	if (!pReader) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)DNew CCDXAReader(NULL, &hr);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		}
	}

	if (!pReader ) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk = (IUnknown*)(INonDelegatingUnknown*)DNew CVTSReader(NULL, &hr);

		if (FAILED(hr) || !(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		} else {
			CPath pout(m_out);
			pout.RenameExtension(_T(".ifo"));
			CopyFile(m_in, pout, FALSE);
		}
	}

	if (!pReader) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk;
		pUnk.CoCreateInstance(CLSID_AsyncReader);

		if (!(pReader = pUnk) || FAILED(pReader->Load(fnw, NULL))) {
			pReader.Release();
		}
	}

	if (!pReader) {
		hr = S_OK;
		CComPtr<IUnknown> pUnk;
		pUnk.CoCreateInstance(CLSID_URLReader);

		if (CComQIPtr<IBaseFilter> pSrc = pUnk) {
			pGB->AddFilter(pSrc, fnw);

			if (!(pReader = pUnk) || FAILED(hr = pReader->Load(fnw, NULL))) {
				pReader.Release();
				pGB->RemoveFilter(pSrc);
			}
		}
	}

	CComQIPtr<IBaseFilter> pSrc = pReader;

	if (FAILED(pGB->AddFilter(pSrc, fnw))) {
		SetFooterIcon(MAKEINTRESOURCE(IDI_ERROR));
		SetFooterText(_T("Sorry, can't save this file, press Cancel"));
		return S_FALSE;
	}

	CComQIPtr<IBaseFilter> pMid = DNew CStreamDriveThruFilter(NULL, &hr);

	if (FAILED(pGB->AddFilter(pMid, L"StreamDriveThru"))) {
		SetFooterIcon(MAKEINTRESOURCE(IDI_ERROR));
		SetFooterText(ResStr(IDS_AG_ERROR));

		return S_FALSE;
	}

	CComQIPtr<IBaseFilter> pDst;
	pDst.CoCreateInstance(CLSID_FileWriter);
	CComQIPtr<IFileSinkFilter2> pFSF = pDst;
	pFSF->SetFileName(CStringW(m_out), NULL);
	pFSF->SetMode(AM_FILE_OVERWRITE);

	if (FAILED(pGB->AddFilter(pDst, L"File Writer"))) {
		SetFooterIcon(MAKEINTRESOURCE(IDI_ERROR));
		SetFooterText(ResStr(IDS_AG_ERROR));

		return S_FALSE;
	}

	hr = pGB->Connect(
			 GetFirstPin((pSrc), PINDIR_OUTPUT),
			 GetFirstPin((pMid), PINDIR_INPUT));

	if (FAILED(hr)) {
		SetFooterIcon(MAKEINTRESOURCE(IDI_ERROR));
		SetFooterText(_T("Error Connect pSrc / pMid"));

		return S_FALSE;
	}

	hr = pGB->Connect(
			 GetFirstPin((pMid), PINDIR_OUTPUT),
			 GetFirstPin((pDst), PINDIR_INPUT));
	if (FAILED(hr)) {
		SetFooterIcon(MAKEINTRESOURCE(IDI_ERROR));
		SetFooterText(_T("Error Connect pMid / pDst"));

		return S_FALSE;
	}

	pMS = pMid;

	pMC->Run();

	return S_OK;
}
Example #10
0
LRESULT CPageDesignerApp::OnFileNew(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
	CNewDocumentDlg dlg;

	dlg.m_numPages = 1;

	dlg.m_pageWidth = ConvertSpecifiedValueToUserUnit(UNIT_PT, 612);
	dlg.m_pageHeight = ConvertSpecifiedValueToUserUnit(UNIT_PT, 792);

	dlg.m_marginLeft = ConvertSpecifiedValueToUserUnit(UNIT_PT, 36);
	dlg.m_marginRight = ConvertSpecifiedValueToUserUnit(UNIT_PT, 36);
	dlg.m_marginTop = ConvertSpecifiedValueToUserUnit(UNIT_PT, 36);
	dlg.m_marginBottom = ConvertSpecifiedValueToUserUnit(UNIT_PT, 36);

	dlg.m_columnNumber = 1;
	dlg.m_columnGutter = ConvertSpecifiedValueToUserUnit(UNIT_PT, 12);

	dlg.m_facingPages = TRUE;

	if (dlg.DoModal(GetMainHwnd(), NULL) == IDOK)
	{
		CComObject<CPDDocument>* pDocument;
		CComObject<CPDDocument>::CreateInstance(&pDocument);
		if (pDocument)
		{
			pDocument->AddRef();

			pDocument->m_pageWidth = dlg.m_pageWidth;
			pDocument->m_pageHeight = dlg.m_pageHeight;

			pDocument->m_marginTop = dlg.m_marginTop;
			pDocument->m_marginBottom = dlg.m_marginBottom;
			pDocument->m_marginInside = dlg.m_marginLeft;
			pDocument->m_marginOutside = dlg.m_marginRight;

			pDocument->m_columnNumber = dlg.m_columnNumber;
			pDocument->m_columnGutter = dlg.m_columnGutter;

			pDocument->m_facingPages = dlg.m_facingPages? VARIANT_TRUE: VARIANT_FALSE;

			WCHAR str[256];
			swprintf(str, L"Untitled%d.pddoc", ++m_nextDocumentIndex);
			pDocument->m_fileTitle = str;

			pDocument->NewDocument();	// Init (?)
			pDocument->CreatePages(dlg.m_numPages);

			pDocument->ShowViews();

		//	CComQIPtr<IUIManager> uiManager = m_frame;
		//	CComQIPtr<IPDDocument> document = pDocument;

		//	CComPtr<IUnknown> _this;
		//	QueryInterface(IID_IUnknown, (void**)&_this);

			//uiManager->ActivateObject(GetUnknown(), document);
		}
	}
#if 0
	HINSTANCE hLib = LoadLibrary("C:\\mmsx\\mmstudioplugins\\DOMCOREMOD.dll");
	if (hLib)
	{
		HTMLModalDialogProc HTMLModalDialog = (HTMLModalDialogProc)GetProcAddress(hLib, "HTMLModalDialog");
		if (HTMLModalDialog)
		{
			CComQIPtr<IDOMDocument> xmldoc;
			xmldoc.CoCreateInstance(CLSID_LDocument);
			xmldoc->put_async(VARIANT_FALSE);
			VARIANT_BOOL success;
			xmldoc->loadXML(L"<newdocument/>", &success);

			CComQIPtr<IDOMElement> element;
			xmldoc->get_documentElement(&element);

			WCHAR buf[64];

			swprintf(buf, L"%d", 1);
			element->setAttribute(L"pagesnum", buf);

			swprintf(buf, L"%d", 1);
			element->setAttribute(L"columnsnum", buf);

			swprintf(buf, L"%dpt", 1);
			element->setAttribute(L"columnsgutter", buf);

			_variant_t arg = (IDispatch*)element.p;

			_variant_t result;
			HTMLModalDialog(GetMainHwnd(), L"C:\\MMStudio\\pd_newdocument.html", &arg, L"", &result);

			CComObject<CPDDocument>* pDocument;
			CComObject<CPDDocument>::CreateInstance(&pDocument);
			if (pDocument)
			{
				pDocument->AddRef();

				pDocument->NewDocument();	// Init (?)

				pDocument->m_pageWidth = 200;
				pDocument->m_pageHeight = 400;
				pDocument->CreatePages(4);

				pDocument->ShowViews();

				CComQIPtr<IUIManager> uiManager = m_frame;
				CComQIPtr<IPDDocument> document = pDocument;

				CComPtr<IUnknown> _this;
				QueryInterface(IID_IUnknown, (void**)&_this);

				uiManager->ActivateObject(_this, document);
			}
		}
		else
		{
			MessageBox(GetMainHwnd(), "Couldn't find proc", "PageDesigner", MB_OK);
		}

		FreeLibrary(hLib);
	}
	else
	{
		MessageBox(GetMainHwnd(), "Couldn't load library", "PageDesigner", MB_OK);
	}
#endif

#if 0
	CComObject<CESvgDocument>* pDocument;
	CComObject<CESvgDocument>::CreateInstance(&pDocument);
	pDocument->AddRef();

	if (pDocument != NULL)
	{
		pDocument->NewDocument();
		pDocument->ShowViews();

		CComPtr<IUnknown> unk;
		pDocument->QueryInterface(IID_IUnknown, (void**)&unk);
		m_frame->ActivateObject(unk);
	}
#endif
	return 0;
}
Example #11
0
void CSiteFile::UpdateOutLinks()
{
	try
	{
		WCHAR sql[256];
		swprintf(sql, L"DELETE FROM links WHERE file_id = %d", m_dbid);

		_variant_t	va;
		m_pWebSite->m_siteDataConnection->Execute(sql, &va, ADODB::adCmdText);
	}
	catch (_com_error &e)
	{
		DbError(e);
	}

	TCHAR ext[_MAX_EXT];
	_splitpath(m_wfd.cFileName, NULL, NULL, NULL, ext);

	if (!stricmp(ext, ".htm") ||
		!stricmp(ext, ".html") ||
		!stricmp(ext, ".asp") ||
		!stricmp(ext, ".svg"))
	{
		CComQIPtr<IDOMDocumentContainer> documentcnt;
		documentcnt.CoCreateInstance(CLSID_DOMDocumentContainer);

		CSiteDir* pDir = (CSiteDir*)m_parent;

		CUString pathName = GetFullPathName();

		VARIANT_BOOL bsuccess;
		documentcnt->load(_bstr_t(pathName), &bsuccess);

		if (bsuccess)
		{
			CComQIPtr<IDOMDocument> document;
			documentcnt->get_document(&document);
			if (document != NULL)
			{
				{ // Links
					CComQIPtr<IDOMElement> documentElement;
					document->get_documentElement(&documentElement);

					CComQIPtr<IMMSXHTMLDocument> htmldocument;
					CComQIPtr<ISVGDocument> svgdocument;

					CArray<IDOMElement*,IDOMElement*> elements;

					if (htmldocument = document)
					{
						CollectElementTags(L"a", elements, documentElement);
					}
					else if (svgdocument = document)
					{
						CollectElementTags(L"a", elements, documentElement);
					}

					for (int i = 0; i < elements.GetSize(); i++)
					{
						IDOMElement* element = elements[i];

						BSTR bhref;

						if (htmldocument)
						{
							element->getAttribute(L"href", &bhref);
						}
						else if (svgdocument)
						{
							// TODO, use getAttributeNS
							element->getAttribute(L"xlink:href", &bhref);
						}

						_bstr_t href = _bstr_t(bhref, false);
						if (href.length())
						{
							char oldcwd[_MAX_PATH];
							_getcwd(oldcwd, _MAX_PATH);

							chdir(pDir->m_pathName);
							char fullpath[_MAX_PATH];
							_fullpath(fullpath, href, _MAX_PATH);

							chdir(oldcwd);

							CSiteFile* pHrefFile = (CSiteFile*)m_pWebSite->m_pRootDir->FindFilePathName(fullpath, 2);

							if (pHrefFile)
							{
								try
								{
									WCHAR sql[256];
									swprintf(sql, L"INSERT INTO links (file_id, out_link_id) VALUES ('%d', %d)", m_dbid, pHrefFile->m_dbid);

									_variant_t	va;
									m_pWebSite->m_siteDataConnection->Execute(sql, &va, ADODB::adCmdText);
								}
								catch (_com_error &e)
								{
									DbError(e);
								}
							}
						}

						element->Release();
					}

					elements.RemoveAll();
				}

			// DOM hierarchy
				{
					try
					{
						WCHAR sql[256];
						swprintf(sql, L"INSERT INTO DOMDocument (file_id) VALUES (%d)", m_dbid);

						_variant_t	va;

						va.Clear();
						m_pWebSite->m_siteDataConnection->Execute(sql, &va, ADODB::adCmdText);

						ADODB::_RecordsetPtr recordset;
						recordset = m_pWebSite->m_siteDataConnection->Execute(L"SELECT MAX(id) AS id FROM DOMDocument", &va, ADODB::adCmdText);

						m_ownerDocument_id = recordset->Fields->Item[_bstr_t(L"id")]->Value.lVal;

						CComQIPtr<IDOMElement> documentElement;
						document->get_documentElement(&documentElement);
						if (documentElement)
						{
							SaveDOMElementToDatabase(documentElement, 0, 0);
						}
					}
					catch (_com_error &e)
					{
						DbError(e);
					}
				}
			}
		}
	}

	m_pWebSite->Fire_OutLinksChanged(m_dbid);
}
void CExRichEditWindowless::InsertGif(LONG gif)
{
	CComQIPtr<IDynamicOleCom> spDyn;
	HRESULT hr = spDyn.CoCreateInstance(STR_PROGID);
	if(SUCCEEDED(hr))
	{
		LPOLEOBJECT lpOleObject = NULL;
		HRESULT hr = spDyn->QueryInterface(IID_IOleObject, (void**)&lpOleObject);

		IUnknownPtr lpUnk = lpOleObject;
		hr = lpUnk->QueryInterface(IID_IOleObject, (LPVOID*)&lpOleObject);
		if (lpOleObject == NULL)
			throw(E_OUTOFMEMORY);
		//hr = lpOleObject->SetClientSite( static_cast<IOleClientSite *>( this ) );
		IViewObject2Ptr lpViewObject;// IViewObject for IOleObject above
		hr = lpOleObject->QueryInterface(IID_IViewObject2, (LPVOID*)&lpViewObject);
		if (hr != S_OK)
		{
			AtlThrow(hr);
		}
		IRichEditOle* pRichEditOle = GetIRichEditOle();
		////获取RichEdit的OLEClientSite
		IOleClientSitePtr lpClientSite;
		hr = pRichEditOle->GetClientSite(&lpClientSite);

		if (hr != S_OK)
		{
			AtlThrow(hr);
		}
		REOBJECT reobject;
		ZeroMemory(&reobject,sizeof(REOBJECT));
		reobject.cbStruct = sizeof(REOBJECT);

		CLSID clsid;
		hr = lpOleObject->GetUserClassID(&clsid);
		if (hr != S_OK)
		{
			AtlThrow(hr);
		}

		reobject.clsid = clsid;
		reobject.cp = -1;
		//reobject.cp = REO_CP_SELECTION;
		reobject.dvaspect = DVASPECT_CONTENT;//DVASPECT_OPAQUE;
		reobject.poleobj = lpOleObject;
		reobject.polesite = lpClientSite;
		//reobject.pstg = lpStorage;
		SIZEL sizel;
		sizel.cx = sizel.cy = 0; // let richedit determine initial size

		Image* img = (Image*)gif;
		SIZEL sizeInPix = {img->GetWidth(), img->GetHeight()};
		SIZEL sizeInHiMetric;
		AtlPixelToHiMetric(&sizeInPix, &sizeInHiMetric);

		reobject.sizel = sizeInHiMetric;
		reobject.dwFlags = REO_BELOWBASELINE|REO_STATIC;//REO_RESIZABLE

		CExRichEditData* pdata = new CExRichEditData;
		pdata->m_dataType = GIF;
		pdata->m_data = (void*)gif;
		reobject.dwUser = (DWORD)pdata;//TODO 用户数据

		lpOleObject->SetClientSite(lpClientSite); 
		hr = pRichEditOle->InsertObject(&reobject);
		lpOleObject->SetExtent(DVASPECT_CONTENT, &sizeInHiMetric);
		OleSetContainedObject(lpOleObject, TRUE);
		lpOleObject->Release();
		spDyn->SetHostWindow((LONG)hwndParent);
		spDyn->InsertGif(gif);
	}
}
Example #13
0
int _tmain(int argc, _TCHAR* argv[])
{
    HRESULT hr;

    // Initializes the COM library on the current thread and identifies the
    // concurrency model as single-thread apartment (STA).
    ::CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);


    /////////////////////////////////////////////////////////////////////////
    // Create the ATLDllCOMServer.SimpleObject COM object using the
    // #import directive and smart pointers.
    //

    CComQIPtr<ISimpleObject> spSimpleObj;
    hr = spSimpleObj.CoCreateInstance(OLESTR(
                                          "ATLDllCOMServer.SimpleObject"));
    if (FAILED(hr))
    {
        _tprintf(_T(
                     "ISimpleObjectPtr.CoCreateInstance failed w/err 0x%08lx\n"
                 ), hr);
        return hr;
    }


    /////////////////////////////////////////////////////////////////////////
    // Use sink object 1 (CATLSimpleSinkObject1) to set up the sink for the
    // events of the source COM object.
    //

    _putts(_T("Create sink object 1"));

    // Construct the sink object CATLSimpleSinkObject1 defined in
    // ATLSimpleSinkObject.h
    CATLSimpleSinkObject1* pSinkObj1 = new CATLSimpleSinkObject1();

    // Make sure the COM object corresponding to pUnk implements
    // IProvideClassInfo2 or IPersist*. Call this method to extract info
    // about source type library if you specified only 2 parameters to
    // IDispEventImpl.
    hr = AtlGetObjectSourceInterface(spSimpleObj, &pSinkObj1->m_libid,
                                     &pSinkObj1->m_iid, &pSinkObj1->m_wMajorVerNum,
                                     &pSinkObj1->m_wMinorVerNum);
    _ASSERTE(SUCCEEDED(hr));

    // Connect the sink and source, spSimpleObj is the source COM object
    hr = pSinkObj1->DispEventAdvise(spSimpleObj, &pSinkObj1->m_iid);
    _ASSERTE(SUCCEEDED(hr));


    // Invoke the source COM object
    {
        // Set FloatProperty which fires the event FloatPropertyChanging
        _tprintf(_T("Set FloatProperty = %.2f\n"), 1.1f);
        spSimpleObj->PutFloatProperty(1.1f);

        float fProp = spSimpleObj->GetFloatProperty();
        _tprintf(_T("Get FloatProperty = %.2f\n"), fProp);
    }


    // Disconnect from the source COM object if connected
    if (pSinkObj1->m_dwEventCookie != 0xFEFEFEFE)
        pSinkObj1->DispEventUnadvise(spSimpleObj, &pSinkObj1->m_iid);

    // Destroy the sink object
    delete pSinkObj1;


    /////////////////////////////////////////////////////////////////////////
    // Use sink object 2 (CATLSimpleSinkObject2) to set up the sink for the
    // events of the source COM object.
    //

    _putts(_T("Create sink object 2"));

    // Construct the sink object CATLSimpleSinkObject2 defined in
    // ATLSimpleSinkObject.h
    CATLSimpleSinkObject2* pSinkObj2 = new CATLSimpleSinkObject2();

    // Connect the sink and source, m_spSrcObj is the source COM object
    hr = pSinkObj2->DispEventAdvise(spSimpleObj);
    _ASSERTE(SUCCEEDED(hr));


    // Invoke the source COM object
    {
        // Set FloatProperty which fires the event FloatPropertyChanging
        _tprintf(_T("Set FloatProperty = %.2f\n"), 1.2f);
        spSimpleObj->PutFloatProperty(1.2f);

        float fProp = spSimpleObj->GetFloatProperty();
        _tprintf(_T("Get FloatProperty = %.2f\n"), fProp);
    }


    // Disconnect from source if connected
    if (pSinkObj2->m_dwEventCookie != 0xFEFEFEFE)
        pSinkObj2->DispEventUnadvise(spSimpleObj);

    // Destroy the sink object
    delete pSinkObj2;


    /////////////////////////////////////////////////////////////////////////
    // Use sink object 3 (CATLSimpleSinkObject3) to set up the sink for the
    // events of the source COM object.
    //

    _putts(_T("Create sink object 3"));

    // Construct the sink object CATLSimpleSinkObject3 defined in
    // ATLSimpleSinkObject.h
    CATLSimpleSinkObject3* pSinkObj3 = new CATLSimpleSinkObject3();

    // Connect the sink and source, m_spSrcObj is the source COM object
    hr = pSinkObj3->DispEventAdvise(spSimpleObj);
    _ASSERTE(SUCCEEDED(hr));


    // Invoke the source COM object
    {
        // Set FloatProperty which fires the event FloatPropertyChanging
        _tprintf(_T("Set FloatProperty = %.2f\n"), 1.3f);
        spSimpleObj->PutFloatProperty(1.3f);

        float fProp = spSimpleObj->GetFloatProperty();
        _tprintf(_T("Get FloatProperty = %.2f\n"), fProp);
    }


    // Disconnect from source if connected
    if (pSinkObj3->m_dwEventCookie != 0xFEFEFEFE)
        pSinkObj3->DispEventUnadvise(spSimpleObj);

    // Destroy the sink object
    delete pSinkObj3;


    /////////////////////////////////////////////////////////////////////////
    // Release the COM object.
    //

    // Make sure that the source COM object is release before CoUninitialize
    spSimpleObj.Release();

    // Uninitialize COM for this thread
    ::CoUninitialize();

    return 0;
}
/*---------------------------------------------------------------------------
Name:     RdcGeneratorJob::AllocateGenerator

Allocate the resources necessary for signature generation.
This includes connecting to the RDC SDK, allocating buffers, and parameters

Arguments:
   fileSize            - used to compute RDC recursion depth.
   requestedDepth      - the preferred recursion depth, if 0, a default is calculated

----------------------------------------------------------------------------*/
DebugHresult RdcGeneratorJob::AllocateGenerator (
    ULONGLONG fileSize,
    ULONG requestedDepth )
{
    DebugHresult hr = S_OK;

    RDCAssert ( requestedDepth <= MSRDC_MAXIMUM_DEPTH );
    RDCAssert ( !m_Failed );

    m_Depth = 0;

    BYTE *buffer = m_InputBuffer.AppendItems ( g_InputBufferSize );
    if ( !buffer )
    {
        hr = E_OUTOFMEMORY;
    }

    if ( SUCCEEDED ( hr ) )
    {
        hr = m_RdcLibrary.CoCreateInstance ( __uuidof ( RdcLibrary ) );
    }

    if ( SUCCEEDED ( hr ) )
    {
        if ( requestedDepth == 0 )
        {
            hr = m_RdcLibrary->ComputeDefaultRecursionDepth ( fileSize, &m_Depth );
        }
        else
        {
            m_Depth = requestedDepth;
        }
    }

    if ( SUCCEEDED ( hr ) )
    {
        if ( m_Depth == 0 )
        {
            m_Depth = 1;
        }
        if ( m_Depth > MSRDC_MAXIMUM_DEPTH )
        {
            m_Depth = MSRDC_MAXIMUM_DEPTH;
        }
    }

    for ( ULONG i = 0; SUCCEEDED ( hr ) && i < m_Depth; ++i )
    {
        hr = m_RdcLibrary->CreateGeneratorParameters ( RDCGENTYPE_FilterMax, i + 1, &m_RdcGeneratorParameters[i] );
        m_GeneratorParameters[i] = m_RdcGeneratorParameters[i];
        if ( SUCCEEDED ( hr ) )
        {
            IRdcGeneratorFilterMaxParameters * q = 0;
            if ( i == 0 )
            {
                hr = m_RdcGeneratorParameters[0].QueryInterface ( &q );
                if ( SUCCEEDED ( hr ) )
                {
                    hr = q->SetHashWindowSize ( m_HashWindowSize1 );
                }
                if ( SUCCEEDED ( hr ) )
                {
                    hr = q->SetHorizonSize ( m_HorizonSize1 );
                }
            }
            else
            {
                hr = m_RdcGeneratorParameters[i].QueryInterface ( &q );
                if ( SUCCEEDED ( hr ) )
                {
                    hr = q->SetHashWindowSize ( m_HashWindowSizeN );
                }
                if ( SUCCEEDED ( hr ) )
                {
                    hr = q->SetHorizonSize ( m_HorizonSizeN );
                }
            }
            if ( q )
            {
                q->Release();
            }
        }
    }

    if ( SUCCEEDED ( hr ) )
    {
        hr = m_RdcLibrary->CreateGenerator ( m_Depth, &m_GeneratorParameters[0], &m_RdcGenerator );
    }

    if ( SUCCEEDED ( hr ) )
    {
        hr = m_RdcGenerator.QueryInterface ( &m_RdcSimilarityGenerator );
    }
    if ( SUCCEEDED ( hr ) )
    {
        m_SimilarityEnabled = true;
        hr = m_RdcSimilarityGenerator->EnableSimilarity();
    }
    for ( ULONG i = 0; SUCCEEDED ( hr ) && i < m_Depth; ++i )
    {
        if ( !m_OutputBuffer[i].AppendItems ( g_OutputBufferSize ) )
        {
            hr = E_OUTOFMEMORY;
        }
    }
    if ( FAILED ( hr ) )
    {
        m_Failed = true;
    }

    return hr;
}
Example #15
0
SEXP R_dataframe2dataset(SEXP dtaframe, SEXP path, SEXP shape_columns)
{
  if (!Rf_isFrame(dtaframe))
    return showError<false>(L"argument 0 is not a data.frame"), R_NilValue;
//same as narray_tools.cpp
  std::wstring dataset_name;
  tools::copy_to(path, dataset_name);

  struct _cleanup
  {
    typedef std::vector<cols_base*> c_type;
    std::vector<std::string> name;
    c_type c;
    //std::vector<c_type::const_iterator> shape;
    c_type shape;
    ~_cleanup()
    {
      for (size_t i = 0; i < c.size(); i++)
        delete c[i];
      for (size_t i = 0; i < shape.size(); i++)
        delete shape[i];
    }
  }cols;

  //cols.name = df.attr("names");
  tools::getNames(dtaframe, cols.name);

  if (cols.name.empty())
    return showError<false>(L"data.frame has 0 column"), R_NilValue;
  if (tools::size(dtaframe) != cols.name.size())
    return showError<false>(L"unknown"), R_NilValue;

  CComPtr<IGPUtilities> ipDEUtil;
  if (ipDEUtil.CoCreateInstance(CLSID_GPUtilities) != S_OK)
    return showError<true>(L"IDEUtilitiesImpl - CoCreateInstance has failed"), R_NilValue;
  HRESULT hr;

  //cols.c.resize(cols.name.size(), NULL);

  bool isShape = false;
  if (shape_columns != R_NilValue)
  {
    std::vector<std::string> shapes;
    tools::copy_to(shape_columns, shapes);
    if (shapes.size() < 2 || shapes.size() > 4)
      return showError<false>(L"shape expecting 2 strings"), NULL;
    isShape = true;
    for (size_t i = 0; i < shapes.size(); i++)
    {
      std::vector<std::string>::iterator it = std::find(cols.name.begin(), cols.name.end(), shapes[i]);
      if (it == cols.name.end())
        return showError<false>(L"cannot find shape in data.frame"), NULL;

      size_t pos = std::distance(cols.name.begin(), it);
      cols.shape.push_back(new cols_wrap<double>(VECTOR_ELT(dtaframe, pos)));
      //cols.shape.[i] = cols.c.begin() + pos;
      it->clear();
    }
  }


  CComPtr<IName> ipName;
  if (isShape)
    hr = ipDEUtil->CreateFeatureClassName(CComBSTR(dataset_name.c_str()), &ipName);
  else
    hr = ipDEUtil->CreateTableName(CComBSTR(dataset_name.c_str()), &ipName);

  CComQIPtr<IDatasetName> ipDatasetName(ipName);
  CComPtr<IWorkspaceName> ipWksName;
  CComQIPtr<IWorkspace> ipWks;
  if (hr == S_OK)
    hr = ipDatasetName->get_WorkspaceName(&ipWksName);
  if (hr == S_OK)
  {
    CComPtr<IUnknown> ipUnk;
    hr = CComQIPtr<IName>(ipWksName)->Open(&ipUnk);
    ipWks = ipUnk;
  }

  if (hr != S_OK)
    return showError<true>(L"invalid table name"), R_NilValue;

  CComQIPtr<IFeatureWorkspace> ipFWKS(ipWks);
  ATLASSERT(ipFWKS);
  if (!ipFWKS)
    return showError<true>(L"not a FeatureWorkspace"), R_NilValue;

  CComBSTR bstrTableName;
  ipDatasetName->get_Name(&bstrTableName);
  /*
  CComQIPtr<IWorkspaceSchemaImpl> ipWSchema(ipWks);
  if (ipWSchema)
  {
    VARIANT_BOOL b = VARIANT_FALSE;
    ipWSchema->TableExists(bstrTableName, &b);
    if (b != VARIANT_FALSE)
      return ::Rf_error("table Exists"), NULL;
  }*/

  CComPtr<IFieldsEdit> ipFields;
  hr = ipFields.CoCreateInstance(CLSID_Fields);
  if (hr != S_OK) return showError<true>(L"CoCreateInstance"), R_NilValue;
  
  //if (!createField(NULL, esriFieldTypeOID, ipFields))
  //  return NULL;
  if (isShape)
  {
    long pos = createField(NULL, esriFieldTypeGeometry, ipFields);
    CComPtr<IGeometryDef> ipGeoDef;
    CComPtr<IField> ipField;
    ipFields->get_Field(pos, &ipField);
    ipField->get_GeometryDef(&ipGeoDef);
    CComQIPtr<IGeometryDefEdit> ipGeoDefEd(ipGeoDef);
    ipGeoDefEd->put_GeometryType(esriGeometryPoint);
    CComQIPtr<ISpatialReference> ipSR(g_lastUsedSR);
    if (!ipSR)
    {
      ipSR.CoCreateInstance(CLSID_UnknownCoordinateSystem);
      CComQIPtr<ISpatialReferenceResolution> ipSRR(ipSR);
      if (ipSRR) FIX_DEFAULT_SR(ipSRR);
    }
    ipGeoDefEd->putref_SpatialReference(ipSR);
  }


  for (size_t i = 0; i < cols.name.size(); i++)
  {
    if (cols.name[i].empty())
      continue;
    const char* str = cols.name[i].c_str();
    cols_base* item = NULL;
    SEXP it = VECTOR_ELT(dtaframe, i);
    switch (TYPEOF(it))
    {
       case NILSXP: case SYMSXP: case RAWSXP: case LISTSXP:
       case CLOSXP: case ENVSXP: case PROMSXP: case LANGSXP:
       case SPECIALSXP: case BUILTINSXP:
       case CPLXSXP: case DOTSXP: case ANYSXP: case VECSXP:
       case EXPRSXP: case BCODESXP: case EXTPTRSXP: case WEAKREFSXP:
       case S4SXP:
       default:
          return showError<false>(L"unsupported datat.field column type"), NULL;
       case INTSXP:
         item = new cols_wrap<int>(it);
         item->pos = createField(str, esriFieldTypeInteger, ipFields); 
         break;
       case REALSXP: 
         item = new cols_wrap<double>(it);
         item->pos = createField(str, esriFieldTypeDouble, ipFields); 
         break;
       case STRSXP:
       case CHARSXP:
         item = new cols_wrap<std::string>(it);
         item->pos = createField(str, esriFieldTypeString, ipFields);
         break;
       case LGLSXP: 
         item = new cols_wrap<bool>(it);
         item->pos = createField(str, esriFieldTypeInteger, ipFields);
         break;
    }
    ATLASSERT(item);
    cols.c.push_back(item);
    item->name_ref = &cols.name[i];
  }

  CComPtr<IFieldChecker> ipFieldChecker; ipFieldChecker.CoCreateInstance(CLSID_FieldChecker);  
  if (ipFieldChecker)
  {
    ipFieldChecker->putref_ValidateWorkspace(ipWks);
    long error = 0;

    //fix fields names
    CComPtr<IFields> ipFixedFields;
    
    CComPtr<IEnumFieldError> ipEError;
    hr = ipFieldChecker->Validate(ipFields, &ipEError, &ipFixedFields);
    if (hr != S_OK)
      return showError<true>(L"validate fields failed"), NULL;
  
    if (ipFixedFields)
    {
      ipFields = ipFixedFields;
      for (size_t c = 0; c < cols.c.size(); c++)
      {
        CComPtr<IField> ipFixedField;
        ipFixedFields->get_Field(cols.c[c]->pos, &ipFixedField);
        _bstr_t name;
        ipFixedField->get_Name(name.GetAddress());
        cols.c[c]->name_ref->assign(name);
      }
    }
  }

  CComPtr<IUID> ipUID; ipUID.CoCreateInstance(CLSID_UID);
  CComQIPtr<ITable> ipTableNew;
  CComBSTR keyword(L"");
  hr = E_FAIL;
  if (isShape)
  {
    if (ipUID)
    {
      OLECHAR buf[256];
      ::StringFromGUID2(CLSID_Feature, buf, 256);
      ipUID->put_Value(CComVariant(buf));
    }

    CComPtr<IFeatureClass> ipFClass;
    hr = ipFWKS->CreateFeatureClass(bstrTableName, ipFields, ipUID, 0, esriFTSimple, CComBSTR(L"Shape"), keyword, &ipFClass);
    ipTableNew = ipFClass;
  }
  else
  {
    if (ipUID)
    {
      OLECHAR buf[256];
      ::StringFromGUID2(CLSID_Row, buf, 256);
      ipUID->put_Value(CComVariant(buf));
    }
    hr = ipFWKS->CreateTable(bstrTableName, ipFields, ipUID, 0, keyword, &ipTableNew);
  }

  if (hr != S_OK)
    return showError<true>(L"validate fields failed"), R_NilValue;

  CComVariant oid;
 
  CComPtr<ICursor> ipCursor;
  CComPtr<IRowBuffer> ipRowBuffer;
  hr = ipTableNew->Insert(VARIANT_TRUE, &ipCursor);
  if (hr != S_OK)
    return showError<true>(L"Insert cursor failed"), R_NilValue;
  hr = ipTableNew->CreateRowBuffer(&ipRowBuffer);
  if (hr != S_OK)
    return showError<true>(L"Insert cursor failed"), R_NilValue;
  
  //re-map fields
  for (size_t c = 0; c < cols.c.size(); c++)
    ipCursor->FindField(CComBSTR(cols.c[c]->name_ref->c_str()), &(cols.c[c]->pos));

  R_len_t n = tools::size(VECTOR_ELT(dtaframe, 0));
  for (R_len_t i = 0; i < n; i++)
  {
    //ATLTRACE("\n");
    for (size_t c = 0; c < cols.c.size(); c++)
    {
      if (cols.c[c]->pos < 0)
        continue;
      CComVariant val;
      cols.c[c]->get(i, val);
      hr = ipRowBuffer->put_Value(cols.c[c]->pos, val);
      if (hr != S_OK)
        return showError<true>(L"insert row value failed"), R_NilValue;
      //ATLTRACE(" [%i]=%f",cols[c]->pos, (float)val.dblVal);
    }
    VARIANT oid;
    
    if (isShape)
    {
      CComQIPtr<IPoint> ipPoint; ipPoint.CoCreateInstance(CLSID_Point);
      CComVariant valX, valY;
      cols.shape[0]->get(i, valX);
      cols.shape[1]->get(i, valY);
      ipPoint->PutCoords(valX.dblVal, valY.dblVal);
      CComQIPtr<IFeatureBuffer> ipFBuffer(ipRowBuffer);
      ATLASSERT(ipFBuffer);
      hr = ipFBuffer->putref_Shape(ipPoint);
      if (hr != S_OK)
        return showError<true>(L"insert shape failed"), R_NilValue;
    }

    hr = ipCursor->InsertRow(ipRowBuffer, &oid);
    if (hr != S_OK)
      return showError<true>(L"insert row failed"), R_NilValue;
  }
  return R_NilValue;
}
void main(int argc, char**argv)
{
	std::wcout << L"\n ===================================\n";
	std::wcout << L"\n  TextFinderComponent C++ Interface ";
	std::wcout << L"\n ===================================\n";

	HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);

	if (!SUCCEEDED(hr))
	{
		std::wcout << L"\n  could not initialize COM";
	}

	try
	{
		CComQIPtr<ITextCompCOM> TextFinderComp;

		TextFinderComp.CoCreateInstance(CLSID_TextCompCOM);
		
		if (TextFinderComp != 0)
		{
			std::wcout << L"\n =============================================================\n";

			std::wcout << "The Text Component Interface was successfully initialized" << std::endl;

			std::wcout << L"\n =============================================================\n";

			InputArgumentParser parser;

			if (parser.parseCommandLineArgs2TextCompArguments(argc, argv))
			{
				HRESULT h0 = TextFinderComp->InitializeComponent();

				HRESULT h1 = TextFinderComp->SetSearchPath(CComBSTR(parser.getDirectoryPath().c_str()));

				BSTR allPatterns;
				BSTR recursion;

				allPatterns = convertstdSTR2BSTR(bool2String(true)) ;    //By default find all patterns
				
				recursion = convertstdSTR2BSTR(bool2String(false)) ;  // By default Recursion is disabled

				if (parser.getRecursionFlag())
				{
					recursion = convertstdSTR2BSTR(bool2String(true));
				}

				if (!parser.getAllPatternsFlag())
				{
					allPatterns = convertstdSTR2BSTR(bool2String(false));
				}

				HRESULT h2 = TextFinderComp->SetSpecialSearchClause(recursion, allPatterns);

				HRESULT h3 = TextFinderComp->SetFilePatterns(convertVector2CCOMSafeArray(parser.getFilePatterns()).GetSafeArrayPtr());

				HRESULT h4 = TextFinderComp->SetTextPatterns(convertVector2CCOMSafeArray(parser.getTextPatterns()).GetSafeArrayPtr());

				if (SUCCEEDED(h0) && SUCCEEDED(h1) && SUCCEEDED(h2) && SUCCEEDED(h3) && SUCCEEDED(h4))
				{
					
					SAFEARRAY files;
				
					SAFEARRAY* pFiles = &files;

					TextFinderComp->GetQualifyingFileList(&pFiles);

					CComSafeArray<BSTR> Files;

					Files.Attach(pFiles);	

					std::wcout << L"\n =============================================================\n";
					std::wcout << L"\n =============================================================\n";

					std::wcout<<"The Qualifying Files from the Text Search Component via C++ COM interface"<<std::endl;

					displayCCOMBSTRFiles(Files);

					std::cout << "End of C++ Client for Text Search Component" << std::endl;

					std::wcout << L"\n =============================================================\n";

				}
			}

			else
			{
				parser.displayIllegalArgumentMessage();
			}

		}

	}
	catch (std::exception& ex)
	{
		std::wcout << L"\n  Exception Encountered during COM Stuff .. Contact Admin and Bug Him!" << ex.what() << L"\n\n";
		return;
	}

	std::wcout << L"\n\n";
	CoUninitialize();
}
Example #17
0
STDMETHODIMP CWebSite::LoadDocument(BSTR pathName, BOOL *success)
{
	ATLASSERT(m_pRootDir == NULL);

//
	CComQIPtr<IDOMDocument> document;
	document.CoCreateInstance(CLSID_DOMDocument);

	VARIANT_BOOL bsuccess;
	document->load(pathName, &bsuccess);
	if (bsuccess)
	{
		char dir[_MAX_PATH];
		char path[_MAX_PATH];
		char filename[_MAX_PATH];
		char ext[_MAX_PATH];
		_splitpath(_bstr_t(pathName), dir, path, filename, ext);

		TCHAR mdbfullpathname[260];
		_makepath(mdbfullpathname, dir, path, "site_data", "mdb");

		TCHAR rootpath[_MAX_PATH];
		_makepath(rootpath, dir, path, "root", NULL);

		m_rootPath = rootpath;

		// Open website database data
		if (m_siteDataConnection == NULL)
		{
			try
			{
				swprintf(m_connstr, L"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=%S", mdbfullpathname);

				m_siteDataConnection.CreateInstance(__uuidof(ADODB::Connection));
				m_siteDataConnection->Open(m_connstr, "", "", ADODB::adConnectUnspecified);
			}
			catch (_com_error &e)
			{
				DbError(e);
			}
		}

		GetHomepageFileIdFromDB();	// ReadSettings

		m_pRootDir = new CSiteDir;
		m_pRootDir->m_pWebSite = this;
		m_pRootDir->m_pathName = CUString((BSTR)m_rootPath);

		m_pRootDir->BuildFromDatabase();
		m_pRootDir->ScanFiles(TRUE, FALSE);

	//	m_pRootDir->UpdateOutLinks();

		CComQIPtr<IWebSite> site = this;

		m_hChangeThread = CreateThread(NULL, 0, ChangeNotifyThread, site.p, 0, &m_dwChangeThreadID);

	// TODO Fire UI Update event

		ShowViews();
	}

	return S_OK;
}
Example #18
0
STDMETHODIMP CPageDesignerApp::OpenDocument(BSTR pathName, VARIANT_BOOL *success)
{
#if 0
	TCHAR ext[512];
	_splitpath(_bstr_t(pathName), NULL, NULL, NULL, ext);

	CComQIPtr<IWebDocument> document;
	
	if (
		!stricmp(ext, ".htm") ||
		!stricmp(ext, ".html") ||
		!stricmp(ext, ".shtml") ||
		!stricmp(ext, ".asp") ||

		!stricmp(ext, ".svg") ||

		!stricmp(ext, ".smil") ||
		!stricmp(ext, ".smi") ||

		!stricmp(ext, ".xml") ||
		!stricmp(ext, ".xsd")/* ||

		!stricmp(ext, ".wmf") ||
		!stricmp(ext, ".emf")*/)
	{
		document.CoCreateInstance(CLSID_ESvgDocument);
	}
	else if (!stricmp(ext, ".dtd"))
	{
		document.CoCreateInstance(CLSID_DTDDocument);
	}
	else if (
		!stricmp(ext, ".js") ||
		!stricmp(ext, ".vbs"))
	{
		document.CoCreateInstance(CLSID_ExtScriptDocument);
	}
/*
	else if (!stricmp(ext, ".css"))
	{
	//	pDocument = new CCSSDocument;
	}
*/
	else
	{
		document.CoCreateInstance(CLSID_TextDocument);
	}

	if (document != NULL)
	{
		CComQIPtr<IPersistFile> ifile = document;
		if (ifile != NULL)
		{
			HRESULT hr = ifile->Load(pathName, STGM_READ);
			if (SUCCEEDED(hr))
			{
				document->ShowViews();

				m_frame->ActivateObject(document);
			}
			else
			{
				MessageBox(GetMainHwnd(), "Error loading file", "WebEditor", MB_OK);
			}
		}
		else
		{
			MessageBox(GetMainHwnd(), "Document didn't support loading from file", "WebEditor", MB_OK);
		}
	}
#endif
	return S_OK;
}