Ejemplo n.º 1
0
int PolylineTest::writeFileMoniker()
{
	ComPtr<IMoniker> moniker;
	auto hr = CreateFileMoniker(kFileName, &moniker);
	if (FAILED(hr)) {
		return -1;
	}
	IBindCtx* pbc;
	CreateBindCtx(0, &pbc);
	ComPtr<IPolyline> polyline;
	hr = moniker->BindToObject(pbc, NULL, IID_IPolyline, (void**)&polyline);
	if (FAILED(hr)) {
		return -1;
	}
	polyline->put_Color(RGB(0xff, 0x00, 0x00));
	COLORREF value;
	polyline->get_Color(&value);
	assert(value == RGB(0xff, 0x00, 0x00));

	ComPtr<IStorage> pStorage;
	ComPtr<IStream> pStream;
	hr = StgCreateStorageEx(kMonikerFileName, STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		STGFMT_STORAGE, 0, NULL, 0, IID_IStorage, (void**)&pStorage);
	if (FAILED(hr))
		return hr;
	hr = pStorage->CreateStream(kStreamName, STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		0, 0, &pStream);
	if (FAILED(hr))
		return hr;
	OleSaveToStream(moniker, pStream);
	return 0;
}
Ejemplo n.º 2
0
int BookServerTest::createFileMoniker()
{
	ComPtr<IMoniker> moniker;
	auto hr = CreateFileMoniker(kFileName, &moniker);
	if (FAILED(hr)) {
		return -1;
	}
	IBindCtx* pbc;
	CreateBindCtx(0, &pbc);
	ComPtr<IBook> book;
	hr = moniker->BindToObject(pbc, NULL, IID_IBook, (void**)&book);
	if (FAILED(hr)) {
		return -1;
	}
	ComPtr<IStorage> pStorage;
	ComPtr<IStream> pStream;
	hr = StgCreateStorageEx(kMonikerFileName, STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		STGFMT_STORAGE, 0, NULL, 0, IID_IStorage, (void**)&pStorage);
	if (FAILED(hr))
		return hr;
	hr = pStorage->CreateStream(kStreamName, STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		0, 0, &pStream);
	if (FAILED(hr))
		return hr;
	OleSaveToStream(moniker, pStream);
	return 0;
}
Ejemplo n.º 3
0
void CompleteAutoSave(HANDLE hEvent, LPARAM lParam)
	{
	AutoSavePackage *pasp = (AutoSavePackage *)lParam;

	FastIStorage *pstgroot = pasp->pstg;

	IStorage *pstgDisk;

	WCHAR *wzSaveName = L"AutoSave";
	WCHAR *wzSaveExtension = L".vpx";
	WCHAR wzSuffix[32];
	_itow_s(pasp->tableindex, wzSuffix, sizeof(wzSuffix)/sizeof(WCHAR), 10);

	WCHAR * const wzT = new WCHAR[MAX_PATH + 32 + lstrlenW(wzSaveName) + lstrlenW(wzSaveExtension)+ 1];

	WideStrCopy(g_pvp->m_wzMyPath, wzT);
	WideStrCat(wzSaveName, wzT);
	WideStrCat(wzSuffix, wzT);
	WideStrCat(wzSaveExtension, wzT);
	
	//MAKE_WIDEPTR_FROMANSI(wszCodeFile, m_szFileName);

	STGOPTIONS stg;
	stg.usVersion = 1;
	stg.reserved = 0;
	stg.ulSectorSize = 4096;

	HRESULT hr;
	if(SUCCEEDED(hr = StgCreateStorageEx(wzT, STGM_TRANSACTED | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		STGFMT_DOCFILE, 0, &stg, 0, IID_IStorage, (void**)&pstgDisk)))
		{
		pstgroot->CopyTo(0, NULL, NULL, pstgDisk);
		hr = pstgDisk->Commit(STGC_DEFAULT);
		pstgDisk->Release();
		}

	pstgroot->Release();

	SetEvent(hEvent);

	PostMessage(pasp->HwndTable, DONE_AUTOSAVE, (WPARAM)hEvent, hr);

	delete [] wzT;
	delete pasp;
	}
Ejemplo n.º 4
0
int
CreateStore(wchar_t* filename, IStorage** out)
{
    int res;

    assert(filename != NULL);
    assert(out != NULL);

    (int)fprintf(stderr, "Creating store %S\n", filename);
    res = StgCreateStorageEx(
        filename,
        STGM_CREATE | STGM_FAILIFTHERE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE,
        STGFMT_STORAGE,
        0, NULL, NULL, &IID_IStorage,
        out
    );
    return (res == S_OK)? 1 : 0;
}
Ejemplo n.º 5
0
int PolylineTest::writeCompoundFile()
{
	ComPtr<IStorage> pStorage;
	ComPtr<IStream> pStream;
	auto hr = StgCreateStorageEx(kFileName, STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		STGFMT_STORAGE, 0, NULL, 0, IID_IStorage, (void**)&pStorage);
	if (FAILED(hr))
		return hr;
	hr = pStorage->CreateStream(kStreamName, STGM_WRITE | STGM_SHARE_EXCLUSIVE | STGM_CREATE,
		0, 0, &pStream);
	if (FAILED(hr))
		return hr;

	ULARGE_INTEGER ui;
	ui.QuadPart = 10;
	pStream->SetSize(ui);
	ULONG cb;
	hr = pStream->Write(kData, sizeof(int) * _countof(kData), &cb);
	if (FAILED(hr))
		return hr;
	pStorage->Commit(STGC_OVERWRITE);
	return 0;
}
Ejemplo n.º 6
0
static InternetShortcut *create_shortcut(void)
{
    InternetShortcut *newshortcut;

    newshortcut = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(InternetShortcut));
    if (newshortcut)
    {
        HRESULT hr;
        IPropertyStorage *dummy;

        newshortcut->IUniformResourceLocatorA_iface.lpVtbl = &uniformResourceLocatorAVtbl;
        newshortcut->IUniformResourceLocatorW_iface.lpVtbl = &uniformResourceLocatorWVtbl;
        newshortcut->IPersistFile_iface.lpVtbl = &persistFileVtbl;
        newshortcut->IPropertySetStorage_iface.lpVtbl = &propertySetStorageVtbl;
        newshortcut->refCount = 1;
        hr = StgCreateStorageEx(NULL, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_DELETEONRELEASE,
                                STGFMT_STORAGE, 0, NULL, NULL, &IID_IPropertySetStorage, (void **) &newshortcut->property_set_storage);
        if (FAILED(hr))
        {
            TRACE("Failed to create the storage object needed for the shortcut.\n");
            heap_free(newshortcut);
            return NULL;
        }

        hr = IPropertySetStorage_Create(newshortcut->property_set_storage, &FMTID_Intshcut, NULL, PROPSETFLAG_DEFAULT, STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE, &dummy);
        if (FAILED(hr))
        {
            TRACE("Failed to create the property object needed for the shortcut.\n");
            IPropertySetStorage_Release(newshortcut->property_set_storage);
            heap_free(newshortcut);
            return NULL;
        }
        IPropertyStorage_Release(dummy);
    }

    return newshortcut;
}
Ejemplo n.º 7
0
int
SaveStream(IStorage* storage, int index, FILE* out)
{
    int res; ULONG bytesread;
    STATSTG st;

    IStream* stream;

    IStorage* temporary; IStorage* source;
    FILE* in;

    LARGE_INTEGER li;
    (void)memset(&li, 0, sizeof(li));

    res = GetStreamType(storage,index,&st.type);
    if (res == 0)
        return 0;

    if (st.type == STGTY_STREAM) {
        fprintf(stderr, "Fetching stream\n");
        res = GetStream(storage, index, &stream);
    } else if (st.type == STGTY_STORAGE) {
        fprintf(stderr, "Fetching store\n");
        res = GetStorage(storage, index, &source);
    } else {
        fprintf(stderr, "Fetching unknown %x\n", st.type);
        res = 0;
    }
    if (res == 0)
        return 0;

    switch(st.type) {
    case STGTY_STREAM:
        fprintf(stderr, "Seeking to beginning of stream\n");
        (HRESULT)stream->lpVtbl->Seek(stream, li, STREAM_SEEK_SET, NULL);

        fprintf(stderr, "Writing to file\n");
        /* write stream to file */
        for (;;) {
            res = stream->lpVtbl->Read(stream, g_TransferBuffer, sizeof(g_TransferBuffer), &bytesread);
            if (res != S_OK) { res = 1; goto stream_release; }
            (size_t)fwrite(g_TransferBuffer, 1, bytesread, out);
            if (bytesread < sizeof(g_TransferBuffer))
                break;
        }
        res = 1;
        fprintf(stderr, "Done\n");

stream_release:
        (ULONG)stream->lpVtbl->Release(stream);
        break;

    case STGTY_STORAGE:
        fprintf(stderr, "Creating temporary storage on disk\n");
        res = StgCreateStorageEx(NULL, STGM_CREATE|STGM_READWRITE|STGM_SHARE_EXCLUSIVE|STGM_DELETEONRELEASE, STGFMT_STORAGE, 0, NULL, NULL, &IID_IStorage, &temporary);
        if (res != S_OK) { res = 0; goto source_release; }

        fprintf(stderr, "Copying store to temporary storage\n");
        res = source->lpVtbl->CopyTo(source, 0, NULL, NULL, temporary);
        if (res != S_OK) { res = 0; goto temporary_release; }

        res = source->lpVtbl->Commit(source, STGC_DEFAULT);
        if (res != S_OK) { res = 0; goto temporary_release; }

        fprintf(stderr, "Getting temporary storage filename\n");
        res = temporary->lpVtbl->Stat(temporary, &st, STATFLAG_DEFAULT);
        if (res != S_OK) { res = 0; goto temporary_release; }

        fprintf(stderr, "Opening temporary storage %S\n", st.pwcsName);
        in = _wfopen(st.pwcsName, L"rb");
        if (in == NULL) { res = 0; goto temporary_release; }

        fprintf(stderr, "Writing to file\n");
        for (;;) {
            bytesread = fread(&g_TransferBuffer, 1, sizeof(g_TransferBuffer), in);
            (size_t)fwrite(g_TransferBuffer, 1, bytesread, out);
            if (bytesread < sizeof(g_TransferBuffer))
                break;
        }
        fclose(in);

        res = 1;
        fprintf(stderr, "Done\n");

temporary_release:
        temporary->lpVtbl->Release(temporary);
source_release:
        source->lpVtbl->Release(source);
        break;
    }
    return res;
}