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.