Webbrowser::Webbrowser(void): _refNum(0), //_rcWebWnd(0), _bInPlaced(false), _bExternalPlace(false), _bCalledCanInPlace(false), _bWebWndInited(false), _pOleObj(NULL), _pInPlaceObj(NULL), _pStorage(NULL), _pWB2(NULL), _pHtmlDoc2(NULL), _pHtmlDoc3(NULL), _pHtmlWnd2(NULL), _pHtmlEvent(NULL) { ::memset( (PVOID)&_rcWebWnd,0,sizeof(_rcWebWnd)); HRTEST_SE( OleInitialize(0),L"Failed in Initialize Ole"); HRTEST_SE( StgCreateDocfile(0,STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT | STGM_CREATE,0,&_pStorage),L"ERROR:StgCreateDocfile"); HRTEST_SE( OleCreate(CLSID_WebBrowser,IID_IOleObject,OLERENDER_DRAW,0,this,_pStorage,(void**)&_pOleObj),L"Create Ole Failed"); HRTEST_SE( _pOleObj->QueryInterface(IID_IOleInPlaceObject,(LPVOID*)&_pInPlaceObj),L"Create OleInPlaceObject Failed"); GetWebBrowser2(); OleUninitialize(); RETURN: return; }
STDMETHODIMP_(ULONG) CREOleCallback::AddRef() { if (refCount == 0) StgCreateDocfile(NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_DELETEONRELEASE, 0, &pictStg); return ++refCount; }
static STDMETHODIMP_(ULONG) CREOleCallback_AddRef(struct CREOleCallback *lpThis) { if (lpThis->refCount == 0) { if (S_OK != StgCreateDocfile(NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE | STGM_DELETEONRELEASE, 0, &lpThis->pictStg)) lpThis->pictStg = NULL; lpThis->nextStgId = 0; } return ++lpThis->refCount; }
HRESULT MakeRootStorage(LPSTORAGE *ppIStorage, LPCSTR pPathName) { HRESULT hr = NOERROR; DWORD dwMode = STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED ; char *pNameToUse = new char [_MAX_PATH]; LPSTORAGE pIStorage = *ppIStorage; if (NULL == pNameToUse || NULL == pPathName) return ResultFromScode(E_FAIL); // alte ProjektStruktur, eigenes DocFile erzeugen/öffnen // erstellt Pfadnamen hr = MakeFileName (pPathName, pNameToUse, "str"); if (FAILED(hr)) return hr; // Funktionen machen Addref(), Release() im Destruktor (Memberpointer Rootstorage) USES_CONVERSION; hr = StgOpenStorage (A2OLE(pNameToUse), NULL, dwMode, 0, 0, &pIStorage); if (FAILED(hr)) { if (GetScode(hr) == STG_E_FILENOTFOUND) { // neu anlegen dwMode |= STGM_CREATE; hr = StgCreateDocfile (A2OLE(pNameToUse), dwMode, 0, &pIStorage); delete (pNameToUse); if (FAILED(hr)) return hr; // GUID reinschreiben (Kontrollmöglichkeit) hr = WriteClassStg (pIStorage, CLSID_ScriptContainer); if (FAILED(hr)) { pIStorage -> Release(); return hr; } } else { delete (pNameToUse); return hr; } } else delete (pNameToUse); hr = TestclsID (pIStorage, CLSID_ScriptContainer); if (FAILED(hr)) { pIStorage -> Release(); return hr; } *ppIStorage = pIStorage; return NOERROR; }
static void create_patch( const char *filename ) { IStorage *stg = NULL, *stg1 = NULL, *stg2 = NULL; WCHAR *filenameW; HRESULT r; int len; const DWORD mode = STGM_CREATE|STGM_READWRITE|STGM_DIRECT|STGM_SHARE_EXCLUSIVE; const CLSID CLSID_MsiPatch = {0xc1086, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46}}; const CLSID CLSID_MsiTransform = {0xc1082, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46}}; len = MultiByteToWideChar( CP_ACP, 0, filename, -1, NULL, 0 ); filenameW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ); MultiByteToWideChar( CP_ACP, 0, filename, -1, filenameW, len ); r = StgCreateDocfile( filenameW, mode, 0, &stg ); HeapFree( GetProcessHeap(), 0, filenameW ); ok( r == S_OK, "failed to create storage 0x%08x\n", r ); if (!stg) return; r = IStorage_SetClass( stg, &CLSID_MsiPatch ); ok( r == S_OK, "failed to set storage type 0x%08x\n", r ); write_tables( stg, table_patch_data, NUM_PATCH_TABLES ); r = IStorage_CreateStorage( stg, p_name7, mode, 0, 0, &stg1 ); ok( r == S_OK, "failed to create substorage 0x%08x\n", r ); r = IStorage_SetClass( stg1, &CLSID_MsiTransform ); ok( r == S_OK, "failed to set storage type 0x%08x\n", r ); write_tables( stg1, table_transform1_data, NUM_TRANSFORM1_TABLES ); IStorage_Release( stg1 ); r = IStorage_CreateStorage( stg, p_name8, mode, 0, 0, &stg2 ); ok( r == S_OK, "failed to create substorage 0x%08x\n", r ); r = IStorage_SetClass( stg2, &CLSID_MsiTransform ); ok( r == S_OK, "failed to set storage type 0x%08x\n", r ); write_tables( stg2, table_transform2_data, NUM_TRANSFORM2_TABLES ); IStorage_Release( stg2 ); IStorage_Release( stg ); }
//--------------------------------------------------------------------- void E_IStorage::ccom_create_doc_file (WCHAR * pwcsName, DWORD grfMode) // Creates a new compound file storage object using the OLE-provided // compound file implementation for the IStorage interface. // Points pStorage to the new storage object. // Parameters // - pwcsName points to the pathname of the compound file to create. // If it is NULL, a temporary compound file is allocated with a unique name. // - grfMode specifies the access mode to use when opening the new // storage object. Must be one of the STGM enumeration values. { HRESULT hr; hr = StgCreateDocfile (pwcsName, grfMode, 0, &pStorage); if (hr != S_OK) { pStorage = NULL; com_eraise (f.c_format_message (hr), EN_COM); } };
int _tmain(int argc, _TCHAR* argv[]) { CLSID wid; CoInitialize(NULL); CLSIDFromString(const_cast<wchar_t*>(default_guid), &wid); IInitializeWithFile *oo; HRESULT hr; if ((hr = CoCreateInstance(wid, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&oo))) != S_OK) fail(); #if 0 IStorage *isto; if ((hr = StgCreateDocfile(L"t.mp3", STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT, 0, &isto)) != S_OK) fail(); IStream *is; if ((hr = isto->CreateStream(L"lol", STGM_DIRECT | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &is)) != S_OK) fail(); #endif IPropertyStore *ips; IPropertyStoreCapabilities *ipcs; if ((hr = oo->QueryInterface(IID_PPV_ARGS(&ips))) != S_OK) fail(); if ((hr = oo->QueryInterface(IID_PPV_ARGS(&ipcs))) != S_OK) fail(); //iws->Initialize(is, STGM_READWRITE); if ((hr = oo->Initialize(L"t.mp3", STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DIRECT)) != S_OK) fail(); DWORD props; if ((hr = ips->GetCount(&props)) != S_OK) fail(); for (DWORD i = 0; i < props; ++i) { PROPERTYKEY pkey; ips->GetAt(i, &pkey); WCHAR *sz; PSGetNameFromPropertyKey(pkey, &sz); std::wcout << (ipcs->IsPropertyWritable(pkey) == S_OK) << "\t" << sz << std::endl; } return 0; }
// This code was also brazenly stolen from the DX9 SDK // Pass it a file name in wszPath, and it will save the filter graph to that file. HRESULT SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath) { const WCHAR wszStreamName[] = L"ActiveMovieGraph"; HRESULT hr; IStorage *pStorage = NULL; // First, create a document file which will hold the GRF file hr = StgCreateDocfile( wszPath, STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStorage); if(FAILED(hr)) { return hr; } // Next, create a stream to store. IStream *pStream; hr = pStorage->CreateStream( wszStreamName, STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream); if (FAILED(hr)) { pStorage->Release(); return hr; } // The IPersistStream converts a stream into a persistent object. IPersistStream *pPersist = NULL; pGraph->QueryInterface(IID_IPersistStream, reinterpret_cast<void**>(&pPersist)); hr = pPersist->Save(pStream, TRUE); pStream->Release(); pPersist->Release(); if (SUCCEEDED(hr)) { hr = pStorage->Commit(STGC_DEFAULT); } pStorage->Release(); return hr; }
// @pymethod <o PyIStorage>|pythoncom|StgCreateDocfile|Creates a new compound file storage object using the OLE-provided compound file implementation for the <o PyIStorage> interface. PyObject *pythoncom_StgCreateDocfile(PyObject *self, PyObject *args) { DWORD reserved = 0; PyObject *obName; DWORD mode; IStorage *pResult; if (!PyArg_ParseTuple(args, "Oi|i:StgCreateDocfile", &obName, // @pyparm string|name||the path of the compound file to create. It is passed uninterpreted to the file system. This can be a relative name or None. If None, a temporary stream is created. &mode, // @pyparm int|mode||Specifies the access mode used to open the storage. &reserved)) // @pyparm int|reserved|0|A reserved value return NULL; PyWin_AutoFreeBstr bstrName; if ( !PyWinObject_AsAutoFreeBstr(obName, &bstrName, TRUE) ) return NULL; PY_INTERFACE_PRECALL; HRESULT hr = StgCreateDocfile(bstrName, mode, reserved, &pResult); PY_INTERFACE_POSTCALL; if (FAILED(hr)) return PyCom_BuildPyException(hr); return PyCom_PyObjectFromIUnknown(pResult, IID_IStorage, FALSE); }
HRESULT SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath) { const WCHAR wszStreamName[] = L"ActiveMovieGraph"; HRESULT hr; IStorage *pStorage = NULL; hr = StgCreateDocfile( wszPath, STGM_CREATE | STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, 0, &pStorage); if(FAILED(hr)) { return hr; } IStream *pStream; hr = pStorage->CreateStream( wszStreamName, STGM_WRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, 0, 0, &pStream); if (FAILED(hr)) { pStorage->Release(); return hr; } IPersistStream *pPersist = NULL; pGraph->QueryInterface(IID_IPersistStream, (void**)&pPersist); hr = pPersist->Save(pStream, TRUE); pStream->Release(); pPersist->Release(); if (SUCCEEDED(hr)) { hr = pStorage->Commit(STGC_DEFAULT); } pStorage->Release(); return hr; }
/* FIXME: this creates an ANSI storage, try to find conditions under which * Unicode translation fails */ static void testProps(void) { static const WCHAR szDot[] = { '.',0 }; static const WCHAR szPrefix[] = { 's','t','g',0 }; static WCHAR propName[] = { 'p','r','o','p',0 }; static char val[] = "l33t auth0r"; WCHAR filename[MAX_PATH]; HRESULT hr; IStorage *storage = NULL; IPropertySetStorage *propSetStorage = NULL; IPropertyStorage *propertyStorage = NULL; PROPSPEC spec; PROPVARIANT var; CLIPDATA clipdata; unsigned char clipcontent[] = "foobar"; GUID anyOldGuid = { 0x12345678,0xdead,0xbeef, { 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07 } }; if(!GetTempFileNameW(szDot, szPrefix, 0, filename)) return; DeleteFileW(filename); hr = StgCreateDocfile(filename, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage); ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr); if(!pStgCreatePropSetStg) { IStorage_Release(storage); DeleteFileW(filename); return; } hr = pStgCreatePropSetStg(storage, 0, &propSetStorage); ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr); hr = IPropertySetStorage_Create(propSetStorage, &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &propertyStorage); ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr); hr = IPropertyStorage_WriteMultiple(propertyStorage, 0, NULL, NULL, 0); ok(hr == S_OK, "WriteMultiple with 0 args failed: 0x%08x\n", hr); hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, NULL, NULL, 0); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr); /* test setting one that I can't set */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_DICTIONARY; var.vt = VT_I4; U(var).lVal = 1; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == STG_E_INVALIDPARAMETER, "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr); /* test setting one by name with an invalid propidNameFirst */ spec.ulKind = PRSPEC_LPWSTR; U(spec).lpwstr = propName; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, PID_DICTIONARY); ok(hr == STG_E_INVALIDPARAMETER, "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr); /* test setting behavior (case-sensitive) */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_BEHAVIOR; U(var).lVal = 1; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == STG_E_INVALIDPARAMETER, "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr); /* set one by value.. */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; U(var).lVal = 1; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* set one by name */ spec.ulKind = PRSPEC_LPWSTR; U(spec).lpwstr = propName; U(var).lVal = 2; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, PID_FIRST_USABLE); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* set a string value */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PIDSI_AUTHOR; var.vt = VT_LPSTR; U(var).pszVal = val; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* set a clipboard value */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PIDSI_THUMBNAIL; var.vt = VT_CF; clipdata.cbSize = sizeof clipcontent + sizeof (ULONG); clipdata.ulClipFmt = CF_ENHMETAFILE; clipdata.pClipData = clipcontent; U(var).pclipdata = &clipdata; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* check reading */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 0, NULL, NULL); ok(hr == S_FALSE, "ReadMultiple with 0 args failed: 0x%08x\n", hr); hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, NULL, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr); /* read by propid */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I4 && U(var).lVal == 1, "Didn't get expected type or value for property (got type %d, value %d)\n", var.vt, U(var).lVal); /* read by name */ spec.ulKind = PRSPEC_LPWSTR; U(spec).lpwstr = propName; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I4 && U(var).lVal == 2, "Didn't get expected type or value for property (got type %d, value %d)\n", var.vt, U(var).lVal); /* read string value */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PIDSI_AUTHOR; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val), "Didn't get expected type or value for property (got type %d, value %s)\n", var.vt, U(var).pszVal); PropVariantClear(&var); /* read clipboard format */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PIDSI_THUMBNAIL; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_CF, "variant type wrong\n"); ok(U(var).pclipdata->ulClipFmt == CF_ENHMETAFILE, "clipboard type wrong\n"); ok(U(var).pclipdata->cbSize == sizeof clipcontent + sizeof (ULONG), "clipboard size wrong\n"); ok(!memcmp(U(var).pclipdata->pClipData, clipcontent, sizeof clipcontent), "clipboard contents wrong\n"); ok(S_OK == PropVariantClear(&var), "failed to clear variant\n"); /* check deleting */ hr = IPropertyStorage_DeleteMultiple(propertyStorage, 0, NULL); ok(hr == S_OK, "DeleteMultiple with 0 args failed: 0x%08x\n", hr); hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, NULL); ok(hr == E_INVALIDARG, "Expected E_INVALIDARG, got 0x%08x\n", hr); /* contrary to what the docs say, you can't delete the dictionary */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_DICTIONARY; hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec); ok(hr == STG_E_INVALIDPARAMETER, "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr); /* now delete the first value.. */ U(spec).propid = PID_FIRST_USABLE; hr = IPropertyStorage_DeleteMultiple(propertyStorage, 1, &spec); ok(hr == S_OK, "DeleteMultiple failed: 0x%08x\n", hr); /* and check that it's no longer readable */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr); hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT); ok(hr == S_OK, "Commit failed: 0x%08x\n", hr); /* check reverting */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); hr = IPropertyStorage_Revert(propertyStorage); ok(hr == S_OK, "Revert failed: 0x%08x\n", hr); /* now check that it's still not there */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_FALSE, "Expected S_FALSE, got 0x%08x\n", hr); /* set an integer value again */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; var.vt = VT_I4; U(var).lVal = 1; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* commit it */ hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT); ok(hr == S_OK, "Commit failed: 0x%08x\n", hr); /* set it to a string value */ var.vt = VT_LPSTR; U(var).pszVal = val; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* revert it */ hr = IPropertyStorage_Revert(propertyStorage); ok(hr == S_OK, "Revert failed: 0x%08x\n", hr); /* Oddly enough, there's no guarantee that a successful revert actually * implies the value wasn't saved. Maybe transactional mode needs to be * used for that? */ IPropertyStorage_Release(propertyStorage); propertyStorage = NULL; IPropertySetStorage_Release(propSetStorage); propSetStorage = NULL; IStorage_Release(storage); storage = NULL; /* now open it again */ hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &storage); ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr); hr = pStgCreatePropSetStg(storage, 0, &propSetStorage); ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr); hr = IPropertySetStorage_Open(propSetStorage, &FMTID_SummaryInformation, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage); ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr); /* check properties again */ spec.ulKind = PRSPEC_LPWSTR; U(spec).lpwstr = propName; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I4 && U(var).lVal == 2, "Didn't get expected type or value for property (got type %d, value %d)\n", var.vt, U(var).lVal); spec.ulKind = PRSPEC_PROPID; U(spec).propid = PIDSI_AUTHOR; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_LPSTR && !lstrcmpA(U(var).pszVal, val), "Didn't get expected type or value for property (got type %d, value %s)\n", var.vt, U(var).pszVal); PropVariantClear(&var); IPropertyStorage_Release(propertyStorage); IPropertySetStorage_Release(propSetStorage); IStorage_Release(storage); DeleteFileW(filename); /* Test creating a property set storage with a random GUID */ hr = StgCreateDocfile(filename, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage); ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr); if(!pStgCreatePropSetStg) { IStorage_Release(storage); DeleteFileW(filename); return; } hr = pStgCreatePropSetStg(storage, 0, &propSetStorage); ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr); hr = IPropertySetStorage_Create(propSetStorage, &anyOldGuid, NULL, PROPSETFLAG_ANSI, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &propertyStorage); ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr); spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; var.vt = VT_I4; U(var).lVal = 1; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); hr = IPropertyStorage_Commit(propertyStorage, STGC_DEFAULT); ok(hr == S_OK, "Commit failed: 0x%08x\n", hr); IPropertyStorage_Release(propertyStorage); IPropertySetStorage_Release(propSetStorage); IStorage_Release(storage); propertyStorage = NULL; /* now open it again */ hr = StgOpenStorage(filename, NULL, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, NULL, 0, &storage); ok(hr == S_OK, "StgOpenStorage failed: 0x%08x\n", hr); hr = pStgCreatePropSetStg(storage, 0, &propSetStorage); ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr); hr = IPropertySetStorage_Open(propSetStorage, &anyOldGuid, STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &propertyStorage); ok(hr == S_OK, "IPropertySetStorage_Open failed: 0x%08x\n", hr); spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I4 && U(var).lVal == 1, "Didn't get expected type or value for property (got type %d, value %d)\n", var.vt, U(var).lVal); IPropertyStorage_Release(propertyStorage); IPropertySetStorage_Release(propSetStorage); IStorage_Release(storage); DeleteFileW(filename); }
static void testCodepage(void) { static const WCHAR szDot[] = { '.',0 }; static const WCHAR szPrefix[] = { 's','t','g',0 }; static CHAR aval[] = "hi"; static WCHAR wval[] = { 'h','i',0 }; HRESULT hr; IStorage *storage = NULL; IPropertySetStorage *propSetStorage = NULL; IPropertyStorage *propertyStorage = NULL; PROPSPEC spec; PROPVARIANT var; WCHAR fileName[MAX_PATH]; if(!GetTempFileNameW(szDot, szPrefix, 0, fileName)) return; hr = StgCreateDocfile(fileName, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage); ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr); if(!pStgCreatePropSetStg) { IStorage_Release(storage); DeleteFileW(fileName); return; } hr = pStgCreatePropSetStg(storage, 0, &propSetStorage); ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr); hr = IPropertySetStorage_Create(propSetStorage, &FMTID_SummaryInformation, NULL, PROPSETFLAG_DEFAULT, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &propertyStorage); ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr); PropVariantInit(&var); spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_CODEPAGE; /* check code page before it's been explicitly set */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I2 && U(var).iVal == 1200, "Didn't get expected type or value for property\n"); /* Set the code page to ascii */ var.vt = VT_I2; U(var).iVal = 1252; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* check code page */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I2 && U(var).iVal == 1252, "Didn't get expected type or value for property\n"); /* Set code page to Unicode */ U(var).iVal = 1200; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* check code page */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I2 && U(var).iVal == 1200, "Didn't get expected type or value for property\n"); /* Set a string value */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; var.vt = VT_LPSTR; U(var).pszVal = aval; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "hi"), "Didn't get expected type or value for property\n"); PropVariantClear(&var); /* This seemingly non-sensical test is to show that the string is indeed * interpreted according to the current system code page, not according to * the property set's code page. (If the latter were true, the whole * string would be maintained. As it is, only the first character is.) */ var.vt = VT_LPSTR; U(var).pszVal = (LPSTR)wval; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, "h"), "Didn't get expected type or value for property\n"); PropVariantClear(&var); /* now that a property's been set, you can't change the code page */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_CODEPAGE; var.vt = VT_I2; U(var).iVal = 1200; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == STG_E_INVALIDPARAMETER, "Expected STG_E_INVALIDPARAMETER, got 0x%08x\n", hr); IPropertyStorage_Release(propertyStorage); IPropertySetStorage_Release(propSetStorage); IStorage_Release(storage); DeleteFileW(fileName); /* same tests, but with PROPSETFLAG_ANSI */ hr = StgCreateDocfile(fileName, STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE, 0, &storage); ok(hr == S_OK, "StgCreateDocfile failed: 0x%08x\n", hr); hr = pStgCreatePropSetStg(storage, 0, &propSetStorage); ok(hr == S_OK, "StgCreatePropSetStg failed: 0x%08x\n", hr); hr = IPropertySetStorage_Create(propSetStorage, &FMTID_SummaryInformation, NULL, PROPSETFLAG_ANSI, STGM_READWRITE | STGM_CREATE | STGM_SHARE_EXCLUSIVE, &propertyStorage); ok(hr == S_OK, "IPropertySetStorage_Create failed: 0x%08x\n", hr); /* check code page before it's been explicitly set */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I2, "Didn't get expected type for property (%u)\n", var.vt); /* Set code page to Unicode */ U(var).iVal = 1200; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* check code page */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_I2 && U(var).iVal == 1200, "Didn't get expected type or value for property\n"); /* This test is commented out for documentation. It fails under Wine, * and I expect it would under Windows as well, yet it succeeds. There's * obviously something about string conversion I don't understand. */ if(0) { static unsigned char strVal[] = { 0x81, 0xff, 0x04, 0 }; /* Set code page to 950 (Traditional Chinese) */ U(var).iVal = 950; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* Try writing an invalid string: lead byte 0x81 is unused in Traditional * Chinese. */ spec.ulKind = PRSPEC_PROPID; U(spec).propid = PID_FIRST_USABLE; var.vt = VT_LPSTR; U(var).pszVal = (LPSTR)strVal; hr = IPropertyStorage_WriteMultiple(propertyStorage, 1, &spec, &var, 0); ok(hr == S_OK, "WriteMultiple failed: 0x%08x\n", hr); /* Check returned string */ hr = IPropertyStorage_ReadMultiple(propertyStorage, 1, &spec, &var); ok(hr == S_OK, "ReadMultiple failed: 0x%08x\n", hr); ok(var.vt == VT_LPSTR && !strcmp(U(var).pszVal, (LPCSTR)strVal), "Didn't get expected type or value for property\n"); } IPropertyStorage_Release(propertyStorage); IPropertySetStorage_Release(propSetStorage); IStorage_Release(storage); DeleteFileW(fileName); }
static void test_create_database_binary(void) { static const CLSID CLSID_MsiDatabase = { 0xc1084, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46 } }; static const CLSID IID_IPropertySetStorage = { 0x13a, 0, 0, {0xc0, 0, 0, 0, 0, 0, 0, 0x46 } }; static const CLSID FMTID_SummaryInformation = { 0xf29f85e0, 0x4ff9, 0x1068, {0xab, 0x91, 0x08, 0x00, 0x2b, 0x27, 0xb3, 0xd9}}; DWORD mode = STGM_CREATE | STGM_READWRITE | STGM_DIRECT | STGM_SHARE_EXCLUSIVE; static const WCHAR msifile[] = { 'w','i','n','e','t','e','s','t','.','m','s','i',0 }; IPropertySetStorage *pss = NULL; IPropertyStorage *ps = NULL; IStorage *stg = NULL; IStream *stm = NULL; HRESULT r; PROPSPEC propspec[10]; PROPVARIANT propvar[10]; USHORT data[2] = { 0, 0 }; r = StgCreateDocfile( msifile, mode, 0, &stg ); ok( r == S_OK, "failed to create database\n"); r = IStorage_SetClass( stg, &CLSID_MsiDatabase ); ok( r == S_OK, "failed to set clsid\n"); /* create the _StringData stream */ r = IStorage_CreateStream( stg, sd, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm ); ok( r == S_OK, "failed to create stream\n"); IStream_Release( stm ); /* create the _StringPool stream */ r = IStorage_CreateStream( stg, sp, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm ); ok( r == S_OK, "failed to create stream\n"); r = IStream_Write( stm, data, sizeof data, NULL ); ok( r == S_OK, "failed to write stream\n"); IStream_Release( stm ); /* create the _Tables stream */ r = IStorage_CreateStream( stg, tb, STGM_WRITE | STGM_SHARE_EXCLUSIVE, 0, 0, &stm ); ok( r == S_OK, "failed to create stream\n"); IStream_Release( stm ); r = IStorage_QueryInterface( stg, &IID_IPropertySetStorage, (void**) &pss ); ok( r == S_OK, "failed to set clsid\n"); r = IPropertySetStorage_Create( pss, &FMTID_SummaryInformation, NULL, 0, mode, &ps ); ok( r == S_OK, "failed to create property set\n"); r = IPropertyStorage_SetClass( ps, &FMTID_SummaryInformation ); ok( r == S_OK, "failed to set class\n"); propspec[0].ulKind = PRSPEC_PROPID; U(propspec[0]).propid = PID_TITLE; propvar[0].vt = VT_LPSTR; U(propvar[0]).pszVal = LOSE_CONST("test title"); propspec[1].ulKind = PRSPEC_PROPID; U(propspec[1]).propid = PID_SUBJECT; propvar[1].vt = VT_LPSTR; U(propvar[1]).pszVal = LOSE_CONST("msi suminfo / property storage test"); propspec[2].ulKind = PRSPEC_PROPID; U(propspec[2]).propid = PID_AUTHOR; propvar[2].vt = VT_LPSTR; U(propvar[2]).pszVal = LOSE_CONST("mike_m"); propspec[3].ulKind = PRSPEC_PROPID; U(propspec[3]).propid = PID_TEMPLATE; propvar[3].vt = VT_LPSTR; U(propvar[3]).pszVal = LOSE_CONST(";1033"); /* actually the string table's codepage */ propspec[4].ulKind = PRSPEC_PROPID; U(propspec[4]).propid = PID_REVNUMBER; propvar[4].vt = VT_LPSTR; U(propvar[4]).pszVal = LOSE_CONST("{913B8D18-FBB6-4CAC-A239-C74C11E3FA74}"); propspec[5].ulKind = PRSPEC_PROPID; U(propspec[5]).propid = PID_PAGECOUNT; propvar[5].vt = VT_I4; U(propvar[5]).lVal = 100; propspec[6].ulKind = PRSPEC_PROPID; U(propspec[6]).propid = PID_WORDCOUNT; propvar[6].vt = VT_I4; U(propvar[6]).lVal = 0; /* MSDN says that PID_LASTPRINTED should be a VT_FILETIME... */ propspec[7].ulKind = PRSPEC_PROPID; U(propspec[7]).propid = PID_LASTPRINTED; propvar[7].vt = VT_LPSTR; U(propvar[7]).pszVal = LOSE_CONST("7/1/1999 5:17"); r = IPropertyStorage_WriteMultiple( ps, 8, propspec, propvar, PID_FIRST_USABLE ); ok( r == S_OK, "failed to write properties\n"); IPropertyStorage_Commit( ps, STGC_DEFAULT ); IPropertyStorage_Release( ps ); IPropertySetStorage_Release( pss ); IStorage_Commit( stg, STGC_DEFAULT ); IStorage_Release( stg ); }
void SaveMsg2File(){ ULONG cbStrSize = 0L; LPWSTR lpWideCharStr = NULL; wchar_t szPath[_MAX_PATH]; // get temp file directory GetTempPath(_MAX_PATH, szPath); #ifdef MAPI32_W wcscat_s(szPath, L"Correct.msg"); #else wcscat_s(szPath, L"Garbage.msg"); #endif IStorage *pStorage = NULL; LPMSGSESS pMsgSession = NULL; LPMESSAGE pMessage = NULL; HRESULT hr = S_OK; //LPWSTR subject = L"テスト日本の";// L"ceshi测试12"; //LPWSTR body = L"テスト日本のテスト日本の"; // L"lhy测试12"; //LPWSTR receipt = L"*****@*****.**"; LPWSTR subject = L"Η πολιτική αβεβαιότητα ανησυχεί τις αγορές";// L"ceshi测试12"; LPWSTR body = L"Η πολιτική αβεβαιότητα ανησυχεί τις αγορές"; // L"lhy测试12"; LPWSTR receipt = L"*****@*****.**"; LPSTR subjectA = ConvertUnicode2Ansi(subject); LPSTR bodyA = ConvertUnicode2Ansi(body); LPSTR receiptA = ConvertUnicode2Ansi(receipt); //LPSTR subjectA = "ceshi测试12"; //LPSTR bodyA = "lhy测试12"; //LPSTR receiptA = "*****@*****.**"; do{ MAPIINIT_0 mapiInit = { 0, MAPI_MULTITHREAD_NOTIFICATIONS }; hr = MAPIInitialize(&mapiInit); DEFINE_IF_HR_NT_OK_BREAK(hr); LPMALLOC pMalloc = MAPIGetDefaultMalloc(); hr = StgCreateDocfile(szPath, STGM_READWRITE | STGM_TRANSACTED | STGM_CREATE, 0, &pStorage); DEFINE_IF_HR_NT_OK_BREAK(hr); hr = OpenIMsgSession(pMalloc, 0, &pMsgSession); DEFINE_IF_HR_NT_OK_BREAK(hr); #ifdef MAPI32_W // lhy comment:if load exmapi32.dll, this function will failed with error code 0x80040106. hr = OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, MAPI_UNICODE, &pMessage); #else hr = OpenIMsgOnIStg(pMsgSession, MAPIAllocateBuffer, MAPIAllocateMore, MAPIFreeBuffer, pMalloc, NULL, pStorage, NULL, 0, 0, &pMessage); #endif DEFINE_IF_HR_NT_OK_BREAK(hr); hr = WriteClassStg(pStorage, CLSID_MailMessage); DEFINE_IF_HR_NT_OK_BREAK(hr); #ifdef MAPI32_W hr = SetPropsW(pMessage, subject, body, receipt, false, false, false, false, FORCE_SAVE); #else hr = SetPropsA(pMessage, subjectA, bodyA, receiptA, false, false, false, false, FORCE_SAVE); #endif DEFINE_IF_HR_NT_OK_BREAK(hr); hr = pStorage->Commit(STGC_DEFAULT); DEFINE_IF_HR_NT_OK_BREAK(hr); } while (0); delete subjectA; delete bodyA; delete receiptA; if (pMessage){ pMessage->Release(); pMessage = NULL; } if (pStorage){ pStorage->Release(); pStorage = NULL; } if (pMsgSession){ CloseIMsgSession(pMsgSession); pMsgSession = NULL; } MAPIUninitialize(); }
UINT tOleHandler::Create(LPVOID pvType) { HRESULT hr; LPUNKNOWN pObj; UINT uRet=CREATE_GRAPHICONLY; DWORD dwMode=STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE; IPersistStorage *persist_storage = NULL; StgCreateDocfile(NULL, dwMode, 0, &m_pIStorage); if(m_pIStorage == NULL) return CREATE_FAILED; if (NULL==pvType) return CREATE_FAILED; hr=ResultFromScode(E_FAIL); Open(NULL); //CHAPTER24MOD /* * The OLE Control specifications mention that a * a control might implement IPersistStream[Init] * instead of IPersistStorage. In that case you * cannot use OleCreate on a control but must rather * use CoCreateInstance since OleCreate assumes * that IPersistStorage is available. With a control, * you would have to create the object first, then * check if OLEMISC_SETCLIENTSITEFIRST is set, then * send it your IOleClientSite first. Then you check * for IPersistStorage and failing that, try * IPersistStream[Init]. * * For simplicity we'll assume storage-based * controls in this sample. */ //End CHAPTER24MOD hr = CoCreateInstance(*((LPCLSID)pvType), NULL, CLSCTX_ALL, IID_IUnknown, (LPVOID *)&pObj); if(FAILED(hr)) return CREATE_FAILED; if(pObj->QueryInterface(IID_IPersistStorage, (void **) &persist_storage) != S_OK) return CREATE_FAILED; //We need an IOleObject most of the time, so get one here. m_pIOleObject=NULL; hr = pObj->QueryInterface(IID_IOleObject, (LPVOID*)&m_pIOleObject); if(FAILED(hr)) return CREATE_FAILED; // seta o client site m_pIOleObject->SetClientSite(m_pImpIOleClientSite); // inicializa o objeto hr = persist_storage->InitNew(m_pIStorage); if(FAILED(hr)) return CREATE_FAILED; //We don't get the size if PatronObject data was seen already. if (!ObjectInitialize(pObj)) { return CREATE_FAILED; } SIZEL szl; hr=ResultFromScode(E_FAIL); CalcNaturalSize(); //CHAPTER24MOD //Make sure this happens /*if ((OLEMISC_ACTIVATEWHENVISIBLE & m_grfMisc)) Activate(OLEIVERB_INPLACEACTIVATE, NULL);*/ //End CHAPTER24MOD return uRet; }
BOOL COleDocument::OnOpenDocument(LPCTSTR lpszPathName) { ASSERT(lpszPathName == NULL || AfxIsValidString(lpszPathName)); // just use default implementation if 'docfile' not enabled if (!m_bCompoundFile && m_lpRootStg == NULL) { ASSERT(lpszPathName != NULL); return CDocument::OnOpenDocument(lpszPathName); } if (IsModified()) TRACE(traceOle, 0, "Warning: OnOpenDocument replaces an unsaved document.\n"); // abort changes to current docfile if (lpszPathName != NULL) { DeleteContents(); RELEASE(m_lpRootStg); } SetModifiedFlag(); // dirty during de-serialize BOOL bResult = FALSE; TRY { if (m_lpRootStg == NULL) { const CStringW strPathName(lpszPathName); LPCOLESTR lpsz = lpszPathName ? strPathName.GetString() : NULL; // use STGM_CONVERT if necessary SCODE sc; LPSTORAGE lpStorage = NULL; if (StgIsStorageFile(lpsz) == S_FALSE) { // convert existing storage file sc = StgCreateDocfile(lpsz, STGM_READWRITE| STGM_TRANSACTED|STGM_SHARE_DENY_WRITE|STGM_CONVERT, 0, &lpStorage); } else { // open new storage file sc = StgOpenStorage(lpsz, NULL, STGM_READWRITE|STGM_TRANSACTED|STGM_SHARE_DENY_WRITE, 0, 0, &lpStorage); if (FAILED(sc) || lpStorage == NULL) sc = StgOpenStorage(lpsz, NULL, STGM_READ|STGM_TRANSACTED, 0, 0, &lpStorage); } if (FAILED(sc)) AfxThrowOleException(sc); ASSERT(lpStorage != NULL); m_lpRootStg = lpStorage; } // use helper to read document from storage LoadFromStorage(); SetModifiedFlag(FALSE); // start off with unmodified bResult = TRUE; } CATCH_ALL(e) { DeleteContents(); // removed failed contents RELEASE(m_lpRootStg); // if not file-based load, return exceptions to the caller if (lpszPathName == NULL) { THROW_LAST(); } TRY { ReportSaveLoadException(lpszPathName, e, FALSE, AFX_IDP_FAILED_TO_OPEN_DOC); } END_TRY DELETE_EXCEPTION(e); } END_CATCH_ALL return bResult; }
UINT MSI_OpenDatabaseW(LPCWSTR szDBPath, LPCWSTR szPersist, MSIDATABASE **pdb) { IStorage *stg = NULL; HRESULT r; MSIDATABASE *db = NULL; UINT ret = ERROR_FUNCTION_FAILED; LPCWSTR szMode; STATSTG stat; TRACE("%s %s\n",debugstr_w(szDBPath),debugstr_w(szPersist) ); if( !pdb ) return ERROR_INVALID_PARAMETER; szMode = szPersist; if( HIWORD( szPersist ) ) { /* UINT len = lstrlenW( szPerist ) + 1; */ FIXME("don't support persist files yet\b"); return ERROR_INVALID_PARAMETER; /* szMode = msi_alloc( len * sizeof (DWORD) ); */ } else if( szPersist == MSIDBOPEN_READONLY ) { r = StgOpenStorage( szDBPath, NULL, STGM_DIRECT|STGM_READ|STGM_SHARE_DENY_WRITE, NULL, 0, &stg); } else if( szPersist == MSIDBOPEN_CREATE || szPersist == MSIDBOPEN_CREATEDIRECT ) { /* FIXME: MSIDBOPEN_CREATE should case STGM_TRANSACTED flag to be * used here: */ r = StgCreateDocfile( szDBPath, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, 0, &stg); if( r == ERROR_SUCCESS ) { IStorage_SetClass( stg, &CLSID_MsiDatabase ); r = init_string_table( stg ); } } else if( szPersist == MSIDBOPEN_TRANSACT ) { /* FIXME: MSIDBOPEN_TRANSACT should case STGM_TRANSACTED flag to be * used here: */ r = StgOpenStorage( szDBPath, NULL, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg); } else if( szPersist == MSIDBOPEN_DIRECT ) { r = StgOpenStorage( szDBPath, NULL, STGM_DIRECT|STGM_READWRITE|STGM_SHARE_EXCLUSIVE, NULL, 0, &stg); } else { ERR("unknown flag %p\n",szPersist); return ERROR_INVALID_PARAMETER; } if( FAILED( r ) ) { FIXME("open failed r = %08lx!\n",r); return ERROR_FUNCTION_FAILED; } r = IStorage_Stat( stg, &stat, STATFLAG_NONAME ); if( FAILED( r ) ) { FIXME("Failed to stat storage\n"); goto end; } if ( !IsEqualGUID( &stat.clsid, &CLSID_MsiDatabase ) && !IsEqualGUID( &stat.clsid, &CLSID_MsiPatch ) ) { ERR("storage GUID is not a MSI database GUID %s\n", debugstr_guid(&stat.clsid) ); goto end; } db = alloc_msiobject( MSIHANDLETYPE_DATABASE, sizeof (MSIDATABASE), MSI_CloseDatabase ); if( !db ) { FIXME("Failed to allocate a handle\n"); goto end; } if( TRACE_ON( msi ) ) enum_stream_names( stg ); db->storage = stg; db->mode = szMode; list_init( &db->tables ); list_init( &db->transforms ); db->strings = load_string_table( stg ); if( !db->strings ) goto end; ret = ERROR_SUCCESS; msiobj_addref( &db->hdr ); IStorage_AddRef( stg ); *pdb = db; end: if( db ) msiobj_release( &db->hdr ); if( stg ) IStorage_Release( stg ); return ret; }
//设置关系 tagCompanionInfo * CUserInformation::InsertCompanionInfo(IClientUserItem * pIClientUserItem, BYTE cbCompanion) { //效验参数 ASSERT(pIClientUserItem!=NULL); if (pIClientUserItem==NULL) return NULL; //用户搜索 DWORD dwUserID=pIClientUserItem->GetUserID(); tagCompanionInfo * pCompanionInfo=SearchCompanionInfo(dwUserID); //设置信息 if (pCompanionInfo==NULL) { //创建对象 pCompanionInfo=CreateCompanionItem(); if (pCompanionInfo==NULL) return NULL; //设置信息 pCompanionInfo->cbCompanion=cbCompanion; pCompanionInfo->dwGameID=pIClientUserItem->GetGameID(); pCompanionInfo->dwUserID=pIClientUserItem->GetUserID(); lstrcpyn(pCompanionInfo->szNickName,pIClientUserItem->GetNickName(),CountArray(pCompanionInfo->szNickName)); lstrcpyn(pCompanionInfo->szUserNote,pIClientUserItem->GetUserNoteInfo(),CountArray(pCompanionInfo->szUserNote)); //插入通知 if (m_pIUserCompanionSink!=NULL) m_pIUserCompanionSink->OnCompanionInsert(pCompanionInfo); } else { //修改判断 bool bModify=false; if (pCompanionInfo->cbCompanion!=cbCompanion) bModify=true; if ((bModify==false)&&(lstrcmp(pCompanionInfo->szNickName,pIClientUserItem->GetNickName())!=0)) bModify=true; if ((bModify==false)&&(lstrcmp(pCompanionInfo->szUserNote,pIClientUserItem->GetUserNoteInfo())!=0)) bModify=true; //修改判断 if (bModify=false) return pCompanionInfo; //设置信息 pCompanionInfo->cbCompanion=cbCompanion; pCompanionInfo->dwGameID=pIClientUserItem->GetGameID(); pCompanionInfo->dwUserID=pIClientUserItem->GetUserID(); lstrcpyn(pCompanionInfo->szNickName,pIClientUserItem->GetNickName(),CountArray(pCompanionInfo->szNickName)); lstrcpyn(pCompanionInfo->szUserNote,pIClientUserItem->GetUserNoteInfo(),CountArray(pCompanionInfo->szUserNote)); //更新通知 if (m_pIUserCompanionSink!=NULL) m_pIUserCompanionSink->OnCompanionUpdate(pCompanionInfo); } //变量定义 IStream * pIStreamSub=NULL; IStorage * pIStorageSub=NULL; IStorage * pIStorageRoot=NULL; //写入数据 try { //构造名字 WCHAR szStorageName[16]=L""; _snwprintf(szStorageName,CountArray(szStorageName),L"%ld",dwUserID); //工作目录 TCHAR szDirectory[MAX_PATH]=TEXT(""); CWHService::GetWorkDirectory(szDirectory,CountArray(szDirectory)); //打开文件 WCHAR szInfomationFile[MAX_PATH]=L""; _snwprintf(szInfomationFile,CountArray(szInfomationFile),L"%s\\%s",(LPCWSTR)(CT2CW(szDirectory)),INFORMATION_FILE); //打开文件 StgOpenStorage(szInfomationFile,NULL,STGM_READWRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageRoot); if (pIStorageRoot==NULL) StgCreateDocfile(szInfomationFile,STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE,0,&pIStorageRoot); //错误判断 if (pIStorageRoot==NULL) throw TEXT("StgCreateDocfile Create pIStorageRoot Error"); //打开存储 pIStorageRoot->CreateStorage(szStorageName,STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageSub); if (pIStorageSub==NULL) pIStorageRoot->CreateStorage(szStorageName,STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStorageSub); //错误处理 if (pIStorageSub==NULL) throw TEXT("CreateStorage Create pIStorageSub Error"); //创建数据 pIStorageSub->CreateStream(STREAM_COMPANION,STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStreamSub); if (pIStreamSub==NULL) pIStorageSub->CreateStream(STREAM_COMPANION,STGM_CREATE|STGM_WRITE|STGM_SHARE_EXCLUSIVE,0,0,&pIStreamSub); //错误处理 if (pIStreamSub==NULL) throw TEXT("CreateStream Create pIStreamSub Error"); //写入数据 ULONG cbWriteCount=0L; pIStreamSub->Write(pCompanionInfo,sizeof(tagCompanionInfo),&cbWriteCount); //释放接口 SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); SafeRelease(pIStorageRoot); return pCompanionInfo; } catch (...) { //错误断言 ASSERT(FALSE); //释放接口 SafeRelease(pIStreamSub); SafeRelease(pIStorageSub); SafeRelease(pIStorageRoot); } return NULL; }