propsys: Implement PSStringFromPropertyKey.
[wine.git] / dlls / propsys / propsys_main.c
blobcd180fe0993b6257924e37331c064ed89419b801
1 /*
2 * propsys main
4 * Copyright 2008 James Hawkins
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "config.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "objbase.h"
28 #include "propsys.h"
29 #include "wine/debug.h"
30 #include "wine/unicode.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(propsys);
34 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
36 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
38 switch (fdwReason)
40 case DLL_WINE_PREATTACH:
41 return FALSE; /* prefer native version */
42 case DLL_PROCESS_ATTACH:
43 DisableThreadLibraryCalls(hinstDLL);
44 break;
45 case DLL_PROCESS_DETACH:
46 break;
47 default:
48 break;
51 return TRUE;
54 HRESULT WINAPI PSRegisterPropertySchema(PCWSTR path)
56 FIXME("%s stub\n", debugstr_w(path));
58 return S_OK;
61 HRESULT WINAPI PSUnregisterPropertySchema(PCWSTR path)
63 FIXME("%s stub\n", debugstr_w(path));
65 return E_NOTIMPL;
68 HRESULT WINAPI PSStringFromPropertyKey(REFPROPERTYKEY pkey, LPWSTR psz, UINT cch)
70 static const WCHAR guid_fmtW[] = {'{','%','0','8','X','-','%','0','4','X','-',
71 '%','0','4','X','-','%','0','2','X','%','0','2','X','-',
72 '%','0','2','X','%','0','2','X','%','0','2','X',
73 '%','0','2','X','%','0','2','X','%','0','2','X','}',0};
74 static const WCHAR pid_fmtW[] = {'%','u',0};
76 WCHAR pidW[PKEY_PIDSTR_MAX + 1];
77 LPWSTR p = psz;
78 int len;
80 TRACE("(%p, %p, %u)\n", pkey, psz, cch);
82 if (!psz)
83 return E_POINTER;
85 /* GUIDSTRING_MAX accounts for null terminator, +1 for space character. */
86 if (cch <= GUIDSTRING_MAX + 1)
87 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
89 if (!pkey)
91 psz[0] = '\0';
92 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);
95 sprintfW(psz, guid_fmtW, pkey->fmtid.Data1, pkey->fmtid.Data2,
96 pkey->fmtid.Data3, pkey->fmtid.Data4[0], pkey->fmtid.Data4[1],
97 pkey->fmtid.Data4[2], pkey->fmtid.Data4[3], pkey->fmtid.Data4[4],
98 pkey->fmtid.Data4[5], pkey->fmtid.Data4[6], pkey->fmtid.Data4[7]);
100 /* Overwrite the null terminator with the space character. */
101 p += GUIDSTRING_MAX - 1;
102 *p++ = ' ';
103 cch -= GUIDSTRING_MAX - 1 + 1;
105 len = sprintfW(pidW, pid_fmtW, pkey->pid);
107 if (cch >= len + 1)
109 strcpyW(p, pidW);
110 return S_OK;
112 else
114 WCHAR *ptr = pidW + len - 1;
116 psz[0] = '\0';
117 *p++ = '\0';
118 cch--;
120 /* Replicate a quirk of the native implementation where the contents
121 * of the property ID string are written backwards to the output
122 * buffer, skipping the rightmost digit. */
123 if (cch)
125 ptr--;
126 while (cch--)
127 *p++ = *ptr--;
130 return HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER);