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
31 static const BYTE digitsToHex
[] = {
32 0,1,2,3,4,5,6,7,8,9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,10,11,12,13,14,15,
33 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
34 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,10,11,12,13,
37 MAPI_FUNCTIONS mapiFunctions
;
39 /**************************************************************************
40 * ScInitMapiUtil (MAPI32.33)
42 * Initialise Mapi utility functions.
45 * ulReserved [I] Reserved, pass 0.
48 * Success: S_OK. Mapi utility functions may be called.
49 * Failure: MAPI_E_INVALID_PARAMETER, if ulReserved is not 0.
52 * Your application does not need to call this function unless it does not
53 * call MAPIInitialize()/MAPIUninitialize().
55 SCODE WINAPI
ScInitMapiUtil(ULONG ulReserved
)
57 if (mapiFunctions
.ScInitMapiUtil
)
58 return mapiFunctions
.ScInitMapiUtil(ulReserved
);
60 FIXME("(0x%08x)stub!\n", ulReserved
);
62 return MAPI_E_INVALID_PARAMETER
;
66 /**************************************************************************
67 * DeinitMapiUtil (MAPI32.34)
69 * Uninitialise Mapi utility functions.
78 * Your application does not need to call this function unless it does not
79 * call MAPIInitialize()/MAPIUninitialize().
81 VOID WINAPI
DeinitMapiUtil(void)
83 if (mapiFunctions
.DeinitMapiUtil
)
84 mapiFunctions
.DeinitMapiUtil();
89 typedef LPVOID
*LPMAPIALLOCBUFFER
;
91 /**************************************************************************
92 * MAPIAllocateBuffer (MAPI32.12)
93 * MAPIAllocateBuffer@8 (MAPI32.13)
95 * Allocate a block of memory.
98 * cbSize [I] Size of the block to allocate in bytes
99 * lppBuffer [O] Destination for pointer to allocated memory
102 * Success: S_OK. *lppBuffer is filled with a pointer to a memory block of
103 * length cbSize bytes.
104 * Failure: MAPI_E_INVALID_PARAMETER, if lppBuffer is NULL.
105 * MAPI_E_NOT_ENOUGH_MEMORY, if the memory allocation fails.
108 * Memory allocated with this function should be freed with MAPIFreeBuffer().
109 * Further allocations of memory may be linked to the pointer returned using
110 * MAPIAllocateMore(). Linked allocations are freed when the initial pointer
113 SCODE WINAPI
MAPIAllocateBuffer(ULONG cbSize
, LPVOID
*lppBuffer
)
115 LPMAPIALLOCBUFFER lpBuff
;
117 TRACE("(%d,%p)\n", cbSize
, lppBuffer
);
119 if (mapiFunctions
.MAPIAllocateBuffer
)
120 return mapiFunctions
.MAPIAllocateBuffer(cbSize
, lppBuffer
);
125 lpBuff
= HeapAlloc(GetProcessHeap(), 0, cbSize
+ sizeof(*lpBuff
));
127 return MAPI_E_NOT_ENOUGH_MEMORY
;
129 TRACE("initial allocation:%p, returning %p\n", lpBuff
, lpBuff
+ 1);
135 /**************************************************************************
136 * MAPIAllocateMore (MAPI32.14)
137 * MAPIAllocateMore@12 (MAPI32.15)
139 * Allocate a block of memory linked to a previous allocation.
142 * cbSize [I] Size of the block to allocate in bytes
143 * lpOrig [I] Initial allocation to link to, from MAPIAllocateBuffer()
144 * lppBuffer [O] Destination for pointer to allocated memory
147 * Success: S_OK. *lppBuffer is filled with a pointer to a memory block of
148 * length cbSize bytes.
149 * Failure: MAPI_E_INVALID_PARAMETER, if lpOrig or lppBuffer is invalid.
150 * MAPI_E_NOT_ENOUGH_MEMORY, if memory allocation fails.
153 * Memory allocated with this function and stored in *lppBuffer is freed
154 * when lpOrig is passed to MAPIFreeBuffer(). It should not be freed independently.
156 SCODE WINAPI
MAPIAllocateMore(ULONG cbSize
, LPVOID lpOrig
, LPVOID
*lppBuffer
)
158 LPMAPIALLOCBUFFER lpBuff
= lpOrig
;
160 TRACE("(%d,%p,%p)\n", cbSize
, lpOrig
, lppBuffer
);
162 if (mapiFunctions
.MAPIAllocateMore
)
163 return mapiFunctions
.MAPIAllocateMore(cbSize
, lpOrig
, lppBuffer
);
165 if (!lppBuffer
|| !lpBuff
|| !--lpBuff
)
168 /* Find the last allocation in the chain */
171 TRACE("linked:%p->%p\n", lpBuff
, *lpBuff
);
175 if (SUCCEEDED(MAPIAllocateBuffer(cbSize
, lppBuffer
)))
177 *lpBuff
= ((LPMAPIALLOCBUFFER
)*lppBuffer
) - 1;
178 TRACE("linking %p->%p\n", lpBuff
, *lpBuff
);
180 return *lppBuffer
? S_OK
: MAPI_E_NOT_ENOUGH_MEMORY
;
183 /**************************************************************************
184 * MAPIFreeBuffer (MAPI32.16)
185 * MAPIFreeBuffer@4 (MAPI32.17)
187 * Free a block of memory and any linked allocations associated with it.
190 * lpBuffer [I] Memory to free, returned from MAPIAllocateBuffer()
195 ULONG WINAPI
MAPIFreeBuffer(LPVOID lpBuffer
)
197 LPMAPIALLOCBUFFER lpBuff
= lpBuffer
;
199 TRACE("(%p)\n", lpBuffer
);
201 if (mapiFunctions
.MAPIFreeBuffer
)
202 return mapiFunctions
.MAPIFreeBuffer(lpBuffer
);
204 if (lpBuff
&& --lpBuff
)
208 LPVOID lpFree
= lpBuff
;
212 TRACE("linked:%p->%p, freeing %p\n", lpFree
, lpBuff
, lpFree
);
213 HeapFree(GetProcessHeap(), 0, lpFree
);
219 /**************************************************************************
220 * WrapProgress@20 (MAPI32.41)
222 HRESULT WINAPI
WrapProgress(PVOID unk1
, PVOID unk2
, PVOID unk3
, PVOID unk4
, PVOID unk5
)
224 /* Native does not implement this function */
225 return MAPI_E_NO_SUPPORT
;
228 /*************************************************************************
229 * HrThisThreadAdviseSink@8 (MAPI32.42)
231 * Ensure that an advise sink is only notified in its originating thread.
234 * lpSink [I] IMAPIAdviseSink interface to be protected
235 * lppNewSink [I] Destination for wrapper IMAPIAdviseSink interface
238 * Success: S_OK. *lppNewSink contains a new sink to use in place of lpSink.
239 * Failure: E_INVALIDARG, if any parameter is invalid.
241 HRESULT WINAPI
HrThisThreadAdviseSink(LPMAPIADVISESINK lpSink
, LPMAPIADVISESINK
* lppNewSink
)
243 if (mapiFunctions
.HrThisThreadAdviseSink
)
244 return mapiFunctions
.HrThisThreadAdviseSink(lpSink
, lppNewSink
);
246 FIXME("(%p,%p)semi-stub\n", lpSink
, lppNewSink
);
248 if (!lpSink
|| !lppNewSink
)
251 /* Don't wrap the sink for now, just copy it */
252 *lppNewSink
= lpSink
;
253 IMAPIAdviseSink_AddRef(lpSink
);
257 /*************************************************************************
258 * FBinFromHex (MAPI32.44)
260 * Create an array of binary data from a string.
263 * lpszHex [I] String to convert to binary data
264 * lpOut [O] Destination for resulting binary data
267 * Success: TRUE. lpOut contains the decoded binary data.
268 * Failure: FALSE, if lpszHex does not represent a binary string.
271 * - lpOut must be at least half the length of lpszHex in bytes.
272 * - Although the Mapi headers prototype this function as both
273 * Ascii and Unicode, there is only one (Ascii) implementation. This
274 * means that lpszHex is treated as an Ascii string (i.e. a single NUL
275 * character in the byte stream terminates the string).
277 BOOL WINAPI
FBinFromHex(LPWSTR lpszHex
, LPBYTE lpOut
)
279 LPSTR lpStr
= (LPSTR
)lpszHex
;
281 TRACE("(%p,%p)\n", lpszHex
, lpOut
);
285 if (lpStr
[0] < '0' || lpStr
[0] > 'f' || digitsToHex
[lpStr
[0] - '0'] == 0xff ||
286 lpStr
[1] < '0' || lpStr
[1] > 'f' || digitsToHex
[lpStr
[1] - '0'] == 0xff)
289 *lpOut
++ = (digitsToHex
[lpStr
[0] - '0'] << 4) | digitsToHex
[lpStr
[1] - '0'];
295 /*************************************************************************
296 * HexFromBin (MAPI32.45)
298 * Create a string from an array of binary data.
301 * lpHex [I] Binary data to convert to string
302 * iCount [I] Length of lpHex in bytes
303 * lpszOut [O] Destination for resulting hex string
309 * - lpszOut must be at least 2 * iCount + 1 bytes characters long.
310 * - Although the Mapi headers prototype this function as both
311 * Ascii and Unicode, there is only one (Ascii) implementation. This
312 * means that the resulting string is not properly NUL terminated
313 * if the caller expects it to be a Unicode string.
315 void WINAPI
HexFromBin(LPBYTE lpHex
, int iCount
, LPWSTR lpszOut
)
317 static const char hexDigits
[] = { "0123456789ABCDEF" };
318 LPSTR lpStr
= (LPSTR
)lpszOut
;
320 TRACE("(%p,%d,%p)\n", lpHex
, iCount
, lpszOut
);
324 *lpStr
++ = hexDigits
[*lpHex
>> 4];
325 *lpStr
++ = hexDigits
[*lpHex
& 0xf];
331 /*************************************************************************
332 * SwapPlong@8 (MAPI32.47)
334 * Swap the bytes in a ULONG array.
337 * lpData [O] Array to swap bytes in
338 * ulLen [I] Number of ULONG element to swap the bytes of
343 VOID WINAPI
SwapPlong(PULONG lpData
, ULONG ulLen
)
347 for (i
= 0; i
< ulLen
; i
++)
348 lpData
[i
] = RtlUlongByteSwap(lpData
[i
]);
351 /*************************************************************************
352 * SwapPword@8 (MAPI32.48)
354 * Swap the bytes in a USHORT array.
357 * lpData [O] Array to swap bytes in
358 * ulLen [I] Number of USHORT element to swap the bytes of
363 VOID WINAPI
SwapPword(PUSHORT lpData
, ULONG ulLen
)
367 for (i
= 0; i
< ulLen
; i
++)
368 lpData
[i
] = RtlUshortByteSwap(lpData
[i
]);
371 /**************************************************************************
372 * MNLS_lstrlenW@4 (MAPI32.62)
374 * Calculate the length of a Unicode string.
377 * lpszStr [I] String to calculate the length of
380 * The length of lpszStr in Unicode characters.
382 ULONG WINAPI
MNLS_lstrlenW(LPCWSTR lpszStr
)
384 TRACE("(%s)\n", debugstr_w(lpszStr
));
385 return strlenW(lpszStr
);
388 /*************************************************************************
389 * MNLS_lstrcmpW@8 (MAPI32.63)
391 * Compare two Unicode strings.
394 * lpszLeft [I] First string to compare
395 * lpszRight [I] Second string to compare
398 * An integer less than, equal to or greater than 0, indicating that
399 * lpszLeft is less than, the same, or greater than lpszRight.
401 INT WINAPI
MNLS_lstrcmpW(LPCWSTR lpszLeft
, LPCWSTR lpszRight
)
403 TRACE("(%s,%s)\n", debugstr_w(lpszLeft
), debugstr_w(lpszRight
));
404 return strcmpW(lpszLeft
, lpszRight
);
407 /*************************************************************************
408 * MNLS_lstrcpyW@8 (MAPI32.64)
410 * Copy a Unicode string to another string.
413 * lpszDest [O] Destination string
414 * lpszSrc [I] Source string
417 * The length lpszDest in Unicode characters.
419 ULONG WINAPI
MNLS_lstrcpyW(LPWSTR lpszDest
, LPCWSTR lpszSrc
)
423 TRACE("(%p,%s)\n", lpszDest
, debugstr_w(lpszSrc
));
424 len
= (strlenW(lpszSrc
) + 1) * sizeof(WCHAR
);
425 memcpy(lpszDest
, lpszSrc
, len
);
429 /*************************************************************************
430 * MNLS_CompareStringW@12 (MAPI32.65)
432 * Compare two Unicode strings.
435 * dwCp [I] Code page for the comparison
436 * lpszLeft [I] First string to compare
437 * lpszRight [I] Second string to compare
440 * CSTR_LESS_THAN, CSTR_EQUAL or CSTR_GREATER_THAN, indicating that
441 * lpszLeft is less than, the same, or greater than lpszRight.
443 INT WINAPI
MNLS_CompareStringW(DWORD dwCp
, LPCWSTR lpszLeft
, LPCWSTR lpszRight
)
447 TRACE("0x%08x,%s,%s\n", dwCp
, debugstr_w(lpszLeft
), debugstr_w(lpszRight
));
448 ret
= MNLS_lstrcmpW(lpszLeft
, lpszRight
);
449 return ret
< 0 ? CSTR_LESS_THAN
: ret
? CSTR_GREATER_THAN
: CSTR_EQUAL
;
452 /**************************************************************************
453 * FEqualNames@8 (MAPI32.72)
455 * Compare two Mapi names.
458 * lpName1 [I] First name to compare to lpName2
459 * lpName2 [I] Second name to compare to lpName1
462 * TRUE, if the names are the same,
465 BOOL WINAPI
FEqualNames(LPMAPINAMEID lpName1
, LPMAPINAMEID lpName2
)
467 TRACE("(%p,%p)\n", lpName1
, lpName2
);
469 if (!lpName1
|| !lpName2
||
470 !IsEqualGUID(lpName1
->lpguid
, lpName2
->lpguid
) ||
471 lpName1
->ulKind
!= lpName2
->ulKind
)
474 if (lpName1
->ulKind
== MNID_STRING
)
475 return !strcmpW(lpName1
->Kind
.lpwstrName
, lpName2
->Kind
.lpwstrName
);
477 return lpName1
->Kind
.lID
== lpName2
->Kind
.lID
;
480 /**************************************************************************
481 * IsBadBoundedStringPtr@8 (MAPI32.71)
483 * Determine if a string pointer is valid.
486 * lpszStr [I] String to check
487 * ulLen [I] Maximum length of lpszStr
490 * TRUE, if lpszStr is invalid or longer than ulLen,
493 BOOL WINAPI
IsBadBoundedStringPtr(LPCSTR lpszStr
, ULONG ulLen
)
495 if (!lpszStr
|| IsBadStringPtrA(lpszStr
, -1) || strlen(lpszStr
) >= ulLen
)
500 /**************************************************************************
501 * FtAddFt@16 (MAPI32.121)
503 * Add two FILETIME's together.
506 * ftLeft [I] FILETIME to add to ftRight
507 * ftRight [I] FILETIME to add to ftLeft
510 * The sum of ftLeft and ftRight
512 LONGLONG WINAPI
MAPI32_FtAddFt(FILETIME ftLeft
, FILETIME ftRight
)
514 LONGLONG
*pl
= (LONGLONG
*)&ftLeft
, *pr
= (LONGLONG
*)&ftRight
;
519 /**************************************************************************
520 * FtSubFt@16 (MAPI32.123)
522 * Subtract two FILETIME's together.
525 * ftLeft [I] Initial FILETIME
526 * ftRight [I] FILETIME to subtract from ftLeft
529 * The remainder after ftRight is subtracted from ftLeft.
531 LONGLONG WINAPI
MAPI32_FtSubFt(FILETIME ftLeft
, FILETIME ftRight
)
533 LONGLONG
*pl
= (LONGLONG
*)&ftLeft
, *pr
= (LONGLONG
*)&ftRight
;
538 /**************************************************************************
539 * FtMulDw@12 (MAPI32.124)
541 * Multiply a FILETIME by a DWORD.
544 * dwLeft [I] DWORD to multiply with ftRight
545 * ftRight [I] FILETIME to multiply with dwLeft
548 * The product of dwLeft and ftRight
550 LONGLONG WINAPI
MAPI32_FtMulDw(DWORD dwLeft
, FILETIME ftRight
)
552 LONGLONG
*pr
= (LONGLONG
*)&ftRight
;
554 return (LONGLONG
)dwLeft
* (*pr
);
557 /**************************************************************************
558 * FtMulDwDw@8 (MAPI32.125)
560 * Multiply two DWORD, giving the result as a FILETIME.
563 * dwLeft [I] DWORD to multiply with dwRight
564 * dwRight [I] DWORD to multiply with dwLeft
567 * The product of ftMultiplier and ftMultiplicand as a FILETIME.
569 LONGLONG WINAPI
MAPI32_FtMulDwDw(DWORD dwLeft
, DWORD dwRight
)
571 return (LONGLONG
)dwLeft
* (LONGLONG
)dwRight
;
574 /**************************************************************************
575 * FtNegFt@8 (MAPI32.126)
580 * ft [I] FILETIME to negate
583 * The negation of ft.
585 LONGLONG WINAPI
MAPI32_FtNegFt(FILETIME ft
)
587 LONGLONG
*p
= (LONGLONG
*)&ft
;
592 /**************************************************************************
593 * UlAddRef@4 (MAPI32.128)
595 * Add a reference to an object.
598 * lpUnk [I] Object to add a reference to.
601 * The new reference count of the object, or 0 if lpUnk is NULL.
604 * See IUnknown_AddRef.
606 ULONG WINAPI
UlAddRef(void *lpUnk
)
608 TRACE("(%p)\n", lpUnk
);
612 return IUnknown_AddRef((LPUNKNOWN
)lpUnk
);
615 /**************************************************************************
616 * UlRelease@4 (MAPI32.129)
618 * Remove a reference from an object.
621 * lpUnk [I] Object to remove reference from.
624 * The new reference count of the object, or 0 if lpUnk is NULL. If lpUnk is
625 * non-NULL and this function returns 0, the object pointed to by lpUnk has
629 * See IUnknown_Release.
631 ULONG WINAPI
UlRelease(void *lpUnk
)
633 TRACE("(%p)\n", lpUnk
);
637 return IUnknown_Release((LPUNKNOWN
)lpUnk
);
640 /**************************************************************************
641 * UFromSz@4 (MAPI32.133)
643 * Read an integer from a string
646 * lpszStr [I] String to read the integer from.
649 * Success: The integer read from lpszStr.
650 * Failure: 0, if the first character in lpszStr is not 0-9.
653 * This function does not accept whitespace and stops at the first non-digit
656 UINT WINAPI
UFromSz(LPCSTR lpszStr
)
660 TRACE("(%s)\n", debugstr_a(lpszStr
));
664 while (*lpszStr
>= '0' && *lpszStr
<= '9')
666 ulRet
= ulRet
* 10 + (*lpszStr
- '0');
673 /*************************************************************************
674 * OpenStreamOnFile@24 (MAPI32.147)
676 * Create a stream on a file.
679 * lpAlloc [I] Memory allocation function
680 * lpFree [I] Memory free function
681 * ulFlags [I] Flags controlling the opening process
682 * lpszPath [I] Path of file to create stream on
683 * lpszPrefix [I] Prefix of the temporary file name (if ulFlags includes SOF_UNIQUEFILENAME)
684 * lppStream [O] Destination for created stream
687 * Success: S_OK. lppStream contains the new stream object
688 * Failure: E_INVALIDARG if any parameter is invalid, or an HRESULT error code
689 * describing the error.
691 HRESULT WINAPI
OpenStreamOnFile(LPALLOCATEBUFFER lpAlloc
, LPFREEBUFFER lpFree
,
692 ULONG ulFlags
, LPWSTR lpszPath
, LPWSTR lpszPrefix
,
695 WCHAR szBuff
[MAX_PATH
];
696 DWORD dwMode
= STGM_READWRITE
, dwAttributes
= 0;
699 TRACE("(%p,%p,0x%08x,%s,%s,%p)\n", lpAlloc
, lpFree
, ulFlags
,
700 debugstr_a((LPSTR
)lpszPath
), debugstr_a((LPSTR
)lpszPrefix
), lppStream
);
702 if (mapiFunctions
.OpenStreamOnFile
)
703 return mapiFunctions
.OpenStreamOnFile(lpAlloc
, lpFree
, ulFlags
, lpszPath
, lpszPrefix
, lppStream
);
708 if (ulFlags
& SOF_UNIQUEFILENAME
)
710 FIXME("Should generate a temporary name\n");
714 if (!lpszPath
|| !lppStream
)
717 /* FIXME: Should probably munge mode and attributes, and should handle
718 * Unicode arguments (I assume MAPI_UNICODE is set in ulFlags if
719 * we are being passed Unicode strings; MSDN doesn't say).
720 * This implementation is just enough for Outlook97 to start.
722 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
)lpszPath
, -1, szBuff
, MAX_PATH
);
723 hRet
= SHCreateStreamOnFileEx(szBuff
, dwMode
, dwAttributes
, TRUE
,
728 /*************************************************************************
729 * UlFromSzHex@4 (MAPI32.155)
731 * Read an integer from a hexadecimal string.
734 * lpSzHex [I] String containing the hexadecimal number to read
737 * Success: The number represented by lpszHex.
738 * Failure: 0, if lpszHex does not contain a hex string.
741 * This function does not accept whitespace and stops at the first non-hex
744 ULONG WINAPI
UlFromSzHex(LPCWSTR lpszHex
)
746 LPCSTR lpStr
= (LPCSTR
)lpszHex
;
749 TRACE("(%s)\n", debugstr_a(lpStr
));
753 if (lpStr
[0] < '0' || lpStr
[0] > 'f' || digitsToHex
[lpStr
[0] - '0'] == 0xff ||
754 lpStr
[1] < '0' || lpStr
[1] > 'f' || digitsToHex
[lpStr
[1] - '0'] == 0xff)
757 ulRet
= ulRet
* 16 + ((digitsToHex
[lpStr
[0] - '0'] << 4) | digitsToHex
[lpStr
[1] - '0']);
763 /************************************************************************
764 * FBadEntryList@4 (MAPI32.190)
766 * Determine is an entry list is invalid.
769 * lpEntryList [I] List to check
772 * TRUE, if lpEntryList is invalid,
775 BOOL WINAPI
FBadEntryList(LPENTRYLIST lpEntryList
)
779 if (IsBadReadPtr(lpEntryList
, sizeof(*lpEntryList
)) ||
780 IsBadReadPtr(lpEntryList
->lpbin
,
781 lpEntryList
->cValues
* sizeof(*lpEntryList
->lpbin
)))
784 for (i
= 0; i
< lpEntryList
->cValues
; i
++)
785 if(IsBadReadPtr(lpEntryList
->lpbin
[i
].lpb
, lpEntryList
->lpbin
[i
].cb
))
791 /*************************************************************************
792 * CbOfEncoded@4 (MAPI32.207)
794 * Return the length of an encoded string.
797 * lpSzEnc [I] Encoded string to get the length of.
800 * The length of the encoded string in bytes.
802 ULONG WINAPI
CbOfEncoded(LPCSTR lpszEnc
)
806 TRACE("(%s)\n", debugstr_a(lpszEnc
));
809 ulRet
= (((strlen(lpszEnc
) | 3) >> 2) + 1) * 3;
813 /*************************************************************************
814 * cmc_query_configuration (MAPI32.235)
816 * Retrieves the configuration information for the installed CMC
819 * session [I] MAPI session handle
820 * item [I] Enumerated variable that identifies which
821 * configuration information is being requested
822 * reference [O] Buffer where configuration information is written
823 * config_extensions[I/O] Path of file to create stream on
828 CMC_return_code WINAPI
cmc_query_configuration(
829 CMC_session_id session
,
831 CMC_buffer reference
,
832 CMC_extension
*config_extensions
)
835 return CMC_E_NOT_SUPPORTED
;
838 /**************************************************************************
839 * FGetComponentPath (MAPI32.254)
840 * FGetComponentPath@20 (MAPI32.255)
842 * Return the installed component path, usually to the private mapi32.dll.
845 * component [I] Component ID
846 * qualifier [I] Application LCID
847 * dll_path [O] returned component path
848 * dll_path_length [I] component path length
849 * install [I] install mode
856 * Previously documented in Q229700 "How to locate the correct path
857 * to the Mapisvc.inf file in Microsoft Outlook".
859 BOOL WINAPI
FGetComponentPath(LPCSTR component
, LPCSTR qualifier
, LPSTR dll_path
,
860 DWORD dll_path_length
, BOOL install
)
865 TRACE("%s %s %p %u %d\n", component
, qualifier
, dll_path
, dll_path_length
, install
);
867 if (mapiFunctions
.FGetComponentPath
)
868 return mapiFunctions
.FGetComponentPath(component
, qualifier
, dll_path
, dll_path_length
, install
);
872 hmsi
= LoadLibraryA("msi.dll");
875 UINT (WINAPI
*pMsiProvideQualifiedComponentA
)(LPCSTR
, LPCSTR
, DWORD
, LPSTR
, LPDWORD
);
877 pMsiProvideQualifiedComponentA
= (void *)GetProcAddress(hmsi
, "MsiProvideQualifiedComponentA");
878 if (pMsiProvideQualifiedComponentA
)
880 static const char * const fmt
[] = { "%d\\NT", "%d\\95", "%d" };
884 for (i
= 0; i
< sizeof(fmt
)/sizeof(fmt
[0]); i
++)
886 /* FIXME: what's the correct behaviour here? */
887 if (!qualifier
|| qualifier
== lcid_ver
)
889 sprintf(lcid_ver
, fmt
[i
], GetUserDefaultUILanguage());
890 qualifier
= lcid_ver
;
893 if (pMsiProvideQualifiedComponentA(component
, qualifier
,
894 install
? INSTALLMODE_DEFAULT
: INSTALLMODE_EXISTING
,
895 dll_path
, &dll_path_length
) == ERROR_SUCCESS
)
901 if (qualifier
!= lcid_ver
) break;
909 /**************************************************************************
910 * HrQueryAllRows (MAPI32.75)
912 HRESULT WINAPI
HrQueryAllRows(LPMAPITABLE lpTable
, LPSPropTagArray lpPropTags
,
913 LPSRestriction lpRestriction
, LPSSortOrderSet lpSortOrderSet
,
914 LONG crowsMax
, LPSRowSet
*lppRows
)
916 if (mapiFunctions
.HrQueryAllRows
)
917 return mapiFunctions
.HrQueryAllRows(lpTable
, lpPropTags
, lpRestriction
, lpSortOrderSet
, crowsMax
, lppRows
);
919 FIXME("(%p, %p, %p, %p, %d, %p): stub\n", lpTable
, lpPropTags
, lpRestriction
, lpSortOrderSet
, crowsMax
, lppRows
);
921 return MAPI_E_CALL_FAILED
;
924 /**************************************************************************
925 * WrapCompressedRTFStream (MAPI32.186)
927 HRESULT WINAPI
WrapCompressedRTFStream(LPSTREAM compressed
, ULONG flags
, LPSTREAM
*uncompressed
)
929 if (mapiFunctions
.WrapCompressedRTFStream
)
930 return mapiFunctions
.WrapCompressedRTFStream(compressed
, flags
, uncompressed
);
932 FIXME("(%p, 0x%08x, %p): stub\n", compressed
, flags
, uncompressed
);
933 return MAPI_E_NO_SUPPORT
;
936 static HMODULE mapi_provider
;
937 static HMODULE mapi_ex_provider
;
939 /**************************************************************************
942 * Attempts to load a MAPI provider from the specified registry key.
944 * Returns a handle to the loaded module in `mapi_provider' if successful.
946 static void load_mapi_provider(HKEY hkeyMail
, LPCWSTR valueName
, HMODULE
*mapi_provider
)
948 static const WCHAR mapi32_dll
[] = {'m','a','p','i','3','2','.','d','l','l',0 };
950 DWORD dwType
, dwLen
= 0;
953 /* Check if we have a value set for DLLPath */
954 if ((RegQueryValueExW(hkeyMail
, valueName
, NULL
, &dwType
, NULL
, &dwLen
) == ERROR_SUCCESS
) &&
955 ((dwType
== REG_SZ
) || (dwType
== REG_EXPAND_SZ
)) && (dwLen
> 0))
957 dllPath
= HeapAlloc(GetProcessHeap(), 0, dwLen
);
961 RegQueryValueExW(hkeyMail
, valueName
, NULL
, NULL
, (LPBYTE
)dllPath
, &dwLen
);
963 /* Check that this value doesn't refer to mapi32.dll (eg, as Outlook does) */
964 if (lstrcmpiW(dllPath
, mapi32_dll
) != 0)
966 if (dwType
== REG_EXPAND_SZ
)
969 LPWSTR dllPathExpanded
;
971 /* Expand the path if necessary */
972 dwExpandLen
= ExpandEnvironmentStringsW(dllPath
, NULL
, 0);
973 dllPathExpanded
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * dwExpandLen
+ 1);
977 ExpandEnvironmentStringsW(dllPath
, dllPathExpanded
, dwExpandLen
+ 1);
979 HeapFree(GetProcessHeap(), 0, dllPath
);
980 dllPath
= dllPathExpanded
;
985 TRACE("loading %s\n", debugstr_w(dllPath
));
986 *mapi_provider
= LoadLibraryW(dllPath
);
989 HeapFree(GetProcessHeap(), 0, dllPath
);
994 /**************************************************************************
995 * load_mapi_providers
997 * Scans the registry for MAPI providers and attempts to load a Simple and
998 * Extended MAPI library.
1000 * Returns TRUE if at least one library loaded, FALSE otherwise.
1002 void load_mapi_providers(void)
1004 static const WCHAR regkey_mail
[] = {
1005 'S','o','f','t','w','a','r','e','\\','C','l','i','e','n','t','s','\\',
1006 'M','a','i','l',0 };
1008 static const WCHAR regkey_dllpath
[] = {'D','L','L','P','a','t','h',0 };
1009 static const WCHAR regkey_dllpath_ex
[] = {'D','L','L','P','a','t','h','E','x',0 };
1010 static const WCHAR regkey_backslash
[] = { '\\', 0 };
1013 DWORD dwType
, dwLen
= 0;
1014 LPWSTR appName
= NULL
, appKey
= NULL
;
1018 /* Open the Mail key */
1019 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, regkey_mail
, 0, KEY_READ
, &hkeyMail
) != ERROR_SUCCESS
)
1022 /* Check if we have a default value set, and the length of it */
1023 if ((RegQueryValueExW(hkeyMail
, NULL
, NULL
, &dwType
, NULL
, &dwLen
) != ERROR_SUCCESS
) ||
1024 !((dwType
== REG_SZ
) || (dwType
== REG_EXPAND_SZ
)) || (dwLen
== 0))
1027 appName
= HeapAlloc(GetProcessHeap(), 0, dwLen
);
1032 /* Get the value, and get the path to the app key */
1033 RegQueryValueExW(hkeyMail
, NULL
, NULL
, NULL
, (LPBYTE
)appName
, &dwLen
);
1035 TRACE("appName: %s\n", debugstr_w(appName
));
1037 appKey
= HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR
) * (lstrlenW(regkey_mail
) +
1038 lstrlenW(regkey_backslash
) + lstrlenW(appName
) + 1));
1043 lstrcpyW(appKey
, regkey_mail
);
1044 lstrcatW(appKey
, regkey_backslash
);
1045 lstrcatW(appKey
, appName
);
1047 RegCloseKey(hkeyMail
);
1049 TRACE("appKey: %s\n", debugstr_w(appKey
));
1051 /* Open the app's key */
1052 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE
, appKey
, 0, KEY_READ
, &hkeyMail
) != ERROR_SUCCESS
)
1055 /* Try to load the providers */
1056 load_mapi_provider(hkeyMail
, regkey_dllpath
, &mapi_provider
);
1057 load_mapi_provider(hkeyMail
, regkey_dllpath_ex
, &mapi_ex_provider
);
1059 /* Now try to load our function pointers */
1060 ZeroMemory(&mapiFunctions
, sizeof(mapiFunctions
));
1062 /* Simple MAPI functions */
1065 mapiFunctions
.MAPIAddress
= (void*) GetProcAddress(mapi_provider
, "MAPIAddress");
1066 mapiFunctions
.MAPIDeleteMail
= (void*) GetProcAddress(mapi_provider
, "MAPIDeleteMail");
1067 mapiFunctions
.MAPIDetails
= (void*) GetProcAddress(mapi_provider
, "MAPIDetails");
1068 mapiFunctions
.MAPIFindNext
= (void*) GetProcAddress(mapi_provider
, "MAPIFindNext");
1069 mapiFunctions
.MAPILogoff
= (void*) GetProcAddress(mapi_provider
, "MAPILogoff");
1070 mapiFunctions
.MAPILogon
= (void*) GetProcAddress(mapi_provider
, "MAPILogon");
1071 mapiFunctions
.MAPIReadMail
= (void*) GetProcAddress(mapi_provider
, "MAPIReadMail");
1072 mapiFunctions
.MAPIResolveName
= (void*) GetProcAddress(mapi_provider
, "MAPIResolveName");
1073 mapiFunctions
.MAPISaveMail
= (void*) GetProcAddress(mapi_provider
, "MAPISaveMail");
1074 mapiFunctions
.MAPISendDocuments
= (void*) GetProcAddress(mapi_provider
, "MAPISendDocuments");
1075 mapiFunctions
.MAPISendMail
= (void*) GetProcAddress(mapi_provider
, "MAPISendMail");
1076 mapiFunctions
.MAPISendMailW
= (void*) GetProcAddress(mapi_provider
, "MAPISendMailW");
1079 /* Extended MAPI functions */
1080 if (mapi_ex_provider
)
1082 mapiFunctions
.MAPIInitialize
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIInitialize");
1083 mapiFunctions
.MAPILogonEx
= (void*) GetProcAddress(mapi_ex_provider
, "MAPILogonEx");
1084 mapiFunctions
.MAPIUninitialize
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIUninitialize");
1086 mapiFunctions
.DeinitMapiUtil
= (void*) GetProcAddress(mapi_ex_provider
, "DeinitMapiUtil@0");
1087 mapiFunctions
.DllCanUnloadNow
= (void*) GetProcAddress(mapi_ex_provider
, "DllCanUnloadNow");
1088 mapiFunctions
.DllGetClassObject
= (void*) GetProcAddress(mapi_ex_provider
, "DllGetClassObject");
1089 mapiFunctions
.FGetComponentPath
= (void*) GetProcAddress(mapi_ex_provider
, "FGetComponentPath");
1090 mapiFunctions
.HrThisThreadAdviseSink
= (void*) GetProcAddress(mapi_ex_provider
, "HrThisThreadAdviseSink@8");
1091 mapiFunctions
.HrQueryAllRows
= (void*) GetProcAddress(mapi_ex_provider
, "HrQueryAllRows@24");
1092 mapiFunctions
.MAPIAdminProfiles
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIAdminProfiles");
1093 mapiFunctions
.MAPIAllocateBuffer
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIAllocateBuffer");
1094 mapiFunctions
.MAPIAllocateMore
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIAllocateMore");
1095 mapiFunctions
.MAPIFreeBuffer
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIFreeBuffer");
1096 mapiFunctions
.MAPIGetDefaultMalloc
= (void*) GetProcAddress(mapi_ex_provider
, "MAPIGetDefaultMalloc@0");
1097 mapiFunctions
.MAPIOpenLocalFormContainer
= (void *) GetProcAddress(mapi_ex_provider
, "MAPIOpenLocalFormContainer");
1098 mapiFunctions
.OpenStreamOnFile
= (void*) GetProcAddress(mapi_ex_provider
, "OpenStreamOnFile@24");
1099 mapiFunctions
.ScInitMapiUtil
= (void*) GetProcAddress(mapi_ex_provider
, "ScInitMapiUtil@4");
1100 mapiFunctions
.WrapCompressedRTFStream
= (void*) GetProcAddress(mapi_ex_provider
, "WrapCompressedRTFStream@12");
1104 RegCloseKey(hkeyMail
);
1105 HeapFree(GetProcessHeap(), 0, appKey
);
1106 HeapFree(GetProcessHeap(), 0, appName
);
1109 /**************************************************************************
1110 * unload_mapi_providers
1112 * Unloads any loaded MAPI libraries.
1114 void unload_mapi_providers(void)
1118 FreeLibrary(mapi_provider
);
1119 FreeLibrary(mapi_ex_provider
);