Solved

Using MAPI

Posted on 1998-06-22
13
711 Views
Last Modified: 2010-04-04
At first sorry for my english...

I'm not new in Delphi but have a problem with MAPI in Delphi (ver. 3.01).

This is part of my program, its work well... but after exiting this procedure (TForm.Button2Click) is error occured (something like "access violation .... read of addres xxxxxxxx"). Im trying it on Exchage and OutLook...


{===================}
procedure TForm1.Button2Click(Sender: TObject);
var m, Seedm:LPSTR; ulResult:cardinal; h:hWnd; pf,ps:string;
begin

hSession:=0;
if hSession=0
   then ulResult:=MAPILogon(0,nil,nil, MAPI_LOGON_UI ,0,@hSession);

ulResult:=MAPIFindNext(hSession,0,nil,nil,0,0,m);
while ulResult=SUCCESS_SUCCESS do
begin
SeedM:=M;
ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID,0,M);
end;
{ReadMail;}
MAPILogoff (hSession,0,0,0);
hSession:=0;
end;
{================}

Thank you.
marsat.marinfo@comset.net
0
Comment
Question by:AlexanderA
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
13 Comments
 

Author Comment

by:AlexanderA
ID: 1355013
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1355014
Hi AlexanderA,

Don't search anymore on this subject ;-) Look at the source of this freeware component ... or just use it!.

Excelent demo's and good documents.

temail2.zip at Torries!

torry.rimini.com/vcl/internet/temail2.zip.

Regards, Zif.
0
 

Author Comment

by:AlexanderA
ID: 1355015
From: ZifNab Date: Monday, June 22 1998 - 02:42AM PDT  
Hi AlexanderA,
Don't search anymore on this subject ;-) Look at the source of this freeware component ... or just use it!.
Excelent demo's and good documents.
temail2.zip at Torries!
torry.rimini.com/vcl/internet/temail2.zip.
Regards, Zif.

Im ulready have using this component, but error still occured,
may be this is a Delphi error? Or OutLook problem? But im trying it on many computer.

Im desperate...
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:ZifNab
ID: 1355016
where is hSession defined?
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355017
You did not allocate space for M and Seedm

As write in help for MAPIFindNext
MessageID
Output parameter specifying the returned message identifier. The MessageID parameter is a variable-length string allocated by the CALLER. To ensure compatibility, ALLOCATE 512 characters. A smaller buffer will only be sufficient if the returned message identifier will always be 64 characters or less.
0
 

Author Comment

by:AlexanderA
ID: 1355018
From: ZifNab Date: Monday, June 22 1998 - 04:03AM PDT  
where is hSession defined?
 
Dont worry - all variable defined and space is allocated,
its just a part of my program...

OK.  
Excelent demo's and good documents.
temail2.zip at Torries!
torry.rimini.com/vcl/internet/temail2.zip.

This component doesnt working too (its working but error occured /see my original message/)
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355019
Please, write full version of TForm1.Button2Click(Sender: TObject);
0
 
LVL 3

Expert Comment

by:vladika
ID: 1355020
Why do you not use hSession in
  ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID,0,M); ?

The value of the Session parameter must represent a valid session; it CANNOT BE ZERO.

0
 

Author Comment

by:AlexanderA
ID: 1355021
>Why do you not use hSession in
>  ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or >MAPI_LONG_MSGID,0,M); ?
>The value of the Session parameter must represent a valid >session; it CANNOT BE ZERO.

OK. Just run my code and try to do this...
Im feel myself a little stupid.
Ok, part with FindNext is working now - thanks to Vladika, (im allocate to small space for PChar).

BUT now the other part doesnt working (the error occured on EXIT of program - a little strange):

procedure TForm1.Button2Click(Sender: TObject);
var m, Seedm:PChar; ulResult:cardinal; h:hWnd; i:integer;
lpMapiMessage: PMapiMessage;
begin
m := Stralloc(600);
FillChar(m^, 600,0);
Seedm := Stralloc(600);
FillChar(Seedm^, 600,0);

hSession:=0;
 if hSession=0
    then ulResult:=MAPILogon(0,nil,nil, {MAPI_EXTENDED or }MAPI_LOGON_UI {or MAPI_NEW_SESSION},0,@hSession);
 Form1.memo1.lines.add(IntToStr(ulResult));
 ulResult:=MAPIFindNext(hSession,0,nil,nil,0,0,m);
 Form1.memo1.lines.add(IntToStr(ulResult));
while ulResult=SUCCESS_SUCCESS do
begin
 form1.memo1.lines.add('FindMessage'+m);
 form1.memo2.lines.add(SeedM);
 Application.ProcessMessages;
 StrPCopy(SeedM, M);

 MapiReadMail(0, 0, m,{MAPI_DIALOG or }{MAPI_LOGON_UI or MAPI_NEW_SESSION}0, 0, lpMapiMessage);

{^^^^^ i think problem is here...}

 ulResult:=MAPIFindNext (0,0,Nil,SeedM,MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID,0,M);
end;
Form1.memo1.lines.add('Mapi get OK');
{ReadMail;}
MAPILogoff (hSession,0,0,0);
hSession:=0;
Form1.memo1.lines.add('Mapi logoff OK');
end;


0
 

Author Comment

by:AlexanderA
ID: 1355022
Still waiting for answers...
Im want to understand how to work with MAPI.
To Vladika - as i know you have MAPI documentation - can you send me some of it??? (MapiReadMail, SendMail, FindNext, Logon, Logoff and so on...), i have download part of SDK (abt 4Mb) but didnt find nothing - only examles in C.

Thank you very much for help.
marsat.marinfo@comset.net
0
 
LVL 3

Accepted Solution

by:
vladika earned 100 total points
ID: 1355023
1) You did not call StrDispose for M and SeedM in the end of procedure
2) M and SeedM is NULL-terminated string, so why are you use StrPCopy?
StrPCopy works for pascal style strings
3) You did not use hSession in MAPIFindNext and MAPIReadMail
4) Check type of hSession (it must be LHANDLE).

Try my procedure

procedure TForm1.Button2Click(Sender: TObject);
type TMapiMessageID = array[0..511] of Char;
var ulResult:cardinal;
    lpMapiMessage: PMapiMessage;
    M, SeedM: TMapiMessageID;
begin
  hSession:=0;
  ulResult:=MAPILogon(0,nil,nil, {MAPI_EXTENDED or }MAPI_LOGON_UI {or MAPI_NEW_SESSION},0,@hSession);
  Memo1.lines.Add('MAPILogon: Result = '+IntToStr(ulResult));
  ulResult:=MAPIFindNext(hSession,0,nil,nil,0,0,M);
  Memo1.lines.Add('MAPIFindNext: Result = ' + IntToStr(ulResult));
  while ulResult=SUCCESS_SUCCESS do
  begin
    Memo1.lines.Add('FindMessage: MsgID='+M);
    Application.ProcessMessages;
    Move(M, SeedM, SizeOf(TMapiMessageID));  // copy M into SeedM

    MapiReadMail(hSession, 0, M,{MAPI_DIALOG or }{MAPI_LOGON_UI or MAPI_NEW_SESSION}0, 0, lpMapiMessage);  // use hSession here

    ulResult:=MAPIFindNext (hSession, 0, nil, SeedM, MAPI_GUARANTEE_FIFO or MAPI_LONG_MSGID, 0, M);  // use hSession here
    Memo1.lines.Add('MAPIFindNext: Result = ' + IntToStr(ulResult));
  end;
  Memo1.lines.add('Mapi get OK');
  {ReadMail;}
  MAPILogoff (hSession,0,0,0);
  hSession:=0;
  Memo1.lines.add('Mapi logoff OK');
end;


0
 
LVL 3

Expert Comment

by:vladika
ID: 1355024
See mapi.pas in Delphi 3\Source\RTL\Win
See mapi.hlp in Delphi 3\HELP

If you have not these files I can send it to you.

0
 

Author Comment

by:AlexanderA
ID: 1355025
Vladika, thank you very much.

I dont believe myself but its working now.

Im just getting started this project - and this is not last my question.

Thank you again.
Write me at -  marsat.marinfo@comset.net
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question