ReactOS 0.4.15-dev-5669-g09dde2c
util.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winreg.h"
#include "winuser.h"
#include "winerror.h"
#include "winternl.h"
#include "objbase.h"
#include "shlwapi.h"
#include "wine/debug.h"
#include "mapival.h"
#include "xcmc.h"
#include "msi.h"
#include "util.h"
Include dependency graph for util.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Typedefs

typedef LPVOIDLPMAPIALLOCBUFFER
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (mapi)
 
SCODE WINAPI ScInitMapiUtil (ULONG ulReserved)
 
VOID WINAPI DeinitMapiUtil (void)
 
SCODE WINAPI MAPIAllocateBuffer (ULONG cbSize, LPVOID *lppBuffer)
 
SCODE WINAPI MAPIAllocateMore (ULONG cbSize, LPVOID lpOrig, LPVOID *lppBuffer)
 
ULONG WINAPI MAPIFreeBuffer (LPVOID lpBuffer)
 
HRESULT WINAPI WrapProgress (PVOID unk1, PVOID unk2, PVOID unk3, PVOID unk4, PVOID unk5)
 
HRESULT WINAPI HrDispatchNotifications (ULONG flags)
 
HRESULT WINAPI HrThisThreadAdviseSink (LPMAPIADVISESINK lpSink, LPMAPIADVISESINK *lppNewSink)
 
BOOL WINAPI FBinFromHex (LPWSTR lpszHex, LPBYTE lpOut)
 
void WINAPI HexFromBin (LPBYTE lpHex, int iCount, LPWSTR lpszOut)
 
VOID WINAPI SwapPlong (PULONG lpData, ULONG ulLen)
 
VOID WINAPI SwapPword (PUSHORT lpData, ULONG ulLen)
 
ULONG WINAPI MNLS_lstrlenW (LPCWSTR lpszStr)
 
INT WINAPI MNLS_lstrcmpW (LPCWSTR lpszLeft, LPCWSTR lpszRight)
 
ULONG WINAPI MNLS_lstrcpyW (LPWSTR lpszDest, LPCWSTR lpszSrc)
 
INT WINAPI MNLS_CompareStringW (DWORD dwCp, LPCWSTR lpszLeft, LPCWSTR lpszRight)
 
BOOL WINAPI FEqualNames (LPMAPINAMEID lpName1, LPMAPINAMEID lpName2)
 
BOOL WINAPI IsBadBoundedStringPtr (LPCSTR lpszStr, ULONG ulLen)
 
LONGLONG WINAPI MAPI32_FtAddFt (FILETIME ftLeft, FILETIME ftRight)
 
LONGLONG WINAPI MAPI32_FtSubFt (FILETIME ftLeft, FILETIME ftRight)
 
LONGLONG WINAPI MAPI32_FtMulDw (DWORD dwLeft, FILETIME ftRight)
 
LONGLONG WINAPI MAPI32_FtMulDwDw (DWORD dwLeft, DWORD dwRight)
 
LONGLONG WINAPI MAPI32_FtNegFt (FILETIME ft)
 
ULONG WINAPI UlAddRef (void *lpUnk)
 
ULONG WINAPI UlRelease (void *lpUnk)
 
UINT WINAPI UFromSz (LPCSTR lpszStr)
 
HRESULT WINAPI OpenStreamOnFile (LPALLOCATEBUFFER lpAlloc, LPFREEBUFFER lpFree, ULONG ulFlags, LPWSTR lpszPath, LPWSTR lpszPrefix, LPSTREAM *lppStream)
 
ULONG WINAPI UlFromSzHex (LPCWSTR lpszHex)
 
BOOL WINAPI FBadEntryList (LPENTRYLIST lpEntryList)
 
ULONG WINAPI CbOfEncoded (LPCSTR lpszEnc)
 
CMC_return_code WINAPI cmc_query_configuration (CMC_session_id session, CMC_enum item, CMC_buffer reference, CMC_extension *config_extensions)
 
BOOL WINAPI FGetComponentPath (LPCSTR component, LPCSTR qualifier, LPSTR dll_path, DWORD dll_path_length, BOOL install)
 
HRESULT WINAPI HrQueryAllRows (LPMAPITABLE lpTable, LPSPropTagArray lpPropTags, LPSRestriction lpRestriction, LPSSortOrderSet lpSortOrderSet, LONG crowsMax, LPSRowSet *lppRows)
 
HRESULT WINAPI WrapCompressedRTFStream (LPSTREAM compressed, ULONG flags, LPSTREAM *uncompressed)
 
static void load_mapi_provider (HKEY hkeyMail, LPCWSTR valueName, HMODULE *mapi_provider)
 
void load_mapi_providers (void)
 
void unload_mapi_providers (void)
 

Variables

static const BYTE digitsToHex []
 
MAPI_FUNCTIONS mapiFunctions
 
static HMODULE mapi_provider
 
static HMODULE mapi_ex_provider
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 25 of file util.c.

Typedef Documentation

◆ LPMAPIALLOCBUFFER

Definition at line 101 of file util.c.

Function Documentation

◆ CbOfEncoded()

ULONG WINAPI CbOfEncoded ( LPCSTR  lpszEnc)

Definition at line 823 of file util.c.

824{
825 ULONG ulRet = 0;
826
827 TRACE("(%s)\n", debugstr_a(lpszEnc));
828
829 if (lpszEnc)
830 ulRet = (((strlen(lpszEnc) | 3) >> 2) + 1) * 3;
831 return ulRet;
832}
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define debugstr_a
Definition: kernel32.h:31
#define TRACE(s)
Definition: solgame.cpp:4
uint32_t ULONG
Definition: typedefs.h:59

◆ cmc_query_configuration()

CMC_return_code WINAPI cmc_query_configuration ( CMC_session_id  session,
CMC_enum  item,
CMC_buffer  reference,
CMC_extension config_extensions 
)

Definition at line 849 of file util.c.

854{
855 FIXME("stub\n");
856 return CMC_E_NOT_SUPPORTED;
857}
#define FIXME(fmt,...)
Definition: debug.h:111
#define CMC_E_NOT_SUPPORTED
Definition: xcmc.h:67

◆ DeinitMapiUtil()

VOID WINAPI DeinitMapiUtil ( void  )

Definition at line 93 of file util.c.

94{
95 if (mapiFunctions.DeinitMapiUtil)
96 mapiFunctions.DeinitMapiUtil();
97 else
98 FIXME("()stub!\n");
99}
MAPI_FUNCTIONS mapiFunctions
Definition: util.c:49

◆ FBadEntryList()

BOOL WINAPI FBadEntryList ( LPENTRYLIST  lpEntryList)

Definition at line 796 of file util.c.

797{
798 ULONG i;
799
800 if (IsBadReadPtr(lpEntryList, sizeof(*lpEntryList)) ||
801 IsBadReadPtr(lpEntryList->lpbin,
802 lpEntryList->cValues * sizeof(*lpEntryList->lpbin)))
803 return TRUE;
804
805 for (i = 0; i < lpEntryList->cValues; i++)
806 if(IsBadReadPtr(lpEntryList->lpbin[i].lpb, lpEntryList->lpbin[i].cb))
807 return TRUE;
808
809 return FALSE;
810}
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI IsBadReadPtr(IN LPCVOID lp, IN UINT_PTR ucb)
Definition: except.c:803
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
ULONG cValues
Definition: mapidefs.h:296
SBinary * lpbin
Definition: mapidefs.h:297
LPBYTE lpb
Definition: mapidefs.h:290
ULONG cb
Definition: mapidefs.h:289

Referenced by FBadProp().

◆ FBinFromHex()

BOOL WINAPI FBinFromHex ( LPWSTR  lpszHex,
LPBYTE  lpOut 
)

Definition at line 298 of file util.c.

299{
300 LPSTR lpStr = (LPSTR)lpszHex;
301
302 TRACE("(%p,%p)\n", lpszHex, lpOut);
303
304 while (*lpStr)
305 {
306 if (lpStr[0] < '0' || lpStr[0] > 'f' || digitsToHex[lpStr[0] - '0'] == 0xff ||
307 lpStr[1] < '0' || lpStr[1] > 'f' || digitsToHex[lpStr[1] - '0'] == 0xff)
308 return FALSE;
309
310 *lpOut++ = (digitsToHex[lpStr[0] - '0'] << 4) | digitsToHex[lpStr[1] - '0'];
311 lpStr += 2;
312 }
313 return TRUE;
314}
static const BYTE digitsToHex[]
Definition: util.c:43
char * LPSTR
Definition: xmlstorage.h:182

◆ FEqualNames()

BOOL WINAPI FEqualNames ( LPMAPINAMEID  lpName1,
LPMAPINAMEID  lpName2 
)

Definition at line 486 of file util.c.

487{
488 TRACE("(%p,%p)\n", lpName1, lpName2);
489
490 if (!lpName1 || !lpName2 ||
491 !IsEqualGUID(lpName1->lpguid, lpName2->lpguid) ||
492 lpName1->ulKind != lpName2->ulKind)
493 return FALSE;
494
495 if (lpName1->ulKind == MNID_STRING)
496 return !lstrcmpW(lpName1->Kind.lpwstrName, lpName2->Kind.lpwstrName);
497
498 return lpName1->Kind.lID == lpName2->Kind.lID;
499}
int WINAPI lstrcmpW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:170
#define MNID_STRING
Definition: mapidefs.h:638
#define IsEqualGUID(rguid1, rguid2)
Definition: guiddef.h:147
ULONG ulKind
Definition: mapidefs.h:643
LPWSTR lpwstrName
Definition: mapidefs.h:647
LPGUID lpguid
Definition: mapidefs.h:642
LONG lID
Definition: mapidefs.h:646
union _MAPINAMEID::@3011 Kind

◆ FGetComponentPath()

BOOL WINAPI FGetComponentPath ( LPCSTR  component,
LPCSTR  qualifier,
LPSTR  dll_path,
DWORD  dll_path_length,
BOOL  install 
)

Definition at line 880 of file util.c.

882{
883 BOOL ret = FALSE;
884 HMODULE hmsi;
885
886 TRACE("%s %s %p %u %d\n", component, qualifier, dll_path, dll_path_length, install);
887
888 if (mapiFunctions.FGetComponentPath)
889 return mapiFunctions.FGetComponentPath(component, qualifier, dll_path, dll_path_length, install);
890
891 dll_path[0] = 0;
892
893 hmsi = LoadLibraryA("msi.dll");
894 if (hmsi)
895 {
896 UINT (WINAPI *pMsiProvideQualifiedComponentA)(LPCSTR, LPCSTR, DWORD, LPSTR, LPDWORD);
897
898 pMsiProvideQualifiedComponentA = (void *)GetProcAddress(hmsi, "MsiProvideQualifiedComponentA");
899 if (pMsiProvideQualifiedComponentA)
900 {
901 static const char * const fmt[] = { "%d\\NT", "%d\\95", "%d" };
902 char lcid_ver[20];
903 UINT i;
904
905 for (i = 0; i < ARRAY_SIZE(fmt); i++)
906 {
907 /* FIXME: what's the correct behaviour here? */
908 if (!qualifier || qualifier == lcid_ver)
909 {
910 sprintf(lcid_ver, fmt[i], GetUserDefaultUILanguage());
911 qualifier = lcid_ver;
912 }
913
914 if (pMsiProvideQualifiedComponentA(component, qualifier,
916 dll_path, &dll_path_length) == ERROR_SUCCESS)
917 {
918 ret = TRUE;
919 break;
920 }
921
922 if (qualifier != lcid_ver) break;
923 }
924 }
925 FreeLibrary(hmsi);
926 }
927 return ret;
928}
#define ARRAY_SIZE(a)
Definition: main.h:24
#define ERROR_SUCCESS
Definition: deptool.c:10
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
unsigned int BOOL
Definition: ntddk_ex.h:94
LANGID WINAPI GetUserDefaultUILanguage(void)
Definition: lang.c:810
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static APTTYPEQUALIFIER * qualifier
Definition: compobj.c:79
int install
Definition: msacm.c:1365
@ INSTALLMODE_EXISTING
Definition: msi.h:165
@ INSTALLMODE_DEFAULT
Definition: msi.h:166
unsigned int UINT
Definition: ndis.h:50
#define LPDWORD
Definition: nt_native.h:46
#define DWORD
Definition: nt_native.h:44
Definition: dsound.c:943
int ret
#define WINAPI
Definition: msvc.h:6
const char * LPCSTR
Definition: xmlstorage.h:183

◆ HexFromBin()

void WINAPI HexFromBin ( LPBYTE  lpHex,
int  iCount,
LPWSTR  lpszOut 
)

Definition at line 336 of file util.c.

337{
338 static const char hexDigits[] = { "0123456789ABCDEF" };
339 LPSTR lpStr = (LPSTR)lpszOut;
340
341 TRACE("(%p,%d,%p)\n", lpHex, iCount, lpszOut);
342
343 while (iCount-- > 0)
344 {
345 *lpStr++ = hexDigits[*lpHex >> 4];
346 *lpStr++ = hexDigits[*lpHex & 0xf];
347 lpHex++;
348 }
349 *lpStr = '\0';
350}
static const CHAR hexDigits[]
Definition: url.c:109

◆ HrDispatchNotifications()

HRESULT WINAPI HrDispatchNotifications ( ULONG  flags)

Definition at line 243 of file util.c.

244{
245 FIXME("(%08x)\n", flags);
246 return S_OK;
247}
GLbitfield flags
Definition: glext.h:7161
#define S_OK
Definition: intsafe.h:52

◆ HrQueryAllRows()

HRESULT WINAPI HrQueryAllRows ( LPMAPITABLE  lpTable,
LPSPropTagArray  lpPropTags,
LPSRestriction  lpRestriction,
LPSSortOrderSet  lpSortOrderSet,
LONG  crowsMax,
LPSRowSet lppRows 
)

Definition at line 933 of file util.c.

936{
937 if (mapiFunctions.HrQueryAllRows)
938 return mapiFunctions.HrQueryAllRows(lpTable, lpPropTags, lpRestriction, lpSortOrderSet, crowsMax, lppRows);
939
940 FIXME("(%p, %p, %p, %p, %d, %p): stub\n", lpTable, lpPropTags, lpRestriction, lpSortOrderSet, crowsMax, lppRows);
941 *lppRows = NULL;
942 return MAPI_E_CALL_FAILED;
943}
#define NULL
Definition: types.h:112
#define MAPI_E_CALL_FAILED
Definition: mapicode.h:43

◆ HrThisThreadAdviseSink()

HRESULT WINAPI HrThisThreadAdviseSink ( LPMAPIADVISESINK  lpSink,
LPMAPIADVISESINK lppNewSink 
)

Definition at line 262 of file util.c.

263{
264 if (mapiFunctions.HrThisThreadAdviseSink)
265 return mapiFunctions.HrThisThreadAdviseSink(lpSink, lppNewSink);
266
267 FIXME("(%p,%p)semi-stub\n", lpSink, lppNewSink);
268
269 if (!lpSink || !lppNewSink)
270 return E_INVALIDARG;
271
272 /* Don't wrap the sink for now, just copy it */
273 *lppNewSink = lpSink;
275 return S_OK;
276}
#define E_INVALIDARG
Definition: ddrawi.h:101
#define IMAPIAdviseSink_AddRef(p)
Definition: mapidefs.h:860

◆ IsBadBoundedStringPtr()

BOOL WINAPI IsBadBoundedStringPtr ( LPCSTR  lpszStr,
ULONG  ulLen 
)

Definition at line 514 of file util.c.

515{
516 if (!lpszStr || IsBadStringPtrA(lpszStr, -1) || strlen(lpszStr) >= ulLen)
517 return TRUE;
518 return FALSE;
519}
BOOL NTAPI IsBadStringPtrA(IN LPCSTR lpsz, IN UINT_PTR ucchMax)
Definition: except.c:987

◆ load_mapi_provider()

static void load_mapi_provider ( HKEY  hkeyMail,
LPCWSTR  valueName,
HMODULE mapi_provider 
)
static

Definition at line 967 of file util.c.

968{
969 static const WCHAR mapi32_dll[] = {'m','a','p','i','3','2','.','d','l','l',0 };
970
971 DWORD dwType, dwLen = 0;
972 LPWSTR dllPath;
973
974 /* Check if we have a value set for DLLPath */
975 if ((RegQueryValueExW(hkeyMail, valueName, NULL, &dwType, NULL, &dwLen) == ERROR_SUCCESS) &&
976 ((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ)) && (dwLen > 0))
977 {
978 dllPath = HeapAlloc(GetProcessHeap(), 0, dwLen);
979
980 if (dllPath)
981 {
982 RegQueryValueExW(hkeyMail, valueName, NULL, NULL, (LPBYTE)dllPath, &dwLen);
983
984 /* Check that this value doesn't refer to mapi32.dll (eg, as Outlook does) */
985 if (lstrcmpiW(dllPath, mapi32_dll) != 0)
986 {
987 if (dwType == REG_EXPAND_SZ)
988 {
989 DWORD dwExpandLen;
990 LPWSTR dllPathExpanded;
991
992 /* Expand the path if necessary */
993 dwExpandLen = ExpandEnvironmentStringsW(dllPath, NULL, 0);
994 dllPathExpanded = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * dwExpandLen + 1);
995
996 if (dllPathExpanded)
997 {
998 ExpandEnvironmentStringsW(dllPath, dllPathExpanded, dwExpandLen + 1);
999
1000 HeapFree(GetProcessHeap(), 0, dllPath);
1001 dllPath = dllPathExpanded;
1002 }
1003 }
1004
1005 /* Load the DLL */
1006 TRACE("loading %s\n", debugstr_w(dllPath));
1007 *mapi_provider = LoadLibraryW(dllPath);
1008 }
1009
1010 HeapFree(GetProcessHeap(), 0, dllPath);
1011 }
1012 }
1013}
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4121
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define LoadLibraryW(x)
Definition: compat.h:747
DWORD WINAPI ExpandEnvironmentStringsW(IN LPCWSTR lpSrc, IN LPWSTR lpDst, IN DWORD nSize)
Definition: environ.c:519
static HMODULE mapi_provider
Definition: util.c:957
unsigned long DWORD
Definition: ntddk_ex.h:95
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
int WINAPI lstrcmpiW(LPCWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:194
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
unsigned char * LPBYTE
Definition: typedefs.h:53
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by load_mapi_providers().

◆ load_mapi_providers()

void load_mapi_providers ( void  )

Definition at line 1023 of file util.c.

1024{
1025 static const WCHAR regkey_mail[] = {
1026 'S','o','f','t','w','a','r','e','\\','C','l','i','e','n','t','s','\\',
1027 'M','a','i','l',0 };
1028
1029 static const WCHAR regkey_dllpath[] = {'D','L','L','P','a','t','h',0 };
1030 static const WCHAR regkey_dllpath_ex[] = {'D','L','L','P','a','t','h','E','x',0 };
1031 static const WCHAR regkey_backslash[] = { '\\', 0 };
1032
1033 HKEY hkeyMail;
1034 DWORD dwType, dwLen = 0;
1035 LPWSTR appName = NULL, appKey = NULL;
1036
1037 TRACE("()\n");
1038
1039 /* Open the Mail key */
1040 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, regkey_mail, 0, KEY_READ, &hkeyMail) != ERROR_SUCCESS)
1041 return;
1042
1043 /* Check if we have a default value set, and the length of it */
1044 if ((RegQueryValueExW(hkeyMail, NULL, NULL, &dwType, NULL, &dwLen) != ERROR_SUCCESS) ||
1045 !((dwType == REG_SZ) || (dwType == REG_EXPAND_SZ)) || (dwLen == 0))
1046 goto cleanUp;
1047
1048 appName = HeapAlloc(GetProcessHeap(), 0, dwLen);
1049
1050 if (!appName)
1051 goto cleanUp;
1052
1053 /* Get the value, and get the path to the app key */
1054 RegQueryValueExW(hkeyMail, NULL, NULL, NULL, (LPBYTE)appName, &dwLen);
1055
1056 TRACE("appName: %s\n", debugstr_w(appName));
1057
1058 appKey = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR) * (lstrlenW(regkey_mail) +
1059 lstrlenW(regkey_backslash) + lstrlenW(appName) + 1));
1060
1061 if (!appKey)
1062 goto cleanUp;
1063
1064 lstrcpyW(appKey, regkey_mail);
1065 lstrcatW(appKey, regkey_backslash);
1066 lstrcatW(appKey, appName);
1067
1068 RegCloseKey(hkeyMail);
1069
1070 TRACE("appKey: %s\n", debugstr_w(appKey));
1071
1072 /* Open the app's key */
1073 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, appKey, 0, KEY_READ, &hkeyMail) != ERROR_SUCCESS)
1074 goto cleanUp;
1075
1076 /* Try to load the providers */
1077 load_mapi_provider(hkeyMail, regkey_dllpath, &mapi_provider);
1078 load_mapi_provider(hkeyMail, regkey_dllpath_ex, &mapi_ex_provider);
1079
1080 /* Now try to load our function pointers */
1082
1083 /* Simple MAPI functions */
1084 if (mapi_provider)
1085 {
1086 mapiFunctions.MAPIAddress = (void*) GetProcAddress(mapi_provider, "MAPIAddress");
1087 mapiFunctions.MAPIDeleteMail = (void*) GetProcAddress(mapi_provider, "MAPIDeleteMail");
1088 mapiFunctions.MAPIDetails = (void*) GetProcAddress(mapi_provider, "MAPIDetails");
1089 mapiFunctions.MAPIFindNext = (void*) GetProcAddress(mapi_provider, "MAPIFindNext");
1090 mapiFunctions.MAPILogoff = (void*) GetProcAddress(mapi_provider, "MAPILogoff");
1091 mapiFunctions.MAPILogon = (void*) GetProcAddress(mapi_provider, "MAPILogon");
1092 mapiFunctions.MAPIReadMail = (void*) GetProcAddress(mapi_provider, "MAPIReadMail");
1093 mapiFunctions.MAPIResolveName = (void*) GetProcAddress(mapi_provider, "MAPIResolveName");
1094 mapiFunctions.MAPISaveMail = (void*) GetProcAddress(mapi_provider, "MAPISaveMail");
1095 mapiFunctions.MAPISendDocuments = (void*) GetProcAddress(mapi_provider, "MAPISendDocuments");
1096 mapiFunctions.MAPISendMail = (void*) GetProcAddress(mapi_provider, "MAPISendMail");
1097 mapiFunctions.MAPISendMailW = (void*) GetProcAddress(mapi_provider, "MAPISendMailW");
1098 }
1099
1100 /* Extended MAPI functions */
1101 if (mapi_ex_provider)
1102 {
1103 mapiFunctions.MAPIInitialize = (void*) GetProcAddress(mapi_ex_provider, "MAPIInitialize");
1104 mapiFunctions.MAPILogonEx = (void*) GetProcAddress(mapi_ex_provider, "MAPILogonEx");
1105 mapiFunctions.MAPIUninitialize = (void*) GetProcAddress(mapi_ex_provider, "MAPIUninitialize");
1106
1107 mapiFunctions.DeinitMapiUtil = (void*) GetProcAddress(mapi_ex_provider, "DeinitMapiUtil@0");
1108 mapiFunctions.DllCanUnloadNow = (void*) GetProcAddress(mapi_ex_provider, "DllCanUnloadNow");
1109 mapiFunctions.DllGetClassObject = (void*) GetProcAddress(mapi_ex_provider, "DllGetClassObject");
1110 mapiFunctions.FGetComponentPath = (void*) GetProcAddress(mapi_ex_provider, "FGetComponentPath");
1111 mapiFunctions.HrThisThreadAdviseSink = (void*) GetProcAddress(mapi_ex_provider, "HrThisThreadAdviseSink@8");
1112 mapiFunctions.HrQueryAllRows = (void*) GetProcAddress(mapi_ex_provider, "HrQueryAllRows@24");
1113 mapiFunctions.MAPIAdminProfiles = (void*) GetProcAddress(mapi_ex_provider, "MAPIAdminProfiles");
1114 mapiFunctions.MAPIAllocateBuffer = (void*) GetProcAddress(mapi_ex_provider, "MAPIAllocateBuffer");
1115 mapiFunctions.MAPIAllocateMore = (void*) GetProcAddress(mapi_ex_provider, "MAPIAllocateMore");
1116 mapiFunctions.MAPIFreeBuffer = (void*) GetProcAddress(mapi_ex_provider, "MAPIFreeBuffer");
1117 mapiFunctions.MAPIGetDefaultMalloc = (void*) GetProcAddress(mapi_ex_provider, "MAPIGetDefaultMalloc@0");
1118 mapiFunctions.MAPIOpenLocalFormContainer = (void *) GetProcAddress(mapi_ex_provider, "MAPIOpenLocalFormContainer");
1119 mapiFunctions.OpenStreamOnFile = (void*) GetProcAddress(mapi_ex_provider, "OpenStreamOnFile@24");
1120 mapiFunctions.ScInitMapiUtil = (void*) GetProcAddress(mapi_ex_provider, "ScInitMapiUtil@4");
1121 mapiFunctions.WrapCompressedRTFStream = (void*) GetProcAddress(mapi_ex_provider, "WrapCompressedRTFStream@12");
1122 }
1123
1124cleanUp:
1125 RegCloseKey(hkeyMail);
1126 HeapFree(GetProcessHeap(), 0, appKey);
1128}
#define RegCloseKey(hKey)
Definition: registry.h:47
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3356
#define lstrcpyW
Definition: compat.h:749
#define lstrlenW
Definition: compat.h:750
static void load_mapi_provider(HKEY hkeyMail, LPCWSTR valueName, HMODULE *mapi_provider)
Definition: util.c:967
static HMODULE mapi_ex_provider
Definition: util.c:958
void cleanUp()
Definition: main.cpp:472
const char * appName(const char *argv0)
Definition: loadlib.c:89
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
#define KEY_READ
Definition: nt_native.h:1023
LPMAPILOGOFF MAPILogoff
Definition: util.h:37
LPMAPILOGON MAPILogon
Definition: util.h:38
LPMAPISENDMAIL MAPISendMail
Definition: util.h:43
LPMAPILOGONEX MAPILogonEx
Definition: util.h:39
LPMAPIDELETEMAIL MAPIDeleteMail
Definition: util.h:33
LPMAPISENDDOCUMENTS MAPISendDocuments
Definition: util.h:45
LPMAPIINITIALIZE MAPIInitialize
Definition: util.h:36
LPMAPISAVEMAIL MAPISaveMail
Definition: util.h:42
LPMAPIFINDNEXT MAPIFindNext
Definition: util.h:35
LPMAPIRESOLVENAME MAPIResolveName
Definition: util.h:41
LPMAPIREADMAIL MAPIReadMail
Definition: util.h:40
LPMAPIADDRESS MAPIAddress
Definition: util.h:32
LPMAPIUNINITIALIZE MAPIUninitialize
Definition: util.h:46
LPMAPISENDMAILW MAPISendMailW
Definition: util.h:44
LPMAPIDETAILS MAPIDetails
Definition: util.h:34
#define ZeroMemory
Definition: winbase.h:1670
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by DllMain().

◆ MAPI32_FtAddFt()

LONGLONG WINAPI MAPI32_FtAddFt ( FILETIME  ftLeft,
FILETIME  ftRight 
)

Definition at line 533 of file util.c.

534{
535 LONGLONG *pl = (LONGLONG*)&ftLeft, *pr = (LONGLONG*)&ftRight;
536
537 return *pl + *pr;
538}
int64_t LONGLONG
Definition: typedefs.h:68

◆ MAPI32_FtMulDw()

LONGLONG WINAPI MAPI32_FtMulDw ( DWORD  dwLeft,
FILETIME  ftRight 
)

Definition at line 571 of file util.c.

572{
573 LONGLONG *pr = (LONGLONG*)&ftRight;
574
575 return (LONGLONG)dwLeft * (*pr);
576}

◆ MAPI32_FtMulDwDw()

LONGLONG WINAPI MAPI32_FtMulDwDw ( DWORD  dwLeft,
DWORD  dwRight 
)

Definition at line 590 of file util.c.

591{
592 return (LONGLONG)dwLeft * (LONGLONG)dwRight;
593}

◆ MAPI32_FtNegFt()

LONGLONG WINAPI MAPI32_FtNegFt ( FILETIME  ft)

Definition at line 606 of file util.c.

607{
608 LONGLONG *p = (LONGLONG*)&ft;
609
610 return - *p;
611}
GLfloat GLfloat p
Definition: glext.h:8902

◆ MAPI32_FtSubFt()

LONGLONG WINAPI MAPI32_FtSubFt ( FILETIME  ftLeft,
FILETIME  ftRight 
)

Definition at line 552 of file util.c.

553{
554 LONGLONG *pl = (LONGLONG*)&ftLeft, *pr = (LONGLONG*)&ftRight;
555
556 return *pr - *pl;
557}

◆ MAPIAllocateBuffer()

SCODE WINAPI MAPIAllocateBuffer ( ULONG  cbSize,
LPVOID lppBuffer 
)

Definition at line 125 of file util.c.

126{
127 LPMAPIALLOCBUFFER lpBuff;
128
129 TRACE("(%d,%p)\n", cbSize, lppBuffer);
130
131 if (mapiFunctions.MAPIAllocateBuffer)
132 return mapiFunctions.MAPIAllocateBuffer(cbSize, lppBuffer);
133
134 if (!lppBuffer)
135 return E_INVALIDARG;
136
137 lpBuff = HeapAlloc(GetProcessHeap(), 0, cbSize + sizeof(*lpBuff));
138 if (!lpBuff)
140
141 TRACE("initial allocation:%p, returning %p\n", lpBuff, lpBuff + 1);
142 *lpBuff++ = NULL;
143 *lppBuffer = lpBuff;
144 return S_OK;
145}
#define MAPI_E_NOT_ENOUGH_MEMORY
Definition: mapicode.h:74

◆ MAPIAllocateMore()

SCODE WINAPI MAPIAllocateMore ( ULONG  cbSize,
LPVOID  lpOrig,
LPVOID lppBuffer 
)

Definition at line 168 of file util.c.

169{
170 LPMAPIALLOCBUFFER lpBuff = lpOrig;
171
172 TRACE("(%d,%p,%p)\n", cbSize, lpOrig, lppBuffer);
173
174 if (mapiFunctions.MAPIAllocateMore)
175 return mapiFunctions.MAPIAllocateMore(cbSize, lpOrig, lppBuffer);
176
177 if (!lppBuffer || !lpBuff || !--lpBuff)
178 return E_INVALIDARG;
179
180 /* Find the last allocation in the chain */
181 while (*lpBuff)
182 {
183 TRACE("linked:%p->%p\n", lpBuff, *lpBuff);
184 lpBuff = *lpBuff;
185 }
186
187 if (SUCCEEDED(MAPIAllocateBuffer(cbSize, lppBuffer)))
188 {
189 *lpBuff = ((LPMAPIALLOCBUFFER)*lppBuffer) - 1;
190 TRACE("linking %p->%p\n", lpBuff, *lpBuff);
191 }
192 return *lppBuffer ? S_OK : MAPI_E_NOT_ENOUGH_MEMORY;
193}
LPVOID * LPMAPIALLOCBUFFER
Definition: util.c:101
#define SUCCEEDED(hr)
Definition: intsafe.h:50
MAPIALLOCATEBUFFER MAPIAllocateBuffer
Definition: mapix.h:96

◆ MAPIFreeBuffer()

ULONG WINAPI MAPIFreeBuffer ( LPVOID  lpBuffer)

Definition at line 207 of file util.c.

208{
210
211 TRACE("(%p)\n", lpBuffer);
212
213 if (mapiFunctions.MAPIFreeBuffer)
214 return mapiFunctions.MAPIFreeBuffer(lpBuffer);
215
216 if (lpBuff && --lpBuff)
217 {
218 while (lpBuff)
219 {
220 LPVOID lpFree = lpBuff;
221
222 lpBuff = *lpBuff;
223
224 TRACE("linked:%p->%p, freeing %p\n", lpFree, lpBuff, lpFree);
225 HeapFree(GetProcessHeap(), 0, lpFree);
226 }
227 }
228 return S_OK;
229}
static TAGREF LPCWSTR LPDWORD LPVOID lpBuffer
Definition: db.cpp:175

◆ MNLS_CompareStringW()

INT WINAPI MNLS_CompareStringW ( DWORD  dwCp,
LPCWSTR  lpszLeft,
LPCWSTR  lpszRight 
)

Definition at line 464 of file util.c.

465{
466 INT ret;
467
468 TRACE("0x%08x,%s,%s\n", dwCp, debugstr_w(lpszLeft), debugstr_w(lpszRight));
469 ret = MNLS_lstrcmpW(lpszLeft, lpszRight);
471}
INT WINAPI MNLS_lstrcmpW(LPCWSTR lpszLeft, LPCWSTR lpszRight)
Definition: util.c:422
int32_t INT
Definition: typedefs.h:58
#define CSTR_EQUAL
Definition: winnls.h:456
#define CSTR_LESS_THAN
Definition: winnls.h:455
#define CSTR_GREATER_THAN
Definition: winnls.h:457

◆ MNLS_lstrcmpW()

INT WINAPI MNLS_lstrcmpW ( LPCWSTR  lpszLeft,
LPCWSTR  lpszRight 
)

Definition at line 422 of file util.c.

423{
424 TRACE("(%s,%s)\n", debugstr_w(lpszLeft), debugstr_w(lpszRight));
425 return lstrcmpW(lpszLeft, lpszRight);
426}

Referenced by MNLS_CompareStringW().

◆ MNLS_lstrcpyW()

ULONG WINAPI MNLS_lstrcpyW ( LPWSTR  lpszDest,
LPCWSTR  lpszSrc 
)

Definition at line 440 of file util.c.

441{
442 ULONG len;
443
444 TRACE("(%p,%s)\n", lpszDest, debugstr_w(lpszSrc));
445 len = (lstrlenW(lpszSrc) + 1) * sizeof(WCHAR);
446 memcpy(lpszDest, lpszSrc, len);
447 return len;
448}
WCHAR lpszDest[260]
GLenum GLsizei len
Definition: glext.h:6722
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

◆ MNLS_lstrlenW()

ULONG WINAPI MNLS_lstrlenW ( LPCWSTR  lpszStr)

Definition at line 403 of file util.c.

404{
405 TRACE("(%s)\n", debugstr_w(lpszStr));
406 return lstrlenW(lpszStr);
407}

◆ OpenStreamOnFile()

HRESULT WINAPI OpenStreamOnFile ( LPALLOCATEBUFFER  lpAlloc,
LPFREEBUFFER  lpFree,
ULONG  ulFlags,
LPWSTR  lpszPath,
LPWSTR  lpszPrefix,
LPSTREAM lppStream 
)

Definition at line 712 of file util.c.

715{
716 WCHAR szBuff[MAX_PATH];
717 DWORD dwMode = STGM_READWRITE, dwAttributes = 0;
718 HRESULT hRet;
719
720 TRACE("(%p,%p,0x%08x,%s,%s,%p)\n", lpAlloc, lpFree, ulFlags,
721 debugstr_a((LPSTR)lpszPath), debugstr_a((LPSTR)lpszPrefix), lppStream);
722
723 if (mapiFunctions.OpenStreamOnFile)
724 return mapiFunctions.OpenStreamOnFile(lpAlloc, lpFree, ulFlags, lpszPath, lpszPrefix, lppStream);
725
726 if (lppStream)
727 *lppStream = NULL;
728
729 if (ulFlags & SOF_UNIQUEFILENAME)
730 {
731 FIXME("Should generate a temporary name\n");
732 return E_INVALIDARG;
733 }
734
735 if (!lpszPath || !lppStream)
736 return E_INVALIDARG;
737
738 /* FIXME: Should probably munge mode and attributes, and should handle
739 * Unicode arguments (I assume MAPI_UNICODE is set in ulFlags if
740 * we are being passed Unicode strings; MSDN doesn't say).
741 * This implementation is just enough for Outlook97 to start.
742 */
743 MultiByteToWideChar(CP_ACP, 0, (LPSTR)lpszPath, -1, szBuff, MAX_PATH);
744 hRet = SHCreateStreamOnFileEx(szBuff, dwMode, dwAttributes, TRUE,
745 NULL, lppStream);
746 return hRet;
747}
#define CP_ACP
Definition: compat.h:109
#define MAX_PATH
Definition: compat.h:34
#define MultiByteToWideChar
Definition: compat.h:110
HRESULT WINAPI SHCreateStreamOnFileEx(LPCWSTR lpszPath, DWORD dwMode, DWORD dwAttributes, BOOL bCreate, IStream *lpTemplate, IStream **lppStream)
Definition: istream.c:401
#define SOF_UNIQUEFILENAME
Definition: mapiutil.h:32
#define STGM_READWRITE
Definition: objbase.h:919
DWORD dwAttributes
Definition: vdmdbg.h:34

◆ ScInitMapiUtil()

SCODE WINAPI ScInitMapiUtil ( ULONG  ulReserved)

Definition at line 67 of file util.c.

68{
69 if (mapiFunctions.ScInitMapiUtil)
70 return mapiFunctions.ScInitMapiUtil(ulReserved);
71
72 FIXME("(0x%08x)stub!\n", ulReserved);
73 if (ulReserved)
75 return S_OK;
76}
#define MAPI_E_INVALID_PARAMETER
Definition: mapicode.h:62
_In_ SURFOBJ _In_ CLIPOBJ _In_opt_ XLATEOBJ _In_ RECTL _In_ RECTL _In_ ULONG _In_ ULONG ulReserved
Definition: winddi.h:4196

◆ SwapPlong()

VOID WINAPI SwapPlong ( PULONG  lpData,
ULONG  ulLen 
)

Definition at line 364 of file util.c.

365{
366 ULONG i;
367
368 for (i = 0; i < ulLen; i++)
369 lpData[i] = RtlUlongByteSwap(lpData[i]);
370}
#define RtlUlongByteSwap(_x)
Definition: compat.h:815

◆ SwapPword()

VOID WINAPI SwapPword ( PUSHORT  lpData,
ULONG  ulLen 
)

Definition at line 384 of file util.c.

385{
386 ULONG i;
387
388 for (i = 0; i < ulLen; i++)
389 lpData[i] = RtlUshortByteSwap(lpData[i]);
390}
#define RtlUshortByteSwap(_x)
Definition: rtlfuncs.h:3197

◆ UFromSz()

UINT WINAPI UFromSz ( LPCSTR  lpszStr)

Definition at line 677 of file util.c.

678{
679 ULONG ulRet = 0;
680
681 TRACE("(%s)\n", debugstr_a(lpszStr));
682
683 if (lpszStr)
684 {
685 while (*lpszStr >= '0' && *lpszStr <= '9')
686 {
687 ulRet = ulRet * 10 + (*lpszStr - '0');
688 lpszStr++;
689 }
690 }
691 return ulRet;
692}

◆ UlAddRef()

ULONG WINAPI UlAddRef ( void lpUnk)

Definition at line 627 of file util.c.

628{
629 TRACE("(%p)\n", lpUnk);
630
631 if (!lpUnk)
632 return 0UL;
633 return IUnknown_AddRef((LPUNKNOWN)lpUnk);
634}
static LPUNKNOWN
Definition: ndr_ole.c:49
#define UL
Definition: tui.h:148

◆ UlFromSzHex()

ULONG WINAPI UlFromSzHex ( LPCWSTR  lpszHex)

Definition at line 765 of file util.c.

766{
767 LPCSTR lpStr = (LPCSTR)lpszHex;
768 ULONG ulRet = 0;
769
770 TRACE("(%s)\n", debugstr_a(lpStr));
771
772 while (*lpStr)
773 {
774 if (lpStr[0] < '0' || lpStr[0] > 'f' || digitsToHex[lpStr[0] - '0'] == 0xff ||
775 lpStr[1] < '0' || lpStr[1] > 'f' || digitsToHex[lpStr[1] - '0'] == 0xff)
776 break;
777
778 ulRet = ulRet * 16 + ((digitsToHex[lpStr[0] - '0'] << 4) | digitsToHex[lpStr[1] - '0']);
779 lpStr += 2;
780 }
781 return ulRet;
782}

◆ UlRelease()

ULONG WINAPI UlRelease ( void lpUnk)

Definition at line 652 of file util.c.

653{
654 TRACE("(%p)\n", lpUnk);
655
656 if (!lpUnk)
657 return 0UL;
658 return IUnknown_Release((LPUNKNOWN)lpUnk);
659}

◆ unload_mapi_providers()

void unload_mapi_providers ( void  )

Definition at line 1135 of file util.c.

1136{
1137 TRACE("()\n");
1138
1141}

Referenced by DllMain().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( mapi  )

◆ WrapCompressedRTFStream()

HRESULT WINAPI WrapCompressedRTFStream ( LPSTREAM  compressed,
ULONG  flags,
LPSTREAM uncompressed 
)

Definition at line 948 of file util.c.

949{
950 if (mapiFunctions.WrapCompressedRTFStream)
951 return mapiFunctions.WrapCompressedRTFStream(compressed, flags, uncompressed);
952
953 FIXME("(%p, 0x%08x, %p): stub\n", compressed, flags, uncompressed);
954 return MAPI_E_NO_SUPPORT;
955}
#define MAPI_E_NO_SUPPORT
Definition: mapicode.h:71
static const BYTE uncompressed[]
Definition: misc.c:392

◆ WrapProgress()

HRESULT WINAPI WrapProgress ( PVOID  unk1,
PVOID  unk2,
PVOID  unk3,
PVOID  unk4,
PVOID  unk5 
)

Definition at line 234 of file util.c.

235{
236 /* Native does not implement this function */
237 return MAPI_E_NO_SUPPORT;
238}

Variable Documentation

◆ digitsToHex

const BYTE digitsToHex[]
static
Initial value:
= {
0,1,2,3,4,5,6,7,8,9,0xff,0xff,0xff,0xff,0xff,0xff,0xff,10,11,12,13,14,15,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,10,11,12,13,
14,15 }

Definition at line 43 of file util.c.

Referenced by FBinFromHex(), and UlFromSzHex().

◆ mapi_ex_provider

HMODULE mapi_ex_provider
static

Definition at line 958 of file util.c.

Referenced by load_mapi_providers(), and unload_mapi_providers().

◆ mapi_provider

HMODULE mapi_provider
static

Definition at line 957 of file util.c.

Referenced by load_mapi_provider(), load_mapi_providers(), and unload_mapi_providers().

◆ mapiFunctions