1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
/*
* w32oo: collection of Win32-specific functions that require a C++ (OO)
* compilation.
*
* Caveats
* =======
* - Due to a conflict between estruct.h and MS names, the Windows macros
* "FAILED" may not be used to test an OLE return code. Use SUCCEEDED
* instead.
*
* $Header: /usr/build/vile/vile/RCS/w32oo.cpp,v 1.3 2001/09/18 09:49:29 tom Exp $
*/
#include "w32vile.h"
#include <ole2.h>
#include <shlobj.h>
#include <stdio.h>
extern "C" {
#include "estruct.h"
#include "edef.h"
/* ------------------------------------------------------------------------ */
/*
* Return path to favorites folder. don't know of any other way to do this
* than via COM ... a bit over the top, doncha' think?
*/
const char *
get_favorites(void)
{
char dir[FILENAME_MAX];
LPMALLOC pMalloc = NULL;
static char *path;
LPITEMIDLIST pidl = NULL;
HRESULT hr;
if (! path)
{
pMalloc = NULL;
pidl = NULL;
#ifndef VILE_OLE
hr = OleInitialize(NULL); /* Intialize OLE */
if (! SUCCEEDED(hr))
{
disp_win32_error(hr, NULL);
return (NULL);
}
#endif
hr = SHGetMalloc(&pMalloc);
if (! SUCCEEDED(hr))
{
disp_win32_error(hr, NULL);
#ifndef VILE_OLE
OleUninitialize();
#endif
return (NULL);
}
hr = SHGetSpecialFolderLocation(NULL, CSIDL_FAVORITES, &pidl);
if (! SUCCEEDED(hr))
{
disp_win32_error(hr, NULL);
pMalloc->Release();
#ifndef VILE_OLE
OleUninitialize();
#endif
return (NULL);
}
if (! SHGetPathFromIDList(pidl, dir))
{
disp_win32_error(W32_SYS_ERROR, NULL);
pMalloc->Release();
#ifndef VILE_OLE
OleUninitialize();
#endif
return (NULL);
}
bsl_to_sl_inplace(dir); /* Convert to canonical form */
path = strmalloc(dir);
if (pidl)
pMalloc->Free(pidl);
pMalloc->Release();
#ifndef VILE_OLE
OleUninitialize();
#endif
if (! path)
no_memory("get_favorites()");
}
return (path);
}
} /* Extern "C" */
|