Results 1 to 6 of 6

Thread: How to create .msg file using QT application?

  1. #1
    Join Date
    Apr 2011
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default How to create .msg file using QT application?

    I am new in QT. I want create a .msg file programmatically in QT.I want to create a Qt gui application with MS Outlook integration.After searching from various web resources,I got a bit of source code but its not working properly.Its contain some errors and conversion problems.

    Qt Code:
    1. #include "mainwindow.h"
    2. #include<QDebug>
    3. #include<QFile>
    4. #include <MAPIX.h>
    5. #include <MAPITags.h>
    6. #include <MAPIDefS.h>
    7. #include <MAPIUtil.h>
    8. #include <MAPIGuid.h>
    9. #include <IMessage.h>
    10. #include <ObjBase.h>
    11. #include<QDir>
    12.  
    13.  
    14. #define INITGUID
    15. #define USES_IID_IMessage
    16.  
    17. MainWindow::MainWindow(QWidget *parent)
    18. : QMainWindow(parent)
    19. {
    20. LPMESSAGE asdfasd = NULL;
    21. qDebug()<<"Sample msg File Open";
    22. SaveToMSG(asdfasd);
    23.  
    24. }
    25.  
    26. MainWindow::~MainWindow()
    27. {
    28.  
    29. }
    30. HRESULT MainWindow::SaveToMSG(LPMESSAGE pMessage)
    31. {
    32. HRESULT hRes = S_OK;
    33. LPSPropValue pSubject = NULL;
    34. LPSTORAGE pStorage = NULL;
    35. LPMSGSESS pMsgSession = NULL;
    36. LPMESSAGE pIMsg = NULL;
    37. SizedSPropTagArray ( 7, excludeTags );
    38. char szPath[_MAX_PATH];
    39. char strAttachmentFile[_MAX_PATH];
    40. LPWSTR lpWideCharStr = NULL;
    41. ULONG cbStrSize = 0L;
    42.  
    43. // create the file name in the directory where "TMP" is defined
    44. // with subject as the filename and ".msg" extension.
    45.  
    46. // get temp file directory
    47. GetTempPath(_MAX_PATH, szPath);
    48.  
    49. // get subject line of message to copy. This will be used as the
    50. // new file name.
    51. HrGetOneProp( pMessage, PR_SUBJECT, &pSubject );
    52.  
    53. // fuse path, subject, and suffix into one string
    54. strcpy ( strAttachmentFile, szPath );
    55. strcat ( strAttachmentFile, pSubject->Value.lpszA );
    56. strcat ( strAttachmentFile, ".msg");
    57.  
    58. // get memory allocation function
    59. LPMALLOC pMalloc = MAPIGetDefaultMalloc();
    60.  
    61. // Convert new file name to WideChar
    62. cbStrSize = MultiByteToWideChar (CP_ACP,
    63. MB_PRECOMPOSED,
    64. strAttachmentFile,
    65. -1, lpWideCharStr, 0);
    66.  
    67. MAPIAllocateBuffer ( cbStrSize * sizeof(WCHAR),
    68. (LPVOID *)&lpWideCharStr );
    69.  
    70. MultiByteToWideChar (CP_ACP,
    71. MB_PRECOMPOSED,
    72. strAttachmentFile,
    73. -1, lpWideCharStr, cbStrSize );
    74.  
    75. // create compound file
    76. hRes = ::StgCreateDocfile(lpWideCharStr,
    77. STGM_READWRITE |
    78. STGM_TRANSACTED |
    79. STGM_CREATE, 0, &pStorage);
    80.  
    81. // Open an IMessage session.
    82. hRes = ::OpenIMsgSession(pMalloc, 0, &pMsgSession);
    83.  
    84. // Open an IMessage interface on an IStorage object
    85. hRes = ::OpenIMsgOnIStg(pMsgSession,
    86. MAPIAllocateBuffer,
    87. MAPIAllocateMore,
    88. MAPIFreeBuffer,
    89. pMalloc,
    90. NULL,
    91. pStorage,
    92. NULL, 0, 0, &pIMsg);
    93.  
    94. // write the CLSID to the IStorage instance - pStorage. This will
    95. // only work with clients that support this compound document type
    96. // as the storage medium. If the client does not support
    97. // CLSID_MailMessage as the compound document, you will have to use
    98. // the CLSID that it does support.
    99. hRes = WriteClassStg(pStorage, CLSID_MailMessage );
    100.  
    101. // Specify properties to exclude in the copy operation. These are
    102. // the properties that Exchange excludes to save bits and time.
    103. // Should not be necessary to exclude these, but speeds the process
    104. // when a lot of messages are being copied.
    105. excludeTags.cValues = 7;
    106. excludeTags.aulPropTag[0] = PR_ACCESS;
    107. excludeTags.aulPropTag[1] = PR_BODY;
    108. excludeTags.aulPropTag[2] = PR_RTF_SYNC_BODY_COUNT;
    109. excludeTags.aulPropTag[3] = PR_RTF_SYNC_BODY_CRC;
    110. excludeTags.aulPropTag[4] = PR_RTF_SYNC_BODY_TAG;
    111. excludeTags.aulPropTag[5] = PR_RTF_SYNC_PREFIX_COUNT;
    112. excludeTags.aulPropTag[6] = PR_RTF_SYNC_TRAILING_COUNT;
    113.  
    114. // copy message properties to IMessage object opened on top of
    115. // IStorage.
    116. hRes = pMessage->CopyTo(0, NULL,
    117. (LPSPropTagArray)&excludeTags,
    118. NULL, NULL,
    119. (LPIID)&IID_IMessage,
    120. pIMsg, 0, NULL );
    121.  
    122. // save changes to IMessage object.
    123. pIMsg -> SaveChanges ( KEEP_OPEN_READWRITE );
    124.  
    125. // save changes in storage of new doc file
    126. hRes = pStorage -> Commit(STGC_DEFAULT);
    127.  
    128. // free objects and clean up memory
    129. MAPIFreeBuffer ( lpWideCharStr );
    130. pStorage->Release();
    131. pIMsg->Release();
    132. CloseIMsgSession ( pMsgSession );
    133.  
    134. pStorage = NULL;
    135. pIMsg = NULL;
    136. pMsgSession = NULL;
    137. lpWideCharStr = NULL;
    138.  
    139. return hRes;
    140. }
    To copy to clipboard, switch view to plain text mode 

    so please help me to rectify these problems.

  2. #2
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create .msg file using QT application?

    what errors are you getting. post the error messages.

  3. The following user says thank you to nish for this useful post:

    kishoreksnair (16th December 2011)

  4. #3
    Join Date
    Apr 2011
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default Re: How to create .msg file using QT application?

    following errors:

    D:\ACROWIT_Project\Samplefopen\mainwindow.cpp:47: error: C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    D:\ACROWIT_Project\Samplefopen\mainwindow.cpp:47: error: C2664: 'GetTempPathW' : cannot convert parameter 2 from 'char [260]' to 'LPWSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    can you please send the sample code,or how can i run the above code...i want to create a msg file(outlook file format with:to,sub,body,attachment,bcc etc).

  5. #4
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to create .msg file using QT application?

    the error messages are self explanatory. use WCHAR instead of char

  6. #5
    Join Date
    Apr 2011
    Posts
    11
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded Qt Jambi PyQt3 PyQt4
    Platforms
    Windows

    Default Re: How to create .msg file using QT application?

    thanks for your help...I am new in QT...and also have some problems in strcpy() and strcat()..

    D:\ACROWIT_Project\Samplefopen\mainwindow.cpp:65: error: C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'WCHAR [260]' to 'LPCSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


    D:\ACROWIT_Project\Samplefopen\mainwindow.cpp:73: error: C2664: 'MultiByteToWideChar' : cannot convert parameter 3 from 'WCHAR [260]' to 'LPCSTR'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

    D:\ACROWIT_Project\Samplefopen\mainwindow.cpp:54: error: C2664: 'strcpy' : cannot convert parameter 1 from 'WCHAR [260]' to 'char *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast


    D:\ACROWIT_Project\Samplefopen\mainwindow.cpp:54: error: C2664: 'strcpy' : cannot convert parameter 1 from 'WCHAR [260]' to 'char *'
    Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

  7. #6
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create .msg file using QT application?

    See this link : http://www.codeproject.com/Tips/7625...TR-LPCTSTR-etc

    The following links may also be usefull : http://www.google.com or http://www.yahoo.com or http://www.bing.com

    You could check these out first before asking more questions...

Similar Threads

  1. Create extensible application with Qt
    By grayfox in forum Qt Programming
    Replies: 1
    Last Post: 29th June 2011, 11:52
  2. How to create the set up file after completing the application???
    By Gokulnathvc in forum General Programming
    Replies: 6
    Last Post: 2nd April 2011, 11:36
  3. How to create application help?
    By cydside in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2009, 19:18
  4. How to Create Executable file for my QT application
    By c_srikanth1984 in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2009, 04:02
  5. How can I create this application?
    By hgedek in forum Qt for Embedded and Mobile
    Replies: 10
    Last Post: 19th January 2008, 16:21

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.