Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot change thread mode after it is set

Status
Not open for further replies.

sjakiePP

Programmer
Apr 6, 2004
104
NL
Hello,

Above is the exception that I receive when I want to open a new MAPI session, to retreive the global address book from the exchange server. I am building an Outlook add-in, the version used is 2003

I tried to add [STAThread] to the methods used, but this had no effect. What could this be?

Thanks in advance.

Sjakie

Code:
try {
	MAPI.SessionClass oSession = new MAPI.SessionClass();	//session
	oSession.Logon(System.Environment.UserName, System.Reflection.Missing.Value, false, false, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value);	//login

	// You can select one AddressList, 
	// by changing the last enumerated type
	// selecting global addres list
	// MAPI.AddressList oAddressList = (MAPI.AddressList) oSession.GetAddressList(MAPI.CdoAddressListTypes.CdoAddressListPAB);
	MAPI.AddressList oAddressList = (MAPI.AddressList) oSession.GetAddressList(MAPI.CdoAddressListTypes.CdoAddressListGAL);
System.Diagnostics.Debug.WriteLine(oAddressList.Name);
	MAPI.AddressEntries oAddressEntries = (MAPI.AddressEntries) oAddressList.AddressEntries;

	for(int j = 1; j <= (int)oAddressEntries.Count; j++) {
		MAPI.AddressEntry oAddressEntry = (MAPI.AddressEntry)oAddressEntries.get_Item(j);
		// Print out each AddressEntry name
		System.Diagnostics.Debug.WriteLine(" " + oAddressEntry.Name);
	}

	oSession.Logoff();
}
catch (System.Exception ex) {
	System.Diagnostics.Debug.WriteLine(ex.Message);
	System.Diagnostics.Debug.WriteLine(ex.StackTrace);
	System.Diagnostics.Debug.WriteLine(ex.Source);
}

---------------------------------------------
Yes, the world is full of strange people.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top