A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

MAPILogon failes when not used in GUI-Thread



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old June 7th 06, 10:25 PM posted to microsoft.public.outlook.program_vba
DanielH
external usenet poster
 
Posts: 6
Default MAPILogon failes when not used in GUI-Thread

Hi,

I am using MAPI in a C#-Program via a wrapper-class which simple DLLImports
the functions from mapi32.dll.
I am calling MAPILogon like this:
MAPILogon(hwnd, null, null, 0, 0, ref session);
hwnd is IntPtr.Zero (NULL in C++).
When I call this code somewhere in FormShow or similar (in the GUI-Thread)
anything works fine, I get logged in without being prompted anything.
Now, I have a Socket which asynchroniously listens on a port. When some data
is being received I am in a new thread. In this thread the same code from
above failes with the error-code 3 (MAPI_E_LOGIN_FAILURE?)
Why? Please help, this is kinda urgent...

Thanks a lot in advance
Ads
  #2  
Old June 8th 06, 01:26 AM posted to microsoft.public.outlook.program_vba
Dan Mitchell
external usenet poster
 
Posts: 58
Default MAPILogon failes when not used in GUI-Thread

=?Utf-8?B?RGFuaWVsSA==?= wrote in
:
I am using MAPI in a C#-Program via a wrapper-class which simple
DLLImports the functions from mapi32.dll.


You do know that this is officially unsupported, right?

http://support.microsoft.com/kb/813349


I am calling MAPILogon like this:
MAPILogon(hwnd, null, null, 0, 0, ref session);
hwnd is IntPtr.Zero (NULL in C++).
When I call this code somewhere in FormShow or similar (in the
GUI-Thread) anything works fine, I get logged in without being
prompted anything. Now, I have a Socket which asynchroniously listens
on a port. When some data is being received I am in a new thread. In
this thread the same code from above failes with the error-code 3
(MAPI_E_LOGIN_FAILURE?) Why? Please help, this is kinda urgent...


I'd guess that the code isn't running as a user that has permission to
log into the profile that your code is trying to use. Are you trying to
pass the session between threads? When your code is running in the main
thread, it's not logging in as such, it's just hooking onto the existing
Outlook session -- in the other thread, it has to create a session to
log into, so it may well be trying to pop up a dialog behind the scenes
and failing. Try passing in the name of the profile you're using, that
might help.

-- dan

-- dan
  #3  
Old June 8th 06, 08:08 AM posted to microsoft.public.outlook.program_vba
DanielH
external usenet poster
 
Posts: 6
Default MAPILogon failes when not used in GUI-Thread



"Dan Mitchell" schrieb:

=?Utf-8?B?RGFuaWVsSA==?= wrote in
:
I am using MAPI in a C#-Program via a wrapper-class which simple
DLLImports the functions from mapi32.dll.


You do know that this is officially unsupported, right?

http://support.microsoft.com/kb/813349



No, I didn't know, that it is not supported... How can I then send an eMail
via Outlook in .NET?

I am calling MAPILogon like this:
MAPILogon(hwnd, null, null, 0, 0, ref session);
hwnd is IntPtr.Zero (NULL in C++).
When I call this code somewhere in FormShow or similar (in the
GUI-Thread) anything works fine, I get logged in without being
prompted anything. Now, I have a Socket which asynchroniously listens
on a port. When some data is being received I am in a new thread. In
this thread the same code from above failes with the error-code 3
(MAPI_E_LOGIN_FAILURE?) Why? Please help, this is kinda urgent...


I'd guess that the code isn't running as a user that has permission to
log into the profile that your code is trying to use. Are you trying to
pass the session between threads? When your code is running in the main
thread, it's not logging in as such, it's just hooking onto the existing
Outlook session -- in the other thread, it has to create a session to
log into, so it may well be trying to pop up a dialog behind the scenes
and failing. Try passing in the name of the profile you're using, that
might help.


I tried to pass the profile-name - no changes.
The user the program is running the program is local admin, so this
shouldn't be a problem...
I don't see the difference between the main-thread and any other thread. Why
is one thread simply hooking into the existing session and one thread not?

Thanks for your answer
  #4  
Old June 8th 06, 04:05 PM posted to microsoft.public.outlook.program_vba
Ken Slovak - [MVP - Outlook]
external usenet poster
 
Posts: 5,848
Default MAPILogon failes when not used in GUI-Thread

Jumping in here for Dan. Neither Extended MAPI nor CDO 1.21 is supported for
..NET code, it might work sometimes but you can't rely on it. You must use
the Outlook object model or a wrapper for Extended MAPI that works across
the Interop such as Redemption (www.dimastr.com/redemption).

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"DanielH" wrote in message
...


"Dan Mitchell" schrieb:

=?Utf-8?B?RGFuaWVsSA==?= wrote in
:
I am using MAPI in a C#-Program via a wrapper-class which simple
DLLImports the functions from mapi32.dll.


You do know that this is officially unsupported, right?

http://support.microsoft.com/kb/813349



No, I didn't know, that it is not supported... How can I then send an
eMail
via Outlook in .NET?

I am calling MAPILogon like this:
MAPILogon(hwnd, null, null, 0, 0, ref session);
hwnd is IntPtr.Zero (NULL in C++).
When I call this code somewhere in FormShow or similar (in the
GUI-Thread) anything works fine, I get logged in without being
prompted anything. Now, I have a Socket which asynchroniously listens
on a port. When some data is being received I am in a new thread. In
this thread the same code from above failes with the error-code 3
(MAPI_E_LOGIN_FAILURE?) Why? Please help, this is kinda urgent...


I'd guess that the code isn't running as a user that has permission to
log into the profile that your code is trying to use. Are you trying to
pass the session between threads? When your code is running in the main
thread, it's not logging in as such, it's just hooking onto the existing
Outlook session -- in the other thread, it has to create a session to
log into, so it may well be trying to pop up a dialog behind the scenes
and failing. Try passing in the name of the profile you're using, that
might help.


I tried to pass the profile-name - no changes.
The user the program is running the program is local admin, so this
shouldn't be a problem...
I don't see the difference between the main-thread and any other thread.
Why
is one thread simply hooking into the existing session and one thread not?

Thanks for your answer


  #5  
Old June 8th 06, 07:56 PM posted to microsoft.public.outlook.program_vba
Dan Mitchell
external usenet poster
 
Posts: 58
Default MAPILogon failes when not used in GUI-Thread

"Ken Slovak - [MVP - Outlook]" wrote in
:
Jumping in here for Dan. Neither Extended MAPI nor CDO 1.21 is
supported for .NET code, it might work sometimes but you can't rely on
it.


To be precise, quoting from a MS support guy in another newsgroup:

"It's the sort of thing that'll mostly work. It'll work while you're
writing it. Then it'll work while you're testing it. It'll work while your
customer is evaluating it. Then as soon as the customer deploys it - BAM!
That's when it'll decide to start having problems. And Microsoft ain't
gonna help you with it, since we told you not to do it in the first place.
"

You must use the Outlook object model or a wrapper for Extended
MAPI that works across the Interop such as Redemption
(www.dimastr.com/redemption).


There's also mapi33.net, which a lot of people seem to have had success
with, though it's still not supported by MS.

-- dan

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Grouping problem (thread hierarchy screwed up by OE6) Vanguard Outlook Express 5 March 11th 06 09:05 AM
Conversation Thread Raffi Bearmant Outlook - General Queries 0 January 13th 06 06:45 AM
How can I delete a thread in a newsgroup? Mike G Outlook Express 4 January 13th 06 02:21 AM
Solution to this thread found skinnyladuk Outlook - General Queries 0 January 12th 06 12:52 AM
Reply/Forward Keeps Running Thread in one Message Instead of Separ Delnang Outlook - Using Forms 0 January 9th 06 04:27 PM


All times are GMT +1. The time now is 11:44 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.