2 * MAPI Utility functions
4 * Copyright 2004 Jon Griffiths
5 * Copyright 2009 Owen Rudge for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #define NONAMELESSUNION
27 #define NONAMELESSSTRUCT
36 #include "wine/debug.h"
37 #include "wine/unicode.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(mapi);
45 static const BYTE digitsToHex[] = {
46 0,1,2,3,4,5,6,7,8,9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,10,11,12,13,14,15,
47 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
48 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,10,11,12,13,
51 MAPI_FUNCTIONS mapiFunctions;
53 /**************************************************************************
54 * ScInitMapiUtil (MAPI32.33)
56 * Initialise Mapi utility functions.
59 * ulReserved [I] Reserved, pass 0.
62 * Success: S_OK. Mapi utility functions may be called.
63 * Failure: MAPI_E_INVALID_PARAMETER, if ulReserved is not 0.
66 * Your application does not need to call this function unless it does not
67 * call MAPIInitialize()/MAPIUninitialize().
69 SCODE WINAPI ScInitMapiUtil(ULONG ulReserved)
71 FIXME("(0x%08x)stub!\n", ulReserved);
73 return MAPI_E_INVALID_PARAMETER;
77 /**************************************************************************
78 * DeinitMapiUtil (MAPI32.34)
80 * Uninitialise Mapi utility functions.
89 * Your application does not need to call this function unless it does not
90 * call MAPIInitialize()/MAPIUninitialize().
92 VOID WINAPI DeinitMapiUtil(void)
97 typedef LPVOID *LPMAPIALLOCBUFFER;
99 /**************************************************************************
100 * MAPIAllocateBuffer (MAPI32.12)
101 * MAPIAllocateBuffer@8 (MAPI32.13)
103 * Allocate a block of memory.
106 * cbSize [I] Size of the block to allocate in bytes
107 * lppBuffer [O] Destination for pointer to allocated memory
110 * Success: S_OK. *lppBuffer is filled with a pointer to a memory block of
111 * length cbSize bytes.
112 * Failure: MAPI_E_INVALID_PARAMETER, if lppBuffer is NULL.
113 * MAPI_E_NOT_ENOUGH_MEMORY, if the memory allocation fails.
116 * Memory allocated with this function should be freed with MAPIFreeBuffer().
117 * Further allocations of memory may be linked to the pointer returned using
118 * MAPIAllocateMore(). Linked allocations are freed when the initial pointer
121 SCODE WINAPI MAPIAllocateBuffer(ULONG cbSize, LPVOID *lppBuffer)
123 LPMAPIALLOCBUFFER lpBuff;
125 TRACE("(%d,%p)\n", cbSize, lppBuffer);
130 lpBuff = HeapAlloc(GetProcessHeap(), 0, cbSize + sizeof(*lpBuff));
132 return MAPI_E_NOT_ENOUGH_MEMORY;
134 TRACE("initial allocation:%p, returning %p\n", lpBuff, lpBuff + 1);
140 /**************************************************************************
141 * MAPIAllocateMore (MAPI32.14)
142 * MAPIAllocateMore@12 (MAPI32.15)
144 * Allocate a block of memory linked to a previous allocation.
147 * cbSize [I] Size of the block to allocate in bytes
148 * lpOrig [I] Initial allocation to link to, from MAPIAllocateBuffer()
149 * lppBuffer [O] Destination for pointer to allocated memory
152 * Success: S_OK. *lppBuffer is filled with a pointer to a memory block of
153 * length cbSize bytes.
154 * Failure: MAPI_E_INVALID_PARAMETER, if lpOrig or lppBuffer is invalid.
155 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
158 * Memory allocated with this function and stored in *lppBuffer is freed
159 * when lpOrig is passed to MAPIFreeBuffer(). It should not be freed independently.
161 SCODE WINAPI MAPIAllocateMore(ULONG cbSize, LPVOID lpOrig, LPVOID *lppBuffer)
163 LPMAPIALLOCBUFFER lpBuff = lpOrig;
165 TRACE("(%d,%p,%p)\n", cbSize, lpOrig, lppBuffer);
167 if (!lppBuffer || !lpBuff || !--lpBuff)
170 /* Find the last allocation in the chain */
173 TRACE("linked:%p->%p\n", lpBuff, *lpBuff);
177 if (SUCCEEDED(MAPIAllocateBuffer(cbSize, lppBuffer)))
179 *lpBuff = ((LPMAPIALLOCBUFFER)*lppBuffer) - 1;
180 TRACE("linking %p->%p\n", lpBuff, *lpBuff);
182 return *lppBuffer ? S_OK : MAPI_E_NOT_ENOUGH_MEMORY;
185 /**************************************************************************
186 * MAPIFreeBuffer (MAPI32.16)
187 * MAPIFreeBuffer@4 (MAPI32.17)
189 * Free a block of memory and any linked allocations associated with it.
192 * lpBuffer [I] Memory to free, returned from MAPIAllocateBuffer()
197 ULONG WINAPI MAPIFreeBuffer(LPVOID lpBuffer)
199 LPMAPIALLOCBUFFER lpBuff = lpBuffer;
201 TRACE("(%p)\n", lpBuffer);
203 if (lpBuff && --lpBuff)
207 LPVOID lpFree = lpBuff;
211 TRACE("linked:%p->%p, freeing %p\n", lpFree, lpBuff, lpFree);
212 HeapFree(GetProcessHeap(), 0, lpFree);
218 /**************************************************************************
219 * WrapProgress@20 (MAPI32.41)
221 HRESULT WINAPI WrapProgress(PVOID unk1, PVOID unk2, PVOID unk3, PVOID unk4, PVOID unk5)
223 /* Native does not implement this function */
224 return MAPI_E_NO_SUPPORT;
227 /*************************************************************************
228 * HrThisThreadAdviseSink@8 (MAPI32.42)
230 * Ensure that an advise sink is only notified in its originating thread.
233 * lpSink [I] IMAPIAdviseSink interface to be protected
234 * lppNewSink [I] Destination for wrapper IMAPIAdviseSink interface
237 * Success: S_OK. *lppNewSink contains a new sink to use in place of lpSink.
238 * Failure: E_INVALIDARG, if any parameter is invalid.
240 HRESULT WINAPI HrThisThreadAdviseSink(LPMAPIADVISESINK lpSink, LPMAPIADVISESINK* lppNewSink)
242 FIXME("(%p,%p)semi-stub\n", lpSink, lppNewSink);
244 if (!lpSink || !lppNewSink)
247 /* Don't wrap the sink for now, just copy it */
248 *lppNewSink = lpSink;
249 IMAPIAdviseSink_AddRef(lpSink);
253 /*************************************************************************
254 * FBinFromHex (MAPI32.44)
256 * Create an array of binary data from a string.
259 * lpszHex [I] String to convert to binary data
260 * lpOut [O] Destination for resulting binary data
263 * Success: TRUE. lpOut contains the decoded binary data.
264 * Failure: FALSE, if lpszHex does not represent a binary string.
267 * - lpOut must be at least half the length of lpszHex in bytes.
268 * - Although the Mapi headers prototype this function as both
269 * Ascii and Unicode, there is only one (Ascii) implementation. This
270 * means that lpszHex is treated as an Ascii string (i.e. a single NUL
271 * character in the byte stream terminates the string).
273 BOOL WINAPI FBinFromHex(LPWSTR lpszHex, LPBYTE lpOut)
275 LPSTR lpStr = (LPSTR)lpszHex;
277 TRACE("(%p,%p)\n", lpszHex, lpOut);
281 if (lpStr[0] < '0' || lpStr[0] > 'f' || digitsToHex[lpStr[0] - '0'] == 0xff ||
282 lpStr[1] < '0' || lpStr[1] > 'f' || digitsToHex[lpStr[1] - '0'] == 0xff)
285 *lpOut++ = (digitsToHex[lpStr[0] - '0'] << 4) | digitsToHex[lpStr[1] - '0'];
291 /*************************************************************************
292 * HexFromBin (MAPI32.45)
294 * Create a string from an array of binary data.
297 * lpHex [I] Binary data to convert to string
298 * iCount [I] Length of lpHex in bytes
299 * lpszOut [O] Destination for resulting hex string
305 * - lpszOut must be at least 2 * iCount + 1 bytes characters long.
306 * - Although the Mapi headers prototype this function as both
307 * Ascii and Unicode, there is only one (Ascii) implementation. This
308 * means that the resulting string is not properly NUL terminated
309 * if the caller expects it to be a Unicode string.
311 void WINAPI HexFromBin(LPBYTE lpHex, int iCount, LPWSTR lpszOut)
313 static const char hexDigits[] = { "0123456789ABCDEF" };
314 LPSTR lpStr = (LPSTR)lpszOut;
316 TRACE("(%p,%d,%p)\n", lpHex, iCount, lpszOut);
320 *lpStr++ = hexDigits[*lpHex >> 4];
321 *lpStr++ = hexDigits[*lpHex & 0xf];
327 /*************************************************************************
328 * SwapPlong@8 (MAPI32.47)
330 * Swap the bytes in a ULONG array.
333 * lpData [O] Array to swap bytes in
334 * ulLen [I] Number of ULONG element to swap the bytes of
339 VOID WINAPI SwapPlong(PULONG lpData, ULONG ulLen)
343 for (i = 0; i < ulLen; i++)
344 lpData[i] = RtlUlongByteSwap(lpData[i]);
347 /*************************************************************************
348 * SwapPword@8 (MAPI32.48)
350 * Swap the bytes in a USHORT array.
353 * lpData [O] Array to swap bytes in
354 * ulLen [I] Number of USHORT element to swap the bytes of
359 VOID WINAPI SwapPword(PUSHORT lpData, ULONG ulLen)
363 for (i = 0; i < ulLen; i++)
364 lpData[i] = RtlUshortByteSwap(lpData[i]);
367 /**************************************************************************
368 * MNLS_lstrlenW@4 (MAPI32.62)
370 * Calculate the length of a Unicode string.
373 * lpszStr [I] String to calculate the length of
376 * The length of lpszStr in Unicode characters.
378 ULONG WINAPI MNLS_lstrlenW(LPCWSTR lpszStr)
380 TRACE("(%s)\n", debugstr_w(lpszStr));
381 return strlenW(lpszStr);
384 /*************************************************************************
385 * MNLS_lstrcmpW@8 (MAPI32.63)
387 * Compare two Unicode strings.
390 * lpszLeft [I] First string to compare
391 * lpszRight [I] Second string to compare
394 * An integer less than, equal to or greater than 0, indicating that
395 * lpszLeft is less than, the same, or greater than lpszRight.
397 INT WINAPI MNLS_lstrcmpW(LPCWSTR lpszLeft, LPCWSTR lpszRight)
399 TRACE("(%s,%s)\n", debugstr_w(lpszLeft), debugstr_w(lpszRight));
400 return strcmpW(lpszLeft, lpszRight);
403 /*************************************************************************
404 * MNLS_lstrcpyW@8 (MAPI32.64)
406 * Copy a Unicode string to another string.
409 * lpszDest [O] Destination string
410 * lpszSrc [I] Source string
413 * The length lpszDest in Unicode characters.
415 ULONG WINAPI MNLS_lstrcpyW(LPWSTR lpszDest, LPCWSTR lpszSrc)
419 TRACE("(%p,%s)\n", lpszDest, debugstr_w(lpszSrc));
420 len = (strlenW(lpszSrc) + 1) * sizeof(WCHAR);
421 memcpy(lpszDest, lpszSrc, len);
425 /*************************************************************************
426 * MNLS_CompareStringW@12 (MAPI32.65)
428 * Compare two Unicode strings.
431 * dwCp [I] Code page for the comparison
432 * lpszLeft [I] First string to compare
433 * lpszRight [I] Second string to compare
436 * CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN, indicating that
437 * lpszLeft is less than, the same, or greater than lpszRight.
439 INT WINAPI MNLS_CompareStringW(DWORD dwCp, LPCWSTR lpszLeft, LPCWSTR lpszRight)
443 TRACE("0x%08x,%s,%s\n", dwCp, debugstr_w(lpszLeft), debugstr_w(lpszRight));
444 ret = MNLS_lstrcmpW(lpszLeft, lpszRight);
445 return ret < 0 ? CSTR_LESS_THAN : ret ? CSTR_GREATER_THAN : CSTR_EQUAL;
448 /**************************************************************************
449 * FEqualNames@8 (MAPI32.72)
451 * Compare two Mapi names.
454 * lpName1 [I] First name to compare to lpName2
455 * lpName2 [I] Second name to compare to lpName1
458 * TRUE, if the names are the same,
461 BOOL WINAPI FEqualNames(LPMAPINAMEID lpName1, LPMAPINAMEID lpName2)
463 TRACE("(%p,%p)\n", lpName1, lpName2);
465 if (!lpName1 || !lpName2 ||
466 !IsEqualGUID(lpName1->lpguid, lpName2->lpguid) ||
467 lpName1->ulKind != lpName2->ulKind)
470 if (lpName1->ulKind == MNID_STRING)
471 return !strcmpW(lpName1->Kind.lpwstrName, lpName2->Kind.lpwstrName);
473 return lpName1->Kind.lID == lpName2->Kind.lID ? TRUE : FALSE;
476 /**************************************************************************
477 * IsBadBoundedStringPtr@8 (MAPI32.71)
479 * Determine if a string pointer is valid.
482 * lpszStr [I] String to check
483 * ulLen [I] Maximum length of lpszStr
486 * TRUE, if lpszStr is invalid or longer than ulLen,
489 BOOL WINAPI IsBadBoundedStringPtr(LPCSTR lpszStr, ULONG ulLen)
491 if (!lpszStr || IsBadStringPtrA(lpszStr, -1) || strlen(lpszStr) >= ulLen)
496 /**************************************************************************
497 * FtAddFt@16 (MAPI32.121)
499 * Add two FILETIME's together.
502 * ftLeft [I] FILETIME to add to ftRight
503 * ftRight [I] FILETIME to add to ftLeft
506 * The sum of ftLeft and ftRight
508 LONGLONG WINAPI MAPI32_FtAddFt(FILETIME ftLeft, FILETIME ftRight)
510 LONGLONG *pl = (LONGLONG*)&ftLeft, *pr = (LONGLONG*)&ftRight;
515 /**************************************************************************
516 * FtSubFt@16 (MAPI32.123)
518 * Subtract two FILETIME's together.
521 * ftLeft [I] Initial FILETIME
522 * ftRight [I] FILETIME to subtract from ftLeft
525 * The remainder after ftRight is subtracted from ftLeft.
527 LONGLONG WINAPI MAPI32_FtSubFt(FILETIME ftLeft, FILETIME ftRight)
529 LONGLONG *pl = (LONGLONG*)&ftLeft, *pr = (LONGLONG*)&ftRight;
534 /**************************************************************************
535 * FtMulDw@12 (MAPI32.124)
537 * Multiply a FILETIME by a DWORD.
540 * dwLeft [I] DWORD to multiply with ftRight
541 * ftRight [I] FILETIME to multiply with dwLeft
544 * The product of dwLeft and ftRight
546 LONGLONG WINAPI MAPI32_FtMulDw(DWORD dwLeft, FILETIME ftRight)
548 LONGLONG *pr = (LONGLONG*)&ftRight;
550 return (LONGLONG)dwLeft * (*pr);
553 /**************************************************************************
554 * FtMulDwDw@8 (MAPI32.125)
556 * Multiply two DWORD, giving the result as a FILETIME.
559 * dwLeft [I] DWORD to multiply with dwRight
560 * dwRight [I] DWORD to multiply with dwLeft
563 * The product of ftMultiplier and ftMultiplicand as a FILETIME.
565 LONGLONG WINAPI MAPI32_FtMulDwDw(DWORD dwLeft, DWORD dwRight)
567 return (LONGLONG)dwLeft * (LONGLONG)dwRight;
570 /**************************************************************************
571 * FtNegFt@8 (MAPI32.126)
576 * ft [I] FILETIME to negate
579 * The negation of ft.
581 LONGLONG WINAPI MAPI32_FtNegFt(FILETIME ft)
583 LONGLONG *p = (LONGLONG*)&ft;
588 /**************************************************************************
589 * UlAddRef@4 (MAPI32.128)
591 * Add a reference to an object.
594 * lpUnk [I] Object to add a reference to.
597 * The new reference count of the object, or 0 if lpUnk is NULL.
600 * See IUnknown_AddRef.
602 ULONG WINAPI UlAddRef(void *lpUnk)
604 TRACE("(%p)\n", lpUnk);
608 return IUnknown_AddRef((LPUNKNOWN)lpUnk);
611 /**************************************************************************
612 * UlRelease@4 (MAPI32.129)
614 * Remove a reference from an object.
617 * lpUnk [I] Object to remove reference from.
620 * The new reference count of the object, or 0 if lpUnk is NULL. If lpUnk is
621 * non-NULL and this function returns 0, the object pointed to by lpUnk has
625 * See IUnknown_Release.
627 ULONG WINAPI UlRelease(void *lpUnk)
629 TRACE("(%p)\n", lpUnk);
633 return IUnknown_Release((LPUNKNOWN)lpUnk);
636 /**************************************************************************
637 * UFromSz@4 (MAPI32.133)
639 * Read an integer from a string
642 * lpszStr [I] String to read the integer from.
645 * Success: The integer read from lpszStr.
646 * Failure: 0, if the first character in lpszStr is not 0-9.
649 * This function does not accept whitespace and stops at the first non-digit
652 UINT WINAPI UFromSz(LPCSTR lpszStr)
656 TRACE("(%s)\n", debugstr_a(lpszStr));
660 while (*lpszStr >= '0' && *lpszStr <= '9')
662 ulRet = ulRet * 10 + (*lpszStr - '0');
669 /*************************************************************************
670 * OpenStreamOnFile@24 (MAPI32.147)
672 * Create a stream on a file.
675 * lpAlloc [I] Memory allocation function
676 * lpFree [I] Memory free function
677 * ulFlags [I] Flags controlling the opening process
678 * lpszPath [I] Path of file to create stream on
679 * lpszPrefix [I] Prefix of the temporary file name (if ulFlags includes SOF_UNIQUEFILENAME)
680 * lppStream [O] Destination for created stream
683 * Success: S_OK. lppStream contains the new stream object
684 * Failure: E_INVALIDARG if any parameter is invalid, or an HRESULT error code
685 * describing the error.
687 HRESULT WINAPI OpenStreamOnFile(LPALLOCATEBUFFER lpAlloc, LPFREEBUFFER lpFree,
688 ULONG ulFlags, LPWSTR lpszPath, LPWSTR lpszPrefix,
691 WCHAR szBuff[MAX_PATH];
692 DWORD dwMode = STGM_READWRITE, dwAttributes = 0;
695 TRACE("(%p,%p,0x%08x,%s,%s,%p)\n", lpAlloc, lpFree, ulFlags,
696 debugstr_a((LPSTR)lpszPath), debugstr_a((LPSTR)lpszPrefix), lppStream);
701 if (ulFlags & SOF_UNIQUEFILENAME)
703 FIXME("Should generate a temporary name\n");
707 if (!lpszPath || !lppStream)
710 /* FIXME: Should probably munge mode and attributes, and should handle
711 * Unicode arguments (I assume MAPI_UNICODE is set in ulFlags if
712 * we are being passed Unicode strings; MSDN doesn't say).
713 * This implementation is just enough for Outlook97 to start.
715 MultiByteToWideChar(CP_ACP, 0, (LPSTR)lpszPath, -1, szBuff, MAX_PATH);
716 hRet = SHCreateStreamOnFileEx(szBuff, dwMode, dwAttributes, TRUE,
721 /*************************************************************************
722 * UlFromSzHex@4 (MAPI32.155)
724 * Read an integer from a hexadecimal string.
727 * lpSzHex [I] String containing the hexadecimal number to read
730 * Success: The number represented by lpszHex.
731 * Failure: 0, if lpszHex does not contain a hex string.
734 * This function does not accept whitespace and stops at the first non-hex
737 ULONG WINAPI UlFromSzHex(LPCWSTR lpszHex)
739 LPCSTR lpStr = (LPCSTR)lpszHex;
742 TRACE("(%s)\n", debugstr_a(lpStr));
746 if (lpStr[0] < '0' || lpStr[0] > 'f' || digitsToHex[lpStr[0] - '0'] == 0xff ||
747 lpStr[1] < '0' || lpStr[1] > 'f' || digitsToHex[lpStr[1] - '0'] == 0xff)
750 ulRet = ulRet * 16 + ((digitsToHex[lpStr[0] - '0'] << 4) | digitsToHex[lpStr[1] - '0']);
756 /************************************************************************
757 * FBadEntryList@4 (MAPI32.190)
759 * Determine is an entry list is invalid.
762 * lpEntryList [I] List to check
765 * TRUE, if lpEntryList is invalid,
768 BOOL WINAPI FBadEntryList(LPENTRYLIST lpEntryList)
772 if (IsBadReadPtr(lpEntryList, sizeof(*lpEntryList)) ||
773 IsBadReadPtr(lpEntryList->lpbin,
774 lpEntryList->cValues * sizeof(*lpEntryList->lpbin)))
777 for (i = 0; i < lpEntryList->cValues; i++)
778 if(IsBadReadPtr(lpEntryList->lpbin[i].lpb, lpEntryList->lpbin[i].cb))
784 /*************************************************************************
785 * CbOfEncoded@4 (MAPI32.207)
787 * Return the length of an encoded string.
790 * lpSzEnc [I] Encoded string to get the length of.
793 * The length of the encoded string in bytes.
795 ULONG WINAPI CbOfEncoded(LPCSTR lpszEnc)
799 TRACE("(%s)\n", debugstr_a(lpszEnc));
802 ulRet = (((strlen(lpszEnc) | 3) >> 2) + 1) * 3;
806 /*************************************************************************
807 * cmc_query_configuration (MAPI32.235)
809 * Retrieves the configuration information for the installed CMC
812 * session [I] MAPI session handle
813 * item [I] Enumerated variable that identifies which
814 * configuration information is being requested
815 * reference [O] Buffer where configuration information is written
816 * config_extensions[I/O] Path of file to create stream on
821 CMC_return_code WINAPI cmc_query_configuration(
822 CMC_session_id session,
824 CMC_buffer reference,
825 CMC_extension *config_extensions)
828 return CMC_E_NOT_SUPPORTED;
831 /**************************************************************************
832 * FGetComponentPath (MAPI32.254)
833 * FGetComponentPath@20 (MAPI32.255)
835 * Return the installed component path, usually to the private mapi32.dll.
838 * component [I] Component ID
839 * qualifier [I] Application LCID
840 * dll_path [O] returned component path
841 * dll_path_length [I] component path length
842 * install [I] install mode
849 * Previously documented in Q229700 "How to locate the correct path
850 * to the Mapisvc.inf file in Microsoft Outlook".
852 BOOL WINAPI FGetComponentPath(LPCSTR component, LPCSTR qualifier, LPSTR dll_path,
853 DWORD dll_path_length, BOOL install)
858 TRACE("%s %s %p %u %d\n", component, qualifier, dll_path, dll_path_length, install);
862 hmsi = LoadLibraryA("msi.dll");
865 UINT (WINAPI *pMsiProvideQualifiedComponentA)(LPCSTR, LPCSTR, DWORD, LPSTR, LPDWORD);
867 pMsiProvideQualifiedComponentA = (void *)GetProcAddress(hmsi, "MsiProvideQualifiedComponentA");
868 if (pMsiProvideQualifiedComponentA)
870 static const char * const fmt[] = { "%d\\NT", "%d\\95", "%d" };
874 for (i = 0; i < sizeof(fmt)/sizeof(fmt[0]); i++)
876 /* FIXME: what's the correct behaviour here? */
877 if (!qualifier || qualifier == lcid_ver)
879 sprintf(lcid_ver, fmt[i], GetUserDefaultUILanguage());
880 qualifier = lcid_ver;
883 if (pMsiProvideQualifiedComponentA(component, qualifier,
884 install ? INSTALLMODE_DEFAULT : INSTALLMODE_EXISTING,
885 dll_path, &dll_path_length) == ERROR_SUCCESS)
891 if (qualifier != lcid_ver) break;
899 /**************************************************************************
900 * HrQueryAllRows (MAPI32.75)
902 HRESULT WINAPI HrQueryAllRows(LPMAPITABLE lpTable, LPSPropTagArray lpPropTags,
903 LPSRestriction lpRestriction, LPSSortOrderSet lpSortOrderSet,
904 LONG crowsMax, LPSRowSet *lppRows)
906 FIXME("(%p, %p, %p, %p, %d, %p): stub\n", lpTable, lpPropTags, lpRestriction, lpSortOrderSet, crowsMax, lppRows);
908 return MAPI_E_CALL_FAILED;
911 static HMODULE mapi_provider;
912 static HMODULE mapi_ex_provider;
914 /**************************************************************************
917 * Attempts to load a MAPI provider from the specified registry key.
919 * Returns a handle to the loaded module in `mapi_provider' if successful.
921 static void load_mapi_provider(HKEY hkeyMail, LPCWSTR valueName, HMODULE *mapi_provider)
923 static const WCHAR mapi32_dll[] = {'m','a','p','i','3','2','.','d','l','l',0 };
925 DWORD dwType, dwLen = 0;
928 /* Check if we have a value set for DLLPath */
929 if ((RegQueryValueExW(hkeyMail, valueName, NULL, &dwType, NULL, &dwLen) == ERROR_SUCCESS) &&
930 ((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ)) && (dwLen > 0))
932 dllPath = HeapAlloc(GetProcessHeap(), 0, dwLen);
936 RegQueryValueExW(hkeyMail, valueName, NULL, NULL, (LPBYTE)dllPath, &dwLen);
938 /* Check that this value doesn't refer to mapi32.dll (eg, as Outlook does) */
939 if (lstrcmpiW(dllPath, mapi32_dll) != 0)
941 if (dwType == REG_EXPAND_SZ)
944 LPWSTR dllPathExpanded;
946 /* Expand the path if necessary */
947 dwExpandLen = ExpandEnvironmentStringsW(dllPath, NULL, 0);
948 dllPathExpanded = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * dwExpandLen + 1);
952 ExpandEnvironmentStringsW(dllPath, dllPathExpanded, dwExpandLen + 1);
954 HeapFree(GetProcessHeap(), 0, dllPath);
955 dllPath = dllPathExpanded;
960 TRACE("loading %s\n", debugstr_w(dllPath));
961 *mapi_provider = LoadLibraryW(dllPath);
964 HeapFree(GetProcessHeap(), 0, dllPath);
969 /**************************************************************************
970 * load_mapi_providers
972 * Scans the registry for MAPI providers and attempts to load a Simple and
973 * Extended MAPI library.
975 * Returns TRUE if at least one library loaded, FALSE otherwise.
977 void load_mapi_providers(void)
979 static const WCHAR regkey_mail[] = {
980 'S','o','f','t','w','a','r','e','\\','C','l','i','e','n','t','s','\\',
983 static const WCHAR regkey_dllpath[] = {'D','L','L','P','a','t','h',0 };
984 static const WCHAR regkey_dllpath_ex[] = {'D','L','L','P','a','t','h','E','x',0 };
985 static const WCHAR regkey_backslash[] = { '\\', 0 };
988 DWORD dwType, dwLen = 0;
989 LPWSTR appName = NULL, appKey = NULL;
993 /* Open the Mail key */
994 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, regkey_mail, 0, KEY_READ, &hkeyMail) != ERROR_SUCCESS)
997 /* Check if we have a default value set, and the length of it */
998 if ((RegQueryValueExW(hkeyMail, NULL, NULL, &dwType, NULL, &dwLen) != ERROR_SUCCESS) ||
999 !((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ)) || (dwLen == 0))
1002 appName = HeapAlloc(GetProcessHeap(), 0, dwLen);
1007 /* Get the value, and get the path to the app key */
1008 RegQueryValueExW(hkeyMail, NULL, NULL, NULL, (LPBYTE)appName, &dwLen);
1010 TRACE("appName: %s\n", debugstr_w(appName));
1012 appKey = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(regkey_mail) +
1013 lstrlenW(regkey_backslash) + lstrlenW(appName)));
1018 lstrcpyW(appKey, regkey_mail);
1019 lstrcatW(appKey, regkey_backslash);
1020 lstrcatW(appKey, appName);
1022 RegCloseKey(hkeyMail);
1024 TRACE("appKey: %s\n", debugstr_w(appKey));
1026 /* Open the app's key */
1027 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, appKey, 0, KEY_READ, &hkeyMail) != ERROR_SUCCESS)
1030 /* Try to load the providers */
1031 load_mapi_provider(hkeyMail, regkey_dllpath, &mapi_provider);
1032 load_mapi_provider(hkeyMail, regkey_dllpath_ex, &mapi_ex_provider);
1034 /* Now try to load our function pointers */
1035 ZeroMemory(&mapiFunctions, sizeof(mapiFunctions));
1037 /* Simple MAPI functions */
1040 mapiFunctions.MAPIAddress = (void*) GetProcAddress(mapi_provider, "MAPIAddress");
1041 mapiFunctions.MAPIDeleteMail = (void*) GetProcAddress(mapi_provider, "MAPIDeleteMail");
1042 mapiFunctions.MAPIDetails = (void*) GetProcAddress(mapi_provider, "MAPIDetails");
1043 mapiFunctions.MAPIFindNext = (void*) GetProcAddress(mapi_provider, "MAPIFindNext");
1044 mapiFunctions.MAPILogoff = (void*) GetProcAddress(mapi_provider, "MAPILogoff");
1045 mapiFunctions.MAPILogon = (void*) GetProcAddress(mapi_provider, "MAPILogon");
1046 mapiFunctions.MAPIReadMail = (void*) GetProcAddress(mapi_provider, "MAPIReadMail");
1047 mapiFunctions.MAPIResolveName = (void*) GetProcAddress(mapi_provider, "MAPIResolveName");
1048 mapiFunctions.MAPISaveMail = (void*) GetProcAddress(mapi_provider, "MAPISaveMail");
1049 mapiFunctions.MAPISendDocuments = (void*) GetProcAddress(mapi_provider, "MAPISendDocuments");
1050 mapiFunctions.MAPISendMail = (void*) GetProcAddress(mapi_provider, "MAPISendMail");
1053 /* Extended MAPI functions */
1054 if (mapi_ex_provider)
1056 mapiFunctions.MAPIInitialize = (void*) GetProcAddress(mapi_ex_provider, "MAPIInitialize");
1057 mapiFunctions.MAPILogonEx = (void*) GetProcAddress(mapi_ex_provider, "MAPILogonEx");
1058 mapiFunctions.MAPIUninitialize = (void*) GetProcAddress(mapi_ex_provider, "MAPIUninitialize");
1062 RegCloseKey(hkeyMail);
1063 HeapFree(GetProcessHeap(), 0, appKey);
1064 HeapFree(GetProcessHeap(), 0, appName);
1067 /**************************************************************************
1068 * unload_mapi_providers
1070 * Unloads any loaded MAPI libraries.
1072 void unload_mapi_providers(void)
1076 FreeLibrary(mapi_provider);
1077 FreeLibrary(mapi_ex_provider);