[This is now documented here: http://msdn.microsoft.com/en-us/library/bb820947.aspx]
There was a thread a while back in the microsoft.public.win32.programmer.messaging newsgroup about how Outlook 2003's new Unicode MSG files. The big question was how to create one. One poster even went as far as to reverse engineer the MSG format from scratch. Fortunately, there's an easier way, which I just got clearance to publish.
We start with the canonical sample for MSG files: http://support.microsoft.com/kb/171907
The key is the OpenIMsgOnIStg function. This function takes a ulFlags parameter. All you need to do to create a Unicode MSG file is to pass MAPI_UNICODE in this parameter. Once you do that, the resulting message will show STORE_UNICODE_OK in it's PR_STORE_SUPPORT_MASK and unicode properties will work.
This flag is supported in this function on Outlook 2003 and higher only.
Hi. I have the same problem with the MAPI_UNICODE on OpenIMsgSession.
I have E2K3 Management Tool and Outlook 2007 SP1 installed on my XP.
I use LoadLibrary on OLMAPI32.DLL and then call OpenIMsgSession with MAPI_UNICODE. I get MAPI_E_UNKNOWN_FLAGS in return.
It seems like it is a general issue.
Vilma - you've got two conflicting implementations of MAPI installed on that box, one that would take the flag and one that wouldn't. This error is a result of that conflict. You need to take one of those implementations of MAPI off the box.
Has anyone used the canonical sample code from http://support.microsoft.com/kb/171907 in Outlook 2010 beta? I can create .MSG files OK, but they do not open in Outlook.
I get "the operation failed" when trying to open an .MSG from the file system when Outlook is open, and I get "Cannot start Microsoft Outlook" when trying to open an .MSG file from the file system when Outlook is not running.
Any ideas? Our routine has worked in previous versions of Outlook, up to Outlook 2007.
Correction on my comment above: the sample code in KB171907 actually does still work just fine! :)
The problem we had was in drag and drop code on Win7.
We are getting an error 0x80070008 when StgCreateDocfile is called from an NT Service. StgCreateDocfile succeeds for first few calls, but after sometime we start getting this error and then we get it for each and every call. We are calling MAPIInitalize(NULL). Since this is an NT Service, MSDN says we should be calling it with MAPI_NT_SERVICE flags. But, if that is the case, then how is it succeeding for the first few calls? We also have McAfee antivirus installed on the machine: could it be interfering with the file creation? We are calling StgCreateDocFile with flags: STGM_READWRITE | STGM_SHARE_EXCLUSIVE | STGM_TRANSACTED.
Please help us.
Thanks in advance.
This appears to be a memory related error. I would look for other signs of resource exhaustion in the process.
I have managed to get my hands on the bytes of an IMessage by using CreateILockBytesOnHGlobal, StgCreateDocfileOnILockBytes, OpenIMsgOnIStg, WriteClassStg and CopyTo, followed by ILockBytes.ReadAt (Outlook 2010).
Unfortunately, if I specify MAPI_UNICODE when calling OpenIMsgOnIStg, it does not have any effect. The result is a Non-Unicode compound file.
Am I missing another Unicode flag somewhere or is this a flaw in the implementation of ILockBytes or even intended to behave this way?
Please help me, I would prefer to avoid a temporary file.