Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: Redemption+CBuilder: RDOSession.Logon MAPILogonEx-Error

Geek News

Redemption+CBuilder: RDOSession.Logon MAPILogonEx-Error
tsahling[ at ]hausmannwynen.de 8/31/2006 12:23:12 PM
Hi!

I use Redemption 4.2 with C-Builder 5 via imported typelib.

I have the problem that a second usage of RDOSession.Logon returns an
EOleSysError with the message "Error in MAPILogonEx:
MAPI_E_NOT_INITIALIZED".

This is the code:

-----
::CoInitializeEx( 0, COINIT_MULTITHREADED );
// --
try
{
auto_ptr<TOutlookApplication> outlook( new TOutlookApplication( 0 )
);
// --
outlook->ConnectKind = ckNewInstance;
outlook->Connect();
// --
try
{
Variant draftMailEntryID;
// --
{
auto_ptr<TRDOSession> rdoSession( new TRDOSession( outlook.get()
) );
// --
rdoSession->Logon( "", "", false, true );
// --
try
{
Redemption_tlb::IRDOFolderPtr rdoDraftsFolder =
rdoSession->GetDefaultFolder( Outlook_tlb::olFolderDrafts );
Redemption_tlb::IRDOMailPtr rdoMail =
rdoDraftsFolder->Items->Add( Outlook_tlb::olMailItem );
// --
rdoMail->Import( WideString( m_vorlagenDatei ), type );
rdoMail->Subject = WideString( m_dokTitel );
rdoMail->Attachments->Add( m_pdfFilename );
rdoMail->Recipients->Add( m_kunEmail );
// --
rdoMail->Save();
// --
draftMailEntryID = rdoMail->EntryID;
}
__finally
{
rdoSession->Logoff();
}
}
// --
_NameSpacePtr comSession = outlook->GetNamespace( WideString(
"MAPI" ) );
// --
comSession->Logon( "", "", false, true );
// --
try
{
MailItemPtr mail = comSession->GetItemFromID( draftMailEntryID );

// --
mail->Display( true );
// --
mail->Close( olDiscard );
}
__finally
{
comSession->Logoff();
}
}
__finally
{
outlook->Disconnect();
}
}
__finally
{
::CoUninitialize();
}
----

This first time this code is executed, everything is fine. If the user
executes this code a second time, I get the error described above
(line: >rdoSession->Logon( "", "", false, true );<)

I tried already to wrap this code with
MAPIInitialize()/MAPIDeinitialize(), but the same error occurs.

Has anyone an idea what the problem might be?

Thanks!

Re: Redemption+CBuilder: RDOSession.Logon MAPILogonEx-Error
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 8/31/2006 5:09:10 PM
Are you sharing the same instance of IRDOSession between different threads?
What is TRDOSession? Is that your class?

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

<tsahling[ at ]hausmannwynen.de> wrote in message
news:1157026992.818264.204980[ at ]b28g2000cwb.googlegroups.com...
[Quoted Text]
> Hi!
>
> I use Redemption 4.2 with C-Builder 5 via imported typelib.
>
> I have the problem that a second usage of RDOSession.Logon returns an
> EOleSysError with the message "Error in MAPILogonEx:
> MAPI_E_NOT_INITIALIZED".
>
> This is the code:
>
> -----
> ::CoInitializeEx( 0, COINIT_MULTITHREADED );
> // --
> try
> {
> auto_ptr<TOutlookApplication> outlook( new TOutlookApplication( 0 )
> );
> // --
> outlook->ConnectKind = ckNewInstance;
> outlook->Connect();
> // --
> try
> {
> Variant draftMailEntryID;
> // --
> {
> auto_ptr<TRDOSession> rdoSession( new TRDOSession( outlook.get()
> ) );
> // --
> rdoSession->Logon( "", "", false, true );
> // --
> try
> {
> Redemption_tlb::IRDOFolderPtr rdoDraftsFolder =
> rdoSession->GetDefaultFolder( Outlook_tlb::olFolderDrafts );
> Redemption_tlb::IRDOMailPtr rdoMail =
> rdoDraftsFolder->Items->Add( Outlook_tlb::olMailItem );
> // --
> rdoMail->Import( WideString( m_vorlagenDatei ), type );
> rdoMail->Subject = WideString( m_dokTitel );
> rdoMail->Attachments->Add( m_pdfFilename );
> rdoMail->Recipients->Add( m_kunEmail );
> // --
> rdoMail->Save();
> // --
> draftMailEntryID = rdoMail->EntryID;
> }
> __finally
> {
> rdoSession->Logoff();
> }
> }
> // --
> _NameSpacePtr comSession = outlook->GetNamespace( WideString(
> "MAPI" ) );
> // --
> comSession->Logon( "", "", false, true );
> // --
> try
> {
> MailItemPtr mail = comSession->GetItemFromID( draftMailEntryID );
>
> // --
> mail->Display( true );
> // --
> mail->Close( olDiscard );
> }
> __finally
> {
> comSession->Logoff();
> }
> }
> __finally
> {
> outlook->Disconnect();
> }
> }
> __finally
> {
> ::CoUninitialize();
> }
> ----
>
> This first time this code is executed, everything is fine. If the user
> executes this code a second time, I get the error described above
> (line: >rdoSession->Logon( "", "", false, true );<)
>
> I tried already to wrap this code with
> MAPIInitialize()/MAPIDeinitialize(), but the same error occurs.
>
> Has anyone an idea what the problem might be?
>
> Thanks!
>


Re: Redemption+CBuilder: RDOSession.Logon MAPILogonEx-Error
tsahling[ at ]hausmannwynen.de 9/1/2006 7:32:04 AM
[Quoted Text]
> Are you sharing the same instance of IRDOSession between different threads?

No, the routine is executed once at a time.

But because of your question I had an idea and tried CoInitializeEx
with parameter COINIT_APARTMENTTHREADED. Now I don't get the exception
and everything works fine!

> What is TRDOSession? Is that your class?

That's a class generated by C-Builder from the Redemption type lib. It
inherits TOleServer and provides instant access to the interface object
behind it (and its events).

Thanks for your quick reply!

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net