Passing Outlook objects between threads C++

Im using C++ VS2005 and in the main thread I establish a reference to an 
Outlook Contact Item.
I call the Display method and it correctly creates an inspector and displays 
the Contact.

While the Contact is open I pass a IDISPATCH pointer to the Contact to 
another thread.

In the new thread I AddRef the Contact, the pointer seems good because I can 
get various properties, FileAs etc.

However when I try to call the Close method I get an invalid access 
exception (the method does not return with an hr result). Watching the 
Inspector events, OnClose and OnCloseComplete do get called before the 
exception. However the Contact is still open when the exception occures.

Any ideas please ? 


0
2/16/2007 12:23:05 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
529 Views

Similar Articles

[PageSpeed] 20

All of OOM objects are apartment threaded, so you need to marshall OOM 
objects if you are using them on the thread different from the one where the 
object was retrieved.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy  - Outlook, CDO
and MAPI Developer Tool

"Michael Tissington" <mtissington@newsgroup.nospam> wrote in message 
news:ex49f$UUHHA.868@TK2MSFTNGP05.phx.gbl...
> Im using C++ VS2005 and in the main thread I establish a reference to an 
> Outlook Contact Item.
> I call the Display method and it correctly creates an inspector and 
> displays the Contact.
>
> While the Contact is open I pass a IDISPATCH pointer to the Contact to 
> another thread.
>
> In the new thread I AddRef the Contact, the pointer seems good because I 
> can get various properties, FileAs etc.
>
> However when I try to call the Close method I get an invalid access 
> exception (the method does not return with an hr result). Watching the 
> Inspector events, OnClose and OnCloseComplete do get called before the 
> exception. However the Contact is still open when the exception occures.
>
> Any ideas please ?
> 


0
dmitry1 (75)
2/15/2007 10:41:53 PM
Hi Michael,
Thank you for posting here!

I notice that you have posted the same question in our 
microsoft.public.win32.programmer.messaging newsgroup, which I have already 
responded. So please check my answer there and if you need any further 
assistance on this particular issue, please reply to me in that thread so I 
can follow up with you in time. 

For your convenience, I have included my reply as follows:

------------------
Hi Michael,
Dmitry's suggestion is in right direction.
I would like to add more information here for your reference:
Please use CoMarshalInterThreadInterfaceInStream in your main thread before 
you create a new thread to streamlized the IDispatch pointer and use 
CoGetInterfaceAndReleaseStream to get the IDispatch pointer. 

You can refer to:
Give ActiveX-based Web Pages a Boost with the Apartment Threading Model ( 
Marshaling Interface Pointers )
http://www.microsoft.com/msj/0297/apartment/apartment.aspx

A Thread to Visual Basic
http://www.freevbcode.com/showcode.asp?ID=1287

Hope this helps. Please feel free to let me know if you have any other 
questions.
------------------

Thank you and have a nice day!

Charles Wang
Microsoft Online Community Support

====================================================== 
When responding to posts, please "Reply to Group" via 
your newsreader so that others may learn and benefit 
from this issue. 
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights. 
======================================================

0
changliw (164)
2/16/2007 3:18:06 AM
Hmm, any sugestions how to do this in C++ ?

"Dmitry Streblechenko" <dmitry@dimastr.com> wrote in message 
news:eKJi9IVUHHA.1212@TK2MSFTNGP03.phx.gbl...
> All of OOM objects are apartment threaded, so you need to marshall OOM 
> objects if you are using them on the thread different from the one where 
> the object was retrieved.
>
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy  - Outlook, CDO
> and MAPI Developer Tool
>
> "Michael Tissington" <mtissington@newsgroup.nospam> wrote in message 
> news:ex49f$UUHHA.868@TK2MSFTNGP05.phx.gbl...
>> Im using C++ VS2005 and in the main thread I establish a reference to an 
>> Outlook Contact Item.
>> I call the Display method and it correctly creates an inspector and 
>> displays the Contact.
>>
>> While the Contact is open I pass a IDISPATCH pointer to the Contact to 
>> another thread.
>>
>> In the new thread I AddRef the Contact, the pointer seems good because I 
>> can get various properties, FileAs etc.
>>
>> However when I try to call the Close method I get an invalid access 
>> exception (the method does not return with an hr result). Watching the 
>> Inspector events, OnClose and OnCloseComplete do get called before the 
>> exception. However the Contact is still open when the exception occures.
>>
>> Any ideas please ?
>>
>
> 


0
2/16/2007 4:52:11 PM
Never mind, I found the answer thanks.


0
2/16/2007 5:25:32 PM
Reply:

Similar Artilces:

no new E-mails in Outlook Express inbox
As of today no E-mails were received. Buckeye checked their system and it is was ok they suggested I contact Dell. My Dell computor is new and I have been in the process of transferring data from my Macintosh to Dell via E-mail. Is this helpful in solving the receiving of E-Mails? Virginia I also cannot locate my address book nor my entered E-Mail adresses??? In news:5D56DA8C-799A-46D2-8DDF-7D4A350640B9@microsoft.com, outlook new users <outlook new users@discussions.microsoft.com> typed: > As of today no E-mails were received. Buckeye checked their system > and it is w...

SPELL CHECK
I am unable to use spell check in outlook express....get the message...."an error occurred while the spelling was checked".... any help would be appreciated..thnx...sam If you are on exchange try and remove your profile folder from both the server and the client machine. Had the same problem last week. >-----Original Message----- >I am unable to use spell check in outlook express....get >the message...."an error occurred while the spelling was >checked".... > >any help would be appreciated..thnx...sam >. > Owen <ohein@sasktel.net> wro...

MHT attachments RECEIVED in outlook 2003 all MESSED UP
Okies, so you go into ONE NOTES and you draw a pretty picture and add some text and then you save the note as an ..MHT file because you are going to send it to your friend and they do NOT HAVE One notes. So you take the .mht file and attache it to an OUTLOOK 2003 e-mail and send it out. Kewl! So they get the attachment in Outlook 2003 and what they have is... is.. well.. ICKY SNOT!! I mean they get a blank "thing" with lots of little red X's where pics should be and all the PICS are listed above as separate pics in the attachment area. They ca...

view additional mailboxes offline in outlook
Using Outlook 2003 - We have stup a user to be able to share a mailbox, with another account. When the account is online then the user can see the mailbox and it's contents. When the user is offline they can see the mailbox, but if they click onn it they get an error message saying that the server is unavailable. The shared mailbox is setup for caching. Is there a way to see this mailbox offline? A user needs to be online to see other mailboxes. -- PATRICK REED [Outlook - MVP]~~~~~~ -Microsoft Certified Professional (MCP) -Have you checked http://www.slipstick.com? -Please...

Outlook 2003 wont stop
I sill have the probs with OL 2003. It absolutely wont stop. If I start Outlook the first time then there is no problem. As I click the EXIT button Outlook closes but the Icon of Outlook remains in the Taskbar of Windows. Restaring OL is not possible. Killing Outlook via TaskManager wont help either. Please Help!! Benjamin Some common reasons why Outlook will not shut down completely when you click either the X or Exit: 1. PDA synchronization software with your PDA in the cradle. 2. WinFax Pro (especially 10.02 in Outlook 2003) - contact their support for an alleged fix. 3. Franklin...

Outlook pop up windows stops outgoing mail
In the last 3 weeks I continue to get a pop up window titled "Enter Network Password". There is a key icon and the request: "Please type your user name and password." It then list my Server: (entered) Password: (entered with asterisk showing) I continually enter my Outlook password with Bellsouth and click the box "Save this password in your password list" and click "OK". Everything then works alright and then the window pops up again in 5 minutes. It happens over and over again. Anybody have any ideas on how to eliminate this? I use XP Pr...

Exporting emails from Outlook 2003 #2
I have a folder that contains over 500 threads on technical matters on a subject. I have tried to use Export to Exel but this does not transfere all the information over including not giving all the text in the body of the email. A similar problem is saving an email to a folder outside outlook it doesn't show the date so you may have a huge list of items all titled but not dated in the title Please can anybody help? Hi stevtb why do you want to export the emails. What is the target/reson to export the emails? -- Oliver Vukovics Share Outlook without Exchange (Vista Ready): Publi...

Outlook 97
I use Outlook 97 to send mail to recipients on a mailing list, but some are reporting that they get a blank message body. There is no attachment, and the messages are sent using MIME format, as plain text. Not all recipients have this problem. Any ideas? Would using UUENCODE help? If so,. why? All input gratefully received Regards Nick ...

Outlook 2007: "Cannot save free/busy information"
Hi, all I have been getting the error message "Cannot save free/busy information" from Outlook frequently these days. It started when we changed our configuration from connecting to an Exchange server on the LAN to using a proxy Exchange server that forwards (I imagine) to another Exchange server on a different LAN. I have my profile configured to deliver to a local PST file. It seems that Outlook does successfully update free/busy info on the server sometimes; the error message appears fairly randomly - e.g. sometimes when I delete a meeting request, but not every time. An...

Can't delete items or move items in Outlook 2002
When I try to delete an item in Outlook 2002, I get an error message that says: "The messaging interface has returned an unkown error. If the problem persists, restart Outlook." I also get that message if I try to move an opened email to a different folder using the Move To Folder command under the File menu. And if I close the email and simply try to click and drag it to a different folder, I get: "Can't move item" Can anyone please tell me how to fix these problems? I'm running Windows XP Pro. Could it be that my .pst file is too large? My outloo...

Problem w/ Outlook
I'm running Office XP and all of a sudden I can't move messages to other folders not delete messages from my Inbox. It doesn't give me a specific error code, just suggests that I restart Outlook. I've tried that with no success. I went to ControlPanel and repaired my Office installation. Any ideas? Eudora is looking beter all the time. ...

Reboots when opening Word documents in Outlook 2000
Whenever I try to open a Word document in Outlook 2000, my computer reboots. This just started happening. I have reloaded Office 2000, done virus scans and checked my pc with Spybot. Nothing has been identified. Any ideas? ...

Exchange 5.5, Outlook 2003 and Czech characters
We are using the following configuration: - Windows XP English - Outlook 2003 English + MUI for French, Spanish, Italian, German - Exchange 5.5. We encounter some problem with Czech characters. When contacts are stored in the mailbox in Exchange 5.5, some czech characters are replaced in contact name, company, .... When we stored the same contact in a pst file, evrything works fine. The characters are not replaced. Have somebody an idea or a solution for me? ...

Unable to open the outlook window.
I just downloaded Microsoft Office Outlook 2003 to my computer. When I try to open Outlook, the window opens for about 2 seconds and then closes automatically. I received an error message: "cannot start microsoft office outlook. unable to open the outlok window. the server is not available. contact your system administrator if this problem persist." I'm have home based computer and don't have an administrator. Can anyone help? Did you create a profile with settings (email account, POP3 and SMPT server names, etc.) for Outlook to use? -- Kathleen Orland Outlook Ti...

Import Outlook Contacts into AC2003
I've created an application using AC2003 which was both fast and easy. I have a new requirement to enhance the database to be able to import both contacts and calendar appointments from Office 2003. One thing that makes this somewhat complicated is that the client wants this process to show both the contact from Outlook and the contact from the access database side by side and selectively choose the pieces of info from the Outlook contacts to be appended in the access database. I know how to do this but it will be a lot of work. Can anyone point me to a tool, project...

cannot open Outlook
When I try to open Outlook 97 I get the following error: Mapisp32 This program has performed an illegal operation and will be shut down. Registers: EAX=00000000 CS=015f EIP=bff7b997 EFLGS=00000246 EBX=00000000 SS=0167 ESP=0063f8d0 EBP=0063fab8 ECX=c14eb7f0 DS=0167 ESI=0063fd58 FS=5217 EDX=bffc9490 ES=0167 EDI=0063fd58 GS=0000 Bytes at CS:EIP: ff 76 04 e8 26 89 ff ff 5e c2 04 00 56 8b 74 24 Stack dump: 0063fb10 7c6b2593 0063fd58 85762034 0063fb10 7c6b2484 0063fb10 85762034 85762278 85762278 7c6a7881 0063fb10 0063fb10 0063fb24 00000000 00000000 ...

Outlook not opening #2
I recently installed Outlook. When I try to open it, I get the error message "Outlook requires Outlook Express 4.01 or greater". I do have OE 5.0 installed. Why am I getting this error? ...

Problems with Outlook 2003
This only happens with externally sent messages. Internal messages work fine. One of my users alerted me to this issue, so I tested this myself. I created 2 messages (internal and external) and added delayed delivery to both. They were both set to go out at the same time. The internal message went, and the external message is still in the outbox. The user who alerted me to this found her message went "before" the scheduled time.We are not running in cached mode and of course running Outlook on Exchange. Is this a bug? ...

Outlook Opens looking for Exchange Server
A computer club member wishes to used Outlook so that she can sync with her Palm. Environment: Windows XP Pro SP2, IE 7, Windows Genuine Advantage installed. Symptom One: When Outlook is opened, the program is looking for Exchange Server. She is using a laptop with no exchange server available. Symptom Two: When performing Office Update, three items did not install all with error code 0x8024402C: 1. Update for Outlook Junk Mail (KB943591) 2. Office 2003 update SP3 3. Security Update for CAPICOM (KB931906) I suspicion that Office 2003 is a 60 day trial that has never been activated. Are ...

Outlook 2003 does not sync properly when connected.
When connected thru a Windows 2000 Server to the internet, and using VPN to connect to an Exchange Server running on Windows 2000 Small Busness Server, I get the following error. "(0x8004011D) The server is not available. Contact your administrator if this condition persists." I am able to connect it I dial into the internet and use VPN to connect to the internet. ...

Outlook prompts a errorr report
Hi, All my Outlook2003 always prompts :"! tasks"Microsoft Exchange Server" report a error(0x8004010F):"operation failure. can't find a object. But My outlook2003 send/receive email is normal.It can send and receive email. Then how can I solve this problems .thanks. !����Microsoft Exchange Server�������˴���0x8004010F):"����ʧ�ܡ��Ҳ���ij������ Nothing you can do from the client side as this message could mean that one or all key system folders on Exchange server are not being replicated/populated with information. The system folders I refer to are: Offline A...

Excel Events Conflict with VB and C# AddIns
Hi, I have two com addins running in Excel. One is written in VB and the other in C#. Both addins are interested in the Workbookopen event. When the event is triggered the c# code captures the event but the VB code does not. If i disable the c# addin then the vb code works. Looks like the c# addin is somehow blocking the vb events. Anyone know how to fix this? Many thanks, Andy There is only one WorkbookOpen event, so once one add-in hooks it, there is nothing for the other one to hook. If you are hooking the WorkbookOpen event in your add-ins, this is likely your problem. You may need...

Outlook across VPN and domains
I have a user who is temporarily working in my office. we have a vpn to our office in another city. I can ping the exchange server there and resolve it by name, but our AD are completely seaperate. We are actually seperate companies and do not wish to merge our domains. But outlook cannot resolve the name to the exchange server in the other domain. I can ping it, I can connect to it via telnet, but Outlook refuses to resolve it. Are you using cached mode or online? Does it work if you set up a hosts file? -- Diane Poremsky [MVP - Outlook] Need Help with Common Tasks? http://www.outloo...

outlook express 6 password problem
Help I have outlook express 6, windows xp. My internet provider just changed from att broadband to comcast. now i keep getting a password rejected error and i cant receive any mail. i cant seem to find a way to shut off the password. in my wifes page of xp it works ok. Hi, Bill - This is a group to support Outlook from the Office group of programs. Outlook Express is a part of Internet Explorer and is a quite different program, despite its similar name.. You will probably get a faster and more expert answer if you post this to an Outlook Express news group. Try posting in one of these n...

Folder-Link Icon in Outlook 2003
In the past (Outlook XP and before) I could distinguish between a regular Folder and a Folder-Link (.xnk file). Their icons were different. In Outlook 2003 a Folder-Link icon looks exactly the same as a Folder icon. Is they any way I can influence the look of Folder Link icons ? You can change the xnk-file icon association by going to Control Panel-> Folder Options -- Robert Sparnaaij [MVP-Outlook] www.howto-outlook.com Tips of the month: -What do the Outlook Icons Mean? -Create an Office 2003 CD slipstreamed with Service Pack 1 ----- "Arie Blonk" <Arie Blonk@discussio...