From: Pat Thoyts Date: Wed, 2 Jan 2008 20:00:15 +0000 (+0000) Subject: Support creation of IStorage on memory by providing an empty filename X-Git-Url: https://privyetmir.co.uk/gitweb.cgi?a=commitdiff_plain;h=024b3ce839bc2028ee1faec8d4eb7a070240e8e6;p=tclstorage Support creation of IStorage on memory by providing an empty filename --- diff --git a/tclstorage.c b/tclstorage.c index e6240ca..6c4dca2 100644 --- a/tclstorage.c +++ b/tclstorage.c @@ -374,12 +374,25 @@ Storage_OpenStorage(ClientData clientData, Tcl_Interp *interp, } if (r == TCL_OK) { - if (mode & STGM_CREATE) - hr = StgCreateDocfile(Tcl_GetUnicode(objv[2]), - mode & STGM_WIN32MASK, 0, &pstg); - else + if (mode & STGM_CREATE) { + int cchFile = 0; + LPCWSTR wszFile = Tcl_GetUnicodeFromObj(objv[2], &cchFile); + if (cchFile < 1) { + ILockBytes *pLockBytes = NULL; + hr = CreateILockBytesOnHGlobal(NULL, TRUE, &pLockBytes); + if (SUCCEEDED(hr)) { + hr = StgCreateDocfileOnILockBytes(pLockBytes, + mode & STGM_WIN32MASK, 0, &pstg); + pLockBytes->lpVtbl->Release(pLockBytes); + } + } else { + hr = StgCreateDocfile(Tcl_GetUnicode(objv[2]), + mode & STGM_WIN32MASK, 0, &pstg); + } + } else { hr = StgOpenStorage(Tcl_GetUnicode(objv[2]), NULL, mode & STGM_WIN32MASK, NULL, 0, &pstg); + } if (SUCCEEDED(hr)) { r = CreateStorageCommand(interp, NULL, pstg, mode);