Exemplo n.º 1
0
void CItemPropertiesDlg::OnRefresh()
{
USES_CONVERSION;
   CWaitCursor wait;

   if( m_OPCItemProps.IsOk() )
   {
      m_list.DeleteAllItems();

      DWORD numItems = 0;
      DWORD* pParameterIDs = NULL;
      LPWSTR* pDescriptions = NULL;
      VARTYPE* pDataTypes = NULL;
      HRESULT hr = m_OPCItemProps.QueryAvailableProperties(T2OLE(m_ItemID.GetBuffer(0)),
                                        &numItems,
                                        &pParameterIDs,
                                        &pDescriptions,
                                        &pDataTypes);
      if( SUCCEEDED(hr) )
      {
         VARIANT* pValues = NULL;
         HRESULT* pErrors = NULL;
         hr = m_OPCItemProps.GetItemProperties(T2OLE(m_ItemID.GetBuffer(0)),
                                     numItems,
                                     pParameterIDs,
                                     &pValues,
                                     &pErrors);
         if( SUCCEEDED(hr) )
         {
            LV_ITEM     lvitem;
            for( DWORD iIndex=0; iIndex<numItems; iIndex++)
            {
               memset(&lvitem, 0, sizeof(LV_ITEM));
               lvitem.mask     = LVIF_TEXT; //|LVIF_IMAGE;
               lvitem.iItem    = iIndex;
               lvitem.iSubItem = 0;
               lvitem.pszText  = OLE2T(pDescriptions[iIndex]);
               lvitem.iImage   = 2;
               m_list.InsertItem(&lvitem);

               lvitem.mask     = LVIF_TEXT;
               lvitem.iSubItem = 1;
               CString text;
               VariantToString(pValues[iIndex], text);
               lvitem.pszText = (LPTSTR)(LPCTSTR)text;
               m_list.SetItem(&lvitem);

               if(pDescriptions[iIndex]) CoTaskMemFree(pDescriptions[iIndex]);
               if(pValues) VariantClear( &pValues[iIndex] );
            }
         }
         if( pParameterIDs ) CoTaskMemFree(pParameterIDs);
         if( pDescriptions ) CoTaskMemFree(pDescriptions);
         if( pDataTypes ) CoTaskMemFree(pDataTypes);
         if( pValues ) CoTaskMemFree(pValues);
         if( pErrors ) CoTaskMemFree(pErrors);
      }
   }
}
Exemplo n.º 2
0
void CLink::Save(CProfINIFile & SavePF)
  {
  if (m_bInUse)
    {
    CString Value, V;
    VariantToString(*this, V, false);
    Value.Format("%i,%i,%s ", m_lLink, m_State.m_bHold?1:0, V);
    SavePF.WrStr("Links", m_sTag, Value);
    }
  };
Exemplo n.º 3
0
////////////////////////////////////////////////////////////////////////
// DumpColumn
//
////////////////////////////////////////////////////////////////////////
void DumpColumn
	(
	DBBINDING*		pBinding,
	void*			pData
	)
{
    ASSERT(pBinding && pData);

	void*	p = NULL;
	BOOL    fIsUnicode = TRUE;
	WCHAR	wszBuffer[MAX_QUERY_LEN];
	
	HRESULT hr = S_OK;
	VARIANT* pvVariant = NULL;
	IUnknown* pIUnknown = NULL;
	void* pByRef = NULL;
    
	// Pretty print a column.
	// May have different type of binding.

	DBSTATUS dwStatus = STATUS_BINDING(*pBinding, pData);
	DBLENGTH dwLength = LENGTH_BINDING(*pBinding, pData);

	DBTYPE wType = pBinding->wType;

	switch(dwStatus)
	{
		case DBSTATUS_S_ISNULL:
			dwLength = 0;
			break;
	
		case DBSTATUS_S_OK:
		case DBSTATUS_S_TRUNCATED:
			switch(wType)
			{
				case DBTYPE_BSTR:
				case DBTYPE_WSTR:
					// We have a string in our buffer, so use it.
					p = &VALUE_BINDING(*pBinding, pData);
					dwLength = wcslen((WCHAR*)p);
					break;

				case DBTYPE_STR:
					// We have a string in our buffer, so use it.
					p = &VALUE_BINDING(*pBinding, pData);
					dwLength = strlen((CHAR*)p);
					fIsUnicode = FALSE;
					break;

				case DBTYPE_VARIANT:
					// We have a variant in our buffer, so convert to string.
					pvVariant = (VARIANT*)&VALUE_BINDING(*pBinding, pData);
					wType = V_VT(pvVariant);

					//VariantChangeTypeEx seems to handle most types,
					TESTC(VariantToString(pvVariant, wszBuffer, MAX_QUERY_LEN, FALSE));
					p = wszBuffer;
					break;

				case DBTYPE_HCHAPTER:
				{
					HCHAPTER hChapter = (HCHAPTER)VALUE_BINDING(*pBinding, pData);
					swprintf(wszBuffer, L"%lu", hChapter);
					p = wszBuffer;	
					break;
				}

				case DBTYPE_IUNKNOWN:
				case DBTYPE_IUNKNOWN | DBTYPE_BYREF:
				{
					//It's possible that this object supports a storage object
					//If so, read all the data from the Storage Object and dump it
					//Otherwise just output the actual ptr					
					static WCHAR s_rgchByteHex[] = L"0123456789ABCDEF";
					
					ULONG cBytesRead = 0;
					ULONG ulMaxSize = MAX_QUERY_LEN / 2;
					BYTE* pbBuffer = (BYTE*)PROVIDER_ALLOC(ulMaxSize);
					WCHAR* pch = wszBuffer;

					p = wszBuffer;
					pIUnknown = (IUnknown*)VALUE_BINDING(*pBinding, pData);
					if(wType & DBTYPE_BYREF)
					{
						pByRef = (void*)VALUE_BINDING(*pBinding, pData);
						pIUnknown = *(IUnknown**)pByRef;
					}

					hr = StorageRead(IID_IUnknown, pIUnknown, pbBuffer, ulMaxSize, &cBytesRead);
						
					if (hr == S_OK || hr == S_FALSE)
					{
						// Convert the byte buffer to string.
						for (BYTE *pb = pbBuffer; cBytesRead ;cBytesRead--, pb++)
						{
							*pch++ = s_rgchByteHex[*pb >> 4];
							*pch++ = s_rgchByteHex[*pb & 0x0F];							
						}
						*pch = L'\0';											
					}
					else
					{
						swprintf(wszBuffer, L"%p", pIUnknown);
					}

					SAFE_FREE(pbBuffer);
					break;
				}
		
				default:
					if(wType & DBTYPE_VECTOR)
					{
						DBVECTOR* pVector = (DBVECTOR*)&VALUE_BINDING(*pBinding, pData);
						hr = VectorToString(pVector, wType, wszBuffer, MAX_QUERY_LEN);
						p = wszBuffer;
					}
					else if(wType & DBTYPE_ARRAY)
					{
						SAFEARRAY* pSafeArray = *(SAFEARRAY**)&VALUE_BINDING(*pBinding, pData);
						hr = SafeArrayToString(pSafeArray, wType, wszBuffer, MAX_QUERY_LEN);
						p = wszBuffer;
					}
					else
					{
						p = L"??? Unknown Type ???";
						dwLength = 0;
					}
					break;
			}
			break;

		default:
	        p = L"??? Unknown Status ???";
			dwLength = 0;
			break;
    };
Exemplo n.º 4
0
void App::GetProperties()
{
    LPSTORAGE				pStorage = NULL;
    IPropertySetStorage*	pPropertySetStorage = NULL;
    IPropertyStorage*		pSummaryInfoStorage = NULL;
    IPropertyStorage*		pDocumentSummaryInfoStorage = NULL;
    IPropertyStorage*		pUserDefinedPropertyStorage = NULL;
    wchar_t					wfilename[_MAX_PATH];
    char					szBuf[256];
    char					filename[MAX_PATH];

    SendMessage(GetDlgItem(hPropDialog, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_SUBJECT), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_AUTHOR), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_MANAGER), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_COMPANY), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_CATEGORY), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_KEYWORDS), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_COMMENTS), WM_SETTEXT, 0, (LPARAM)"");
    SendMessage(GetDlgItem(hPropDialog, IDC_CONTENTS), LB_RESETCONTENT, 0, 0);
    ListView_DeleteAllItems(GetDlgItem(hPropDialog, IDC_CUSTOM));

    int idx = SendMessage(hListBox, LB_GETCURSEL, 0, 0);

    SendMessage(hListBox, LB_GETTEXT, idx, (LPARAM)filename);
    SetWindowText(hPropDialog, filename);

    MultiByteToWideChar(CP_ACP, 0, filename, -1, wfilename, _MAX_PATH);
    HRESULT	res = StgOpenStorage(wfilename, (LPSTORAGE)0, STGM_DIRECT|STGM_READ|STGM_SHARE_EXCLUSIVE,	NULL,0,&pStorage);
    if (res!=S_OK) {
        return;
    }


    // Get the Storage interface
    if (S_OK != pStorage->QueryInterface(IID_IPropertySetStorage, (void**)&pPropertySetStorage)) {
        pStorage->Release();
        return;
    }

    // Get the SummaryInfo property set interface
    if (S_OK == pPropertySetStorage->Open(FMTID_SummaryInformation, STGM_READ|STGM_SHARE_EXCLUSIVE, &pSummaryInfoStorage)) {
        BOOL bFound = FALSE;

        PROPSPEC	PropSpec[5];
        PROPVARIANT	PropVar[5];

        PropSpec[0].ulKind = PRSPEC_PROPID;
        PropSpec[0].propid = PID_TITLE;

        PropSpec[1].ulKind = PRSPEC_PROPID;
        PropSpec[1].propid = PID_SUBJECT;

        PropSpec[2].ulKind = PRSPEC_PROPID;
        PropSpec[2].propid = PID_AUTHOR;

        PropSpec[3].ulKind = PRSPEC_PROPID;
        PropSpec[3].propid = PID_KEYWORDS;

        PropSpec[4].ulKind = PRSPEC_PROPID;
        PropSpec[4].propid = PID_COMMENTS;

        HRESULT hr = pSummaryInfoStorage->ReadMultiple(5, PropSpec, PropVar);
        if (S_OK == hr) {
            if (PropVar[0].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_TITLE), WM_SETTEXT, 0, (LPARAM)PropVar[0].pszVal);
            }
            if (PropVar[1].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_SUBJECT), WM_SETTEXT, 0, (LPARAM)PropVar[1].pszVal);
            }
            if (PropVar[2].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_AUTHOR), WM_SETTEXT, 0, (LPARAM)PropVar[2].pszVal);
            }
            if (PropVar[3].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_KEYWORDS), WM_SETTEXT, 0, (LPARAM)PropVar[3].pszVal);
            }
            if (PropVar[4].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_COMMENTS), WM_SETTEXT, 0, (LPARAM)PropVar[4].pszVal);
            }
        }

        FreePropVariantArray(5, PropVar);
        pSummaryInfoStorage->Release();
    }


    // Get the DocumentSummaryInfo property set interface
    if (S_OK == pPropertySetStorage->Open(FMTID_DocSummaryInformation, STGM_READ|STGM_SHARE_EXCLUSIVE, &pDocumentSummaryInfoStorage)) {
        BOOL bFound = FALSE;

        PROPSPEC	PropSpec[5];
        PROPVARIANT	PropVar[5];

        PropSpec[0].ulKind = PRSPEC_PROPID;
        PropSpec[0].propid = PID_MANAGER;

        PropSpec[1].ulKind = PRSPEC_PROPID;
        PropSpec[1].propid = PID_COMPANY;

        PropSpec[2].ulKind = PRSPEC_PROPID;
        PropSpec[2].propid = PID_CATEGORY;

        PropSpec[3].ulKind = PRSPEC_PROPID;
        PropSpec[3].propid = PID_HEADINGPAIR;

        PropSpec[4].ulKind = PRSPEC_PROPID;
        PropSpec[4].propid = PID_DOCPARTS;

        HRESULT hr = pDocumentSummaryInfoStorage->ReadMultiple(5, PropSpec, PropVar);
        if (S_OK == hr) {
            if (PropVar[0].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_MANAGER), WM_SETTEXT, 0, (LPARAM)PropVar[0].pszVal);
            }
            if (PropVar[1].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_COMPANY), WM_SETTEXT, 0, (LPARAM)PropVar[1].pszVal);
            }
            if (PropVar[2].vt == VT_LPSTR) {
                SendMessage(GetDlgItem(hPropDialog, IDC_CATEGORY), WM_SETTEXT, 0, (LPARAM)PropVar[2].pszVal);
            }
            if ((PropVar[3].vt == (VT_VARIANT | VT_VECTOR)) && (PropVar[4].vt == (VT_LPSTR | VT_VECTOR))) {
                CAPROPVARIANT*	pHeading = &PropVar[3].capropvar;
                CALPSTR*		pDocPart = &PropVar[4].calpstr;

                // Headings:
                // =========
                // 0  - General
                // 2  - Mesh Totals
                // 4  - Scene Totals
                // 6  - External Dependencies
                // 8  - Objects
                // 10 - Materials
                // 12 - Plug-Ins

                int nDocPart = 0;
                for (UINT i=0; i<pHeading->cElems; i+=2) {
                    SendMessage(GetDlgItem(hPropDialog, IDC_CONTENTS), LB_ADDSTRING, 0, (LPARAM)pHeading->pElems[i].pszVal);
                    for (int j=0; j<pHeading->pElems[i+1].lVal; j++) {
                        sprintf(szBuf, "\t%s", pDocPart->pElems[nDocPart]);
                        SendMessage(GetDlgItem(hPropDialog, IDC_CONTENTS), LB_ADDSTRING, 0, (LPARAM)szBuf);
                        nDocPart++;
                    }
                }

            }

        }

        FreePropVariantArray(5, PropVar);
        pDocumentSummaryInfoStorage->Release();
    }

    if (S_OK == pPropertySetStorage->Open(FMTID_UserDefinedProperties, STGM_READ|STGM_SHARE_EXCLUSIVE, &pUserDefinedPropertyStorage)) {
        int		numUserProps = 0;

        // First we need to count the properties
        IEnumSTATPROPSTG*	pIPropertyEnum;
        if (S_OK == pUserDefinedPropertyStorage->Enum(&pIPropertyEnum)) {
            STATPROPSTG property;
            while (pIPropertyEnum->Next(1, &property, NULL) == S_OK) {
                if (property.lpwstrName) {
                    CoTaskMemFree(property.lpwstrName);
                    property.lpwstrName = NULL;
                    numUserProps++;
                }
            }

            PROPSPEC* pPropSpec = new PROPSPEC[numUserProps];
            PROPVARIANT* pPropVar = new PROPVARIANT[numUserProps];

            ZeroMemory(pPropVar, numUserProps*sizeof(PROPVARIANT));
            ZeroMemory(pPropSpec, numUserProps*sizeof(PROPSPEC));

            pIPropertyEnum->Reset();
            int idx = 0;
            while (pIPropertyEnum->Next(1, &property, NULL) == S_OK) {
                if (property.lpwstrName) {
                    pPropSpec[idx].ulKind = PRSPEC_LPWSTR;
                    pPropSpec[idx].lpwstr = (LPWSTR)CoTaskMemAlloc(sizeof(wchar_t)*(wcslen(property.lpwstrName)+1));
                    wcscpy(pPropSpec[idx].lpwstr, property.lpwstrName);
                    idx++;
                    CoTaskMemFree(property.lpwstrName);
                    property.lpwstrName = NULL;
                }
            }
            pIPropertyEnum->Release();

            ListView_DeleteAllItems(GetDlgItem(hPropDialog, IDC_CUSTOM));
            HRESULT hr = pUserDefinedPropertyStorage->ReadMultiple(idx, pPropSpec, pPropVar);
            if (S_OK == hr) {
                for (int i=0; i<idx; i++) {
                    wcstombs(szBuf, pPropSpec[i].lpwstr, 255);
                    LV_ITEM item;
                    item.mask = LVIF_TEXT;
                    item.iItem = i;
                    item.iSubItem = 0;
                    item.pszText = szBuf;
                    item.cchTextMax = strlen(szBuf);
                    ListView_InsertItem(GetDlgItem(hPropDialog, IDC_CUSTOM), &item);

                    VariantToString(this, &pPropVar[i], szBuf, 255);
                    item.iSubItem = 1;
                    item.pszText = szBuf;
                    item.cchTextMax = strlen(szBuf);
                    ListView_SetItem(GetDlgItem(hPropDialog, IDC_CUSTOM), &item);

                    TypeNameFromVariant(this, &pPropVar[i], szBuf, 255);
                    item.iSubItem = 2;
                    item.pszText = szBuf;
                    item.cchTextMax = strlen(szBuf);
                    ListView_SetItem(GetDlgItem(hPropDialog, IDC_CUSTOM), &item);
                }
            }

            for (int i=0; i<idx; i++) {
                CoTaskMemFree(pPropSpec[i].lpwstr);
            }

            FreePropVariantArray(numUserProps, pPropVar);

            delete [] pPropSpec;
            delete [] pPropVar;
        }

        pUserDefinedPropertyStorage->Release();
    }

    pPropertySetStorage->Release();
    pStorage->Release();
}