Форум программистов, компьютерный форум CyberForum.ru

exception при вызове функции по адресу (MAPILogon) - C++

Войти
Регистрация
Восстановить пароль
Другие темы раздела
C++ Книжки по С++ http://www.cyberforum.ru/cpp-beginners/thread327659.html
Здравствуйте, я учусь на 1 курсе, где нам преподают си++. По сути нам объясняют как употреблять ключевые слова и что они "делают". Но как они конкретно влияют на программу я не пойму. Во время семестра у меня еще вылазило уйма вопросов, корень которых скрывался именно в понимании принципа работы компьютера. И так вопрос: Какие вы читали книжки, когда начали программировать, какая вам больше всего...
C++ Есть алгоритм для арбитражного торгового робота на РТС и ММВБ, нужны два - три партнера. Арбитражный робот предполагает безубыточную торговлю. Как правило доход незначительный. В моем случае доходность от 1 до 10 % в день. Хочу написать его самостоятельно, но пока в программировании полный ноль. Вот и приглашаю к сотрудничеству в создании этого продукта программеров. Программеры учат меня писать - по ходу получают алгоритм. На мой взгляд вполне адекватное вознаграждение. В... http://www.cyberforum.ru/cpp-beginners/thread327655.html
C++ Перегрузка функций
Моя последняя лаба=( Светлые умы, помогите... Выполнить задания пятой и шестой лабораторной работы, оформив каждый пункт задания в виде шаблона функции. Все необходимые данные должны передаваться им в качестве параметров. Пятая: 1) номер максимального элемента массива; 2) произведение элементов массива, расположенных между первым и вторым нулевыми элементами. Преобразовать массив таким...
C++ "Угадай число" (напишите программу, хочу проверить со своей).
"Угадай число". Пользователю предлагается отгадать число за 10 попыток. Программа даёт подсказки вида больше, меньше.
C++ Заменить в каждой строке элементы с наибольшим значением нулём http://www.cyberforum.ru/cpp-beginners/thread327586.html
Дан текстовый файл, состоящий из одной или нескольких строк. Каждая строка файла содержит числа,разделенные пробелами. Заменить в каждой строке элементы с наибольшим значением нулём. Создать файл, который будет содержать данные исходного файла, а затем данные преобразованного файла. Пожалуйста. . . Очень надо. . .:(
C++ Задается положительное действительное чисто R Решите очень нужно , Задается положительное действительное чисто R. Найти положительные действительные R1,R2,...,Rn, Ri<4,i=1,...,n, такие, что R=R1*R2*...*Rn=R1+R2+...+Rn подробнее

Показать сообщение отдельно
schdub
 Аватар для schdub
2907 / 1251 / 224
Регистрация: 19.01.2009
Сообщений: 3,240
Завершенные тесты: 1
29.06.2011, 18:40     exception при вызове функции по адресу (MAPILogon)
Вот посмотрите на MFC обертку над Simple MAPI от PJ Naughter:
CMapi.h
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
Module : CMAPI.H
Purpose: Defines the interface for an MFC wrapper class for sending an email using simple MAPI
Created: PJN / 11-05-1999
 
Copyright (c) 1999 - 2000 by PJ Naughter.  
All rights reserved.
 
*/
 
#ifndef __CMAPI_H__
#define __CMAPI_H__
 
 
#ifndef MAPI_H
#include <mapi.h>
#endif
 
 
//Class which encapsulates a MAPI mail message
class CMapiMessage
{
public:
//Enums
    enum RECIPIENT_TYPE { TO, CC, BCC };
 
//Methods
  BOOL AddMultipleRecipients(const CString& sRecipients, RECIPIENT_TYPE RecipientType);
 
//Member variables
  CStringArray  m_To;               //The To: Recipients
  CStringArray  m_CC;               //The CC: Recipients
  CStringArray  m_BCC;              //The BCC Recipients
  CString       m_sSubject;         //The Subject of the message
  CString       m_sBody;            //The Body of the message
  CStringArray  m_Attachments;      //Files to attach to the email
  CStringArray  m_AttachmentTitles; //Titles to use for the email file attachments
};
 
 
//The class which encapsulates the MAPI connection
class CMapiSession
{
public:
//Constructors / Destructors
  CMapiSession();
  ~CMapiSession();
 
//Logon / Logoff Methods
  BOOL Logon(const CString& sProfileName, const CString& sPassword = CString(), CWnd* pParentWnd = NULL);
  BOOL SharedLogon();
  BOOL LoggedOn() const;
  BOOL Logoff();
 
//Send a message
  BOOL Send(CMapiMessage& mesage, BOOL bResolve = FALSE, BOOL bInteractive = FALSE, CWnd* pParentWnd = NULL);
 
//General MAPI support
  BOOL MapiInstalled() const;
 
//Error Handling
  ULONG GetLastError() const;
 
protected:
//Methods
  void Initialise();
  void Deinitialise(); 
  BOOL Resolve(const CString& sName, lpMapiRecipDesc* lppRecip);
 
//Data
  LHANDLE m_hSession; //Mapi Session handle
  ULONG m_nLastError; //Last Mapi error value
  HINSTANCE m_hMapi; //Instance handle of the MAPI dll
  LPMAPILOGON m_lpfnMAPILogon; //MAPILogon function pointer
  LPMAPILOGOFF m_lpfnMAPILogoff; //MAPILogoff function pointer
  LPMAPISENDMAIL m_lpfnMAPISendMail; //MAPISendMail function pointer
  LPMAPIRESOLVENAME m_lpfnMAPIResolveName; //MAPIResolveName function pointer
  LPMAPIFREEBUFFER m_lpfnMAPIFreeBuffer; //MAPIFreeBuffer function pointer
};
 
 
#endif //__CMAPI_H__

CMapi.cpp
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
/*
Module : CMAPI.CPP
Purpose: Defines the implementation for an MFC wrapper class for sending an email using simple MAPI
Created: PJN / 11-05-1999
History: PJN / 05-12-1999 1. Fixed potential problem where CMapi is used in a console app which was giving an ASSERT
                          2. Fixed an assert which can occur if you dismiss the login dialog when doing an 
                          interactive MAPI logon
               28-03-2000 1. Provision of a sample app which implements a mini mail sender.
                          2. Added a CMapiMessage::AddMultipleRecipients method similar to my SMTP class.
               02-04-2000 1. Password field in the configuration dialog now uses ES_PASSWORD edit control style.
                          2. Password value used for Mapi logon is now stored in the registry encrypted instead of as plain text.
               21-04-2000 1. Added an optional parameter to CMapi::SendMessage to allow you to decide whether or not addresses 
                          should be resolved.
               22-06-2000 1. Fixed a bug in CMapiMessage::AddMultipleRecipients where BCC recipients were not being added 
                          correctly.
               18-07-2000 1. Fixed check for MAPI being installed when client apps create an incorrect "MAPI" entry in win.ini
                          or the registry, Thanks to Chris Raethke for spotting this.
                          2. A "SharedLogon" method has been provided which tries to acquire a shared mapi session
                          3. SendMessage method has been extended to allow the message to be interactively edited.
 
 
 
 
Copyright (c) 1999  - 2000 by PJ Naughter.  
All rights reserved.
 
 
*/
 
 
 
/////////////////////////////////  Includes  //////////////////////////////////
 
#include "stdafx.h"
#include "CMapi.h"
#include <afxpriv.h>
 
 
 
 
//////////////////////////////// Statics / Macros /////////////////////////////
 
#ifdef _DEBUG
#undef THIS_FILE
static char BASED_CODE THIS_FILE[] = __FILE__;
#define new DEBUG_NEW
#endif
 
 
 
 
////////////////////////////////// Implementation /////////////////////////////
 
 
 
BOOL CMapiMessage::AddMultipleRecipients(const CString& sRecipients, RECIPIENT_TYPE RecipientType)
{
    ASSERT(sRecipients.GetLength()); //An empty string is now allowed
    
    //Loop through the whole string, adding recipients as they are encountered
    int length = sRecipients.GetLength();
    TCHAR* buf = new TCHAR[length + 1]; // Allocate a work area (don't touch parameter itself)
    _tcscpy(buf, sRecipients);
    for (int pos=0, start=0; pos<=length; pos++)
    {
        //Valid separators between addresses are ',' or ';'
        if ((buf[pos] == _T(',')) || (buf[pos] == _T(';')) || (buf[pos] == 0))
        {
            buf[pos] = 0;   //Redundant when at the end of string, but who cares.
      CString sTemp(&buf[start]);
 
            // Now divide the substring into friendly names and e-mail addresses
      CString To = sTemp;
 
      //Finally add the new recipient to the array of recipients
            To.TrimRight();
            To.TrimLeft();
      if (To.GetLength())
      {
        switch (RecipientType)
        {
          case TO:  m_To.Add(To); break;
          case CC:  m_CC.Add(To); break;
          case BCC: m_BCC.Add(To); break;
          default: ASSERT(FALSE); break;
        }
      }
 
      //Move on to the next position
            start = pos + 1;
        }
    }
    delete[] buf;
    return TRUE;
}
 
 
 
 
CMapiSession::CMapiSession()
{
  m_hSession = 0;
  m_nLastError = 0;
  m_hMapi = NULL;
  m_lpfnMAPILogon = NULL;
  m_lpfnMAPILogoff = NULL;
  m_lpfnMAPISendMail = NULL;
  m_lpfnMAPIResolveName = NULL;
  m_lpfnMAPIFreeBuffer = NULL;
  Initialise();
}
 
CMapiSession::~CMapiSession()
{
  //Logoff if logged on
  Logoff();
 
  //Unload the MAPI dll
  Deinitialise();
}
 
void CMapiSession::Initialise() 
{
  //First make sure the MAPI32 dll is present on the system. Technically we should
  //be also testing by using the check "GetProfileInt(_T("MAIL"), _T("MAPI"), 0) != 0"
  //also, but some installs of MAPI screw this entry up.
    BOOL bMapiInstalled = (SearchPath(NULL, _T("MAPI32.DLL"), NULL, 0, NULL, NULL) != 0);
 
  if (bMapiInstalled)
  {
    //Load up the MAPI dll and get the function pointers we are interested in
    m_hMapi = LoadLibrary(_T("MAPI32.DLL"));
    if (m_hMapi)
    {
      m_lpfnMAPILogon = (LPMAPILOGON) GetProcAddress(m_hMapi, "MAPILogon");
      m_lpfnMAPILogoff = (LPMAPILOGOFF) GetProcAddress(m_hMapi, "MAPILogoff");
      m_lpfnMAPISendMail = (LPMAPISENDMAIL) GetProcAddress(m_hMapi, "MAPISendMail");
      m_lpfnMAPIResolveName = (LPMAPIRESOLVENAME) GetProcAddress(m_hMapi, "MAPIResolveName");
      m_lpfnMAPIFreeBuffer = (LPMAPIFREEBUFFER) GetProcAddress(m_hMapi, "MAPIFreeBuffer");
  
      //If any of the functions are not installed then fail the load
      if (m_lpfnMAPILogon == NULL ||
          m_lpfnMAPILogoff == NULL ||
          m_lpfnMAPISendMail == NULL ||
          m_lpfnMAPIResolveName == NULL ||
          m_lpfnMAPIFreeBuffer == NULL)
      {
        TRACE(_T("Failed to get one of the functions pointer in MAPI32.DLL\n"));
        Deinitialise();
      }
    }
  }
  else
    TRACE(_T("Mapi is not installed on this computer\n"));
}
 
void CMapiSession::Deinitialise()
{
  if (m_hMapi)
  {
    //Unload the MAPI dll and reset the function pointers to NULL
    FreeLibrary(m_hMapi);
    m_hMapi = NULL;
    m_lpfnMAPILogon = NULL;
    m_lpfnMAPILogoff = NULL;
    m_lpfnMAPISendMail = NULL;
    m_lpfnMAPIResolveName = NULL;
    m_lpfnMAPIFreeBuffer = NULL;
  }
}
 
BOOL CMapiSession::Logon(const CString& sProfileName, const CString& sPassword, CWnd* pParentWnd)
{
    //For correct operation of the T2A macro, see MFC Tech Note 59
    USES_CONVERSION;
 
  ASSERT(MapiInstalled()); //MAPI must be installed
  ASSERT(m_lpfnMAPILogon); //Function pointer must be valid
 
  //Initialise the function return value
  BOOL bSuccess = FALSE;
 
  //Just in case we are already logged in
  Logoff();
 
  //Setup the ascii versions of the profile name and password
  int nProfileLength = sProfileName.GetLength();
  int nPasswordLength = sPassword.GetLength();
  LPSTR pszProfileName = NULL;
  LPSTR pszPassword = NULL;
  if (nProfileLength)
  {
    pszProfileName = T2A((LPTSTR) (LPCTSTR) sProfileName);
    pszPassword = T2A((LPTSTR) (LPCTSTR) sPassword);
  }
 
  //Setup the flags & UIParam parameters used in the MapiLogon call
  FLAGS flags = 0;
  ULONG nUIParam = 0;
  if (nProfileLength == 0)
  {
    //No profile name given, then we must interactively request a profile name
    if (pParentWnd)
    {
      nUIParam = (ULONG) pParentWnd->GetSafeHwnd();
      flags |= MAPI_LOGON_UI;
    }
    else
    {
      //No CWnd given, just use the main window of the app as the parent window
      if (AfxGetMainWnd())
      {
        nUIParam = (ULONG) AfxGetMainWnd()->GetSafeHwnd();
        flags |= MAPI_LOGON_UI;
      }
    }
  }
  
  //First try to acquire a new MAPI session using the supplied settings using the MAPILogon functio
  ULONG nError = m_lpfnMAPILogon(nUIParam, pszProfileName, pszPassword, flags | MAPI_NEW_SESSION, 0, &m_hSession);
  if (nError != SUCCESS_SUCCESS && nError != MAPI_E_USER_ABORT)
  {
    //Failed to create a create mapi session, try to acquire a shared mapi session
    TRACE(_T("Failed to logon to MAPI using a new session, trying to acquire a shared one\n"));
    nError = m_lpfnMAPILogon(nUIParam, NULL, NULL, 0, 0, &m_hSession);
    if (nError == SUCCESS_SUCCESS)
    {
      m_nLastError = SUCCESS_SUCCESS;
      bSuccess = TRUE;
    }
    else
    {
      TRACE(_T("Failed to logon to MAPI using a shared session, Error:%d\n"), nError);
      m_nLastError = nError;
    }
  }
  else if (nError == SUCCESS_SUCCESS)
  {
    m_nLastError = SUCCESS_SUCCESS;
    bSuccess = TRUE;
  }
 
  return bSuccess;
}
 
BOOL CMapiSession::SharedLogon()
{
  ASSERT(MapiInstalled()); //MAPI must be installed
  ASSERT(m_lpfnMAPILogon); //Function pointer must be valid
 
  //Initialise the function return value
  BOOL bSuccess = FALSE;
 
  //Just in case we are already logged in
  Logoff();
 
  //Try to acquire a shared mapi session
  ULONG nError = m_lpfnMAPILogon(0, NULL, NULL, 0, 0, &m_hSession);
  if (nError == SUCCESS_SUCCESS)
  {
    m_nLastError = SUCCESS_SUCCESS;
    bSuccess = TRUE;
  }
  else
    m_nLastError = nError;
 
  return bSuccess;
}
 
BOOL CMapiSession::LoggedOn() const
{
  return (m_hSession != 0);
}
 
BOOL CMapiSession::MapiInstalled() const
{
  return (m_hMapi != NULL);
}
 
BOOL CMapiSession::Logoff()
{
  ASSERT(MapiInstalled()); //MAPI must be installed
  ASSERT(m_lpfnMAPILogoff); //Function pointer must be valid
 
  //Initialise the function return value
  BOOL bSuccess = FALSE;
 
  if (m_hSession)
  {
    //Call the MAPILogoff function
    ULONG nError = m_lpfnMAPILogoff(m_hSession, 0, 0, 0); 
    if (nError != SUCCESS_SUCCESS)
    {
      TRACE(_T("Failed in call to MapiLogoff, Error:%d"), nError);
      m_nLastError = nError;
      bSuccess = TRUE;
    }
    else
    {
      m_nLastError = SUCCESS_SUCCESS;
      bSuccess = TRUE;
    }
    m_hSession = 0;
  }
    
  return bSuccess;
}
 
BOOL CMapiSession::Resolve(const CString& sName, lpMapiRecipDesc* lppRecip)
{
    //For correct operation of the T2A macro, see MFC Tech Note 59
    USES_CONVERSION;
 
  ASSERT(MapiInstalled()); //MAPI must be installed
  ASSERT(m_lpfnMAPIResolveName); //Function pointer must be valid
  ASSERT(LoggedOn()); //Must be logged on to MAPI
  ASSERT(m_hSession); //MAPI session handle must be valid
 
  //Call the MAPIResolveName function
  LPSTR lpszAsciiName = T2A((LPTSTR) (LPCTSTR) sName);
  ULONG nError = m_lpfnMAPIResolveName(m_hSession, 0, lpszAsciiName, 0, 0, lppRecip);
  if (nError != SUCCESS_SUCCESS)
  {
    TRACE(_T("Failed to resolve the name: %s, Error:%d\n"), sName, nError);
    m_nLastError = nError;
  }
 
  return (nError == SUCCESS_SUCCESS);
}
 
BOOL CMapiSession::Send(CMapiMessage& message, BOOL bResolve, BOOL bInteractive, CWnd* pParentWnd)
{
    //For correct operation of the T2A macro, see MFC Tech Note 59
    USES_CONVERSION;
 
  ASSERT(MapiInstalled()); //MAPI must be installed
  ASSERT(m_lpfnMAPISendMail); //Function pointer must be valid
  ASSERT(m_lpfnMAPIFreeBuffer); //Function pointer must be valid
 
  //Initialise the function return value
  BOOL bSuccess = FALSE;  
 
  //Create the MapiMessage structure to match the message parameter send into us
  MapiMessage mapiMessage;
  ZeroMemory(&mapiMessage, sizeof(mapiMessage));
  mapiMessage.lpszSubject = T2A((LPTSTR) (LPCTSTR) message.m_sSubject);
  mapiMessage.lpszNoteText = T2A((LPTSTR) (LPCTSTR) message.m_sBody);
  mapiMessage.nRecipCount = message.m_To.GetSize() + message.m_CC.GetSize() + message.m_BCC.GetSize(); 
  ASSERT(mapiMessage.nRecipCount); //Must have at least 1 recipient!
 
  //Allocate the recipients array
  mapiMessage.lpRecips = new MapiRecipDesc[mapiMessage.nRecipCount];
 
  //Setup the "To" recipients
  int nRecipIndex = 0;
  int nToSize = message.m_To.GetSize();
  for (int i=0; i<nToSize; i++)
  {
    MapiRecipDesc& recip = mapiMessage.lpRecips[nRecipIndex];
    ZeroMemory(&recip, sizeof(MapiRecipDesc));
    recip.ulRecipClass = MAPI_TO;
    CString& sName = message.m_To.ElementAt(i);
 
    if (bResolve)
    {
      //Try to resolve the name
      lpMapiRecipDesc lpTempRecip;  
      if (Resolve(sName, &lpTempRecip))
      {
        //Resolve worked, put the resolved name back into the sName
        sName = lpTempRecip->lpszName;
 
        //Don't forget to free up the memory MAPI allocated for us
        m_lpfnMAPIFreeBuffer(lpTempRecip);
      }
    }
    recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName);
 
    ++nRecipIndex;
  }
 
  //Setup the "CC" recipients
  int nCCSize = message.m_CC.GetSize();
  for (i=0; i<nCCSize; i++)
  {
    MapiRecipDesc& recip = mapiMessage.lpRecips[nRecipIndex];
    ZeroMemory(&recip, sizeof(MapiRecipDesc));
    recip.ulRecipClass = MAPI_CC;
    CString& sName = message.m_CC.ElementAt(i);
 
    if (bResolve)
    {    
      //Try to resolve the name
      lpMapiRecipDesc lpTempRecip;  
      if (Resolve(sName, &lpTempRecip))
      {
        //Resolve worked, put the resolved name back into the sName
        sName = lpTempRecip->lpszName;
 
        //Don't forget to free up the memory MAPI allocated for us
        m_lpfnMAPIFreeBuffer(lpTempRecip);
      }
    }
    recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName);
 
    ++nRecipIndex;
  }
 
  //Setup the "BCC" recipients
  int nBCCSize = message.m_BCC.GetSize();
  for (i=0; i<nBCCSize; i++)
  {
    MapiRecipDesc& recip = mapiMessage.lpRecips[nRecipIndex];
    ZeroMemory(&recip, sizeof(MapiRecipDesc));
    recip.ulRecipClass = MAPI_BCC;
    CString& sName = message.m_BCC.ElementAt(i);
 
    if (bResolve)
    {
      //Try to resolve the name
      lpMapiRecipDesc lpTempRecip;  
      if (Resolve(sName, &lpTempRecip))
      {
        //Resolve worked, put the resolved name back into the sName
        sName = lpTempRecip->lpszName;
 
        //Don't forget to free up the memory MAPI allocated for us
        m_lpfnMAPIFreeBuffer(lpTempRecip);
      }
    }
    recip.lpszName = T2A((LPTSTR) (LPCTSTR) sName);
 
    ++nRecipIndex;
  }
 
  //Setup the attachments 
  int nAttachmentSize = message.m_Attachments.GetSize();
  int nTitleSize = message.m_AttachmentTitles.GetSize();
  if (nTitleSize)
  { 
    ASSERT(nTitleSize == nAttachmentSize); //If you are going to set the attachment titles then you must set 
                                           //the attachment title for each attachment
  }
  if (nAttachmentSize)
  {
    mapiMessage.nFileCount = nAttachmentSize;
    mapiMessage.lpFiles = new MapiFileDesc[nAttachmentSize];
    for (i=0; i<nAttachmentSize; i++)
    {
      MapiFileDesc& file = mapiMessage.lpFiles[i];
      ZeroMemory(&file, sizeof(MapiFileDesc));
      file.nPosition = 0xFFFFFFFF;
      CString& sFilename = message.m_Attachments.ElementAt(i);
      file.lpszPathName = T2A((LPTSTR) (LPCTSTR) sFilename);
      file.lpszFileName = file.lpszPathName;
      if (nTitleSize)
      {
        CString& sTitle = message.m_AttachmentTitles.ElementAt(i);
        file.lpszFileName = T2A((LPTSTR) (LPCTSTR) sTitle);
      }
    }
  }
 
  //Setup the parameters into the function
  FLAGS flags = 0;
  ULONG uiParam = 0;
  if (!LoggedOn())
    flags |= MAPI_LOGON_UI;
  if (bInteractive)
  {
    flags |= MAPI_DIALOG;
    if (pParentWnd)
      uiParam = (ULONG) pParentWnd->GetSafeHwnd();
    else
    {
      ASSERT(AfxGetMainWnd());
      uiParam = (ULONG) AfxGetMainWnd()->GetSafeHwnd();
    }
  }
 
  //Do the actual send using MAPISendMail
  ULONG nError = m_lpfnMAPISendMail(m_hSession, uiParam, &mapiMessage, flags, 0);
  if (nError == SUCCESS_SUCCESS)
  {
    bSuccess = TRUE;
    m_nLastError = SUCCESS_SUCCESS;
  }
  else
  {
    TRACE(_T("Failed to send mail message, Error:%d\n"), nError);
    m_nLastError = nError;
  }
 
  //Tidy up the Attachements
  if (nAttachmentSize)
    delete [] mapiMessage.lpFiles;
  
  //Free up the Recipients memory
  delete [] mapiMessage.lpRecips;
 
  return bSuccess;
}
 
ULONG CMapiSession::GetLastError() const
{
  return m_nLastError;
}
 
Текущее время: 23:05. Часовой пояс GMT +3.
КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Рейтинг@Mail.ru