|
is the code i got from msdn for parsing mails
i have doubts in it like..
in the readnextmsg function what is ..c:\\pst\\myprofile.pro???
what shud i use in my program instead of that..and in the findnext function..whats OL??what are the parameters to be passed to the functions...so that i can autmate the process of receiving mails in my inbox!
thank u
here's the code
#include
#include
#include
#include
#include
#include
//assumption::character interface being used.
//the Simple MAPI functions for reading messages can't
//log on implicitly and require an explicit session handle.
/*the client application defines needed variables and
logs on to get a session handle/*
ULONG ReadNextUnreadMsg()
{
ULONG err;
LHANDLE lhSession; // Need a session for MAPIFindNext.
CHAR rgchMsgID[513]; // Message IDs should be >= 512 CHARs + a null.
MapiMessage *lpMessage; // Used to get a message back from MAPIReadmail
int i, // Ubiquitous loop counter.
totalLength; // Number of characters printed on a line.
err = MAPILogon(0L, // ulUIParam; 0 always valid.
"c:\\pst\\myprofil.pro",// Shouldn't hardcode this.
NULL, // No password needed.
0L, // Use shared session.
0L, // Reserved; must be 0.
&lhSession); // Session handle.
if (err != SUCCESS_SUCCESS) // Make sure MAPILogon succeeded.
{
printf("Error: could not log on\r\n");
return(err);
}
//next..the client searches for the first unread message in the //default folder in the store - probably the user's Inbox.
//Since there might not be any unread messages in the folder, //the client first tests the return value from the MAPIFindNext
//function against MAPI_E_NO_MESSAGES before checking against //SUCCESS_SUCCESS. If the call is successful, the client will have
///a valid message identifier to use to retrieve the first// unread message
/* */
// find the first unread message
err = MAPIFindNext(lhSession, // explicit session required
0L, // always valid ulUIParam
NULL, // NULL specifies interpersonal messages
NULL, // seed message ID; NULL=get first message
MAPI_LONG_MSGID | // needed for 512 byte rgchMsgID.
MAPI_UNREAD_ONLY, // only get unread messages.
0L, // reserved; must be 0
rgchMsgID);// buffer to get back a message ID.
if (err == MAPI_E_NO_MESSAGES) // make sure a message was found
{
printf("No unread messages.\r\n");
return(err);
}
if (err != SUCCESS_SUCCESS) // make sure MAPIFindNext didn't fail
{
printf("Error while searching for messages\r\n");
return(err);
}
//The client can now be sure it is safe to retrieve the message. //However, it is a good idea to check the return value from
//the MAPIReadMail function. If the call fails, the memory pointed //to by the client's lpMessage pointer will not be accessible by
//the client. The client should not try to display a message at //that location. Note that this example sets the
//MAPI_SUPPRESS_ATTACH flag so the returned message will not
//have any attachments in it and Simple MAPI will not create any //temporary files for them.
// retrieve the message
err = MAPIReadMail(lhSession, // Explicit session required.
0L, // Always valid ulUIParam.
rgchMsgID, // The message found by MAPIFindNext.
MAPI_SUPPRESS_ATTACH, // TO DO: handle attachments.
0L, // Reserved; must be 0.
&lpMessage); // Location of the returned message.
if(err != SUCCESS_SUCCESS) // Make sure MAPIReadMail succeeded.
{
printf("Error retrieving message %s\r\n",rgchMsgID);
return(err);
}
//Now, the client can display the message. As expected, //it begins by displaying the addressing information attached
//to the message before displaying the subject line and message text.// When displaying the addressing information, it is best if you
//can display friendly names. However, since friendly names are
//not always available, you must verify that each recipient //structure's lpszName member points to a valid string,
// and that the string is not a null string.
// Display the sender's name or address; use the friendly name// if it is present.
if((lpMessage->lpOriginator->lpszName != NULL) &&
lpMessage->lpOriginator->lpszName[0] != '\0')
printf("From: %s\r\n",lpMessage->lpOriginator->lpszName);
else
printf("From: %s\r\n",lpMessage->lpOriginator->lpszAddress);
//Displaying the recipients' addresses is complicated by the //need to avoid breaking a recipient's name or address across
//two lines. This code can be further improved by differentiating //between recipients based on their ulRecipClass members so that
//they can be properly displayed as To, CC, or BCC recipients.// As this code shows, handling recipient data can be the most
// complex part of reading a message.// Display the recipients' names or addresses. To Do: enhance
// this code to separate the recipients into lists of MAPI_TO,// MAPI_CC, and MAPI_BCC recipients for separate display.
if(lpMessage->nRecipCount == 0)
printf("Warning: no recipients present for this message\r\n");
else
for(i = 0; i < lpMessage->nRecipCount; i++) // For each recipient...
{
// This code uses lstrlen to calculate the length of strings and
// to validate that the strings have some content, since the
// length is needed anyway. This avoids the more verbose checks
// as were done for lpMessage->lpOriginator->lpszName earlier.
// lpszT references a name or address; simplifies later code.
// length is the length of the name or address.
LPSTR lpszT = lpMessage->lpRecips[i]->lpszName;
int length = lstrlen(lpszT);
if(i == 0) // First recipient; need to do some initialization.
{
printf("Recipients:");
totalLength = 11; // since strlen("Recipients:") = 11.
}
// Decide whether to use the friendly name or the address.
if(length == 0)
length = lstrlen(lpszT=lpMessage->lpRecips[i]->lpszAddress);
// Verify that the line has room for this name or address. If
// not, print a CR LF pair to go to the next line.
if(totalLength + length + 1 > LINE_WIDTH)
{
printf("\r\n");
totalLength = 0;
}
printf(" %s",lpszT); // Finally, print the name or address.
totalLength += length + 1;// Maintain the line length.
// If there are more addresses, separate them with semicolons.
if(i < (lpMessage->nRecipCount - 1))
{
printf(";");
totalLength++;
}
}
//Now, the client displays the subject line and message text if //they are present. Note that the message text can be printed
//with a simple call to the C library function printf. Since //the message was read with the MAPI_SUPPRESS_ATTACH flag set,
//there will be no attachments in it.// Display the subject and message body. Not printing anything
//for the subject is fine, but something should always be //printed for the message body since it is the last thing
//that this function displays.
if(lpMessage->lpszSubject != NULL && // Standard validity check
lpMessage->lpszSubject[0] != '\0')
printf("Subject: %s\r\n",lpMessage->lpszSubject);
if(lpMessage->lpszNoteText != NULL && // Standard validity check
lpMessage->lpszNoteText[0] != '\0')
printf("Message Text:\r\n%s",lpMessage->lpszNoteText;
else
printf("No message text.\r\n");
//Finally, the client releases the memory that the MAPIReadMail //function allocated for the message, closes the session,
//and returns a successful return value.
MAPIFreeBuffer(lpMessage);
MAPILogoff(lhSession, // The session.
0L, // 0 always valid for ulUIParam.
0L, // No logoff flags.
0L); // Reserved; must be 0.
return SUCCESS_SUCCESS; // Inform the caller of our success.
} // End of ReadNextUnreadMsg
ranjani
|
|
|
|
|
ranjjj wrote:
whats OL??
It's 0L, not OL (zero, not uppercase o). It's simply 0, as a long .
I haven't used MAPI before, so I can't help you with the MAPI stuff.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi all.
Please tell me how to read a word document from C, using simple fopen statement.
Please.
|
|
|
|
|
Hi,
It simple open doc file, call fopen(...) and next read him.
Absolutely other task that you will do with it after reading
Vitali
|
|
|
|
|
No the problem is , if i do a fopen, it reads from start. I want only the text content, no the header.
how to do this.
|
|
|
|
|
As I know doc is not open format.
To read it using low-level functions
you should know this closed format.
Vitali
|
|
|
|
|
It would not be easy. A Word document is an OLE compound file. You'd be much better off using StgOpenStorage() and then using the IStorage interface. I'm not an expert on this, but you should be able to find examples around about using IStorage .
Hope this helps,
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hello guy,
So, this is true, but question is about fopen.
I alsow want know how?
|
|
|
|
|
Sorry, I don't know about this. You'll have to try and find the format of an OLE Compound file. I doubt anyone here would know it - I think almost everyone here would do it using StgOpenStorage() .
Are you programming for Windows, or Linux or another O/S?
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Ryan Binns wrote:
I think almost everyone here would do it using StgOpenStorage().
Actually, I'd be inclined to use Word Automation. If that, in turn, is handled by StgOpenStorage() and/or IStorage , I'm not sure.
|
|
|
|
|
DavidCrow wrote:
Actually, I'd be inclined to use Word Automation. If that, in turn, is handled by StgOpenStorage() and/or IStorage, I'm not sure.
I was meaning, "assuming they wanted to read the file directly" . Word Automation is obviously a much nicer way to do it
FYI, I think I remember seeing the Word does use IStorage internally
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Word is a closed format that isn't documented. Reading it via fopen will only give you a lot of binary data and not the text of the document.
What exactly do you want to do with the data once read? You may be better looking at using the WORD COM object model to load the document and do your work on it.
Have a look on MSDN for KB196776.
Michael
'War is at best barbarism...Its glory is all moonshine. It is only those who have neither fired a shot nor heard the shrieks and groans of the wounded who cry aloud for blood, more vengeance, more desolation. War is hell.' - General William Sherman, 1879
|
|
|
|
|
Michael P Butler wrote:
You may be better looking at using the WORD COM object model to load the document and do your work on it.
I would have said that, but there's a number of reasons you'd want to use the file directly. One I came across is that you can not get access to image data via the COM object model. I ran into this while trying to get PowerPoint slide information, and it has caused me a lot of heartache since .
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
Hi !!
Here is what I'd like to do in C++ : (I don't know if it's possible or not)
I have several functions in a class. I want to call one of them according to a given string representing the name of the function to be called. It looks to me that the only possible way to do it is to manually compare the given string with each existing function and call the good one, but I think it would me much better to have it done automatically, without having to add a comparison if a new function is added.
I'd like to have something like :
MyObject->callThisFunction("processArray");
which would result in calling the processArray() function.
Any help or suggestion will be greatly appreciated !
Jerome
|
|
|
|
|
Use a map and add a macro to add new functions to the map. Then add code to execute the function in the map if it is found.
John
|
|
|
|
|
Hi,
thanks for your answer, but I'm not sure to know what is a map, and how I could use macro to add new functions to the map.
Could you be more specific ?
Thanks !
Jerome
|
|
|
|
|
A map will allow you to map the string names to the function pointers. This is STL and not a beginner subject. It's too early in the morning (05:33) for me to go into much depth now I'll see if I can expand later after I catch some more ...
John
|
|
|
|
|
Hi,
As I right understand you want create somthing
similar as command processor - take text input
and execute it commands.
Do do this simplest way is create association
between C++ functions(class members) and array( or map )
and function that should find 'assoc' in the array by
be text and call them.
Hope this help.
Vitali
|
|
|
|
|
Do you ultimatly want to make your application scriptable?
There are a few articles on how to do that on CP and they also explain what to do to let the scripts call methods of your applications objects.
Who is 'General Failure'? And why is he reading my harddisk?!?
|
|
|
|
|
jhwurmbach wrote:
Do you ultimatly want to make your application scriptable?
Yes !
jhwurmbach wrote:
There are a few articles on how to do that on CP and they also explain what to do to let the scripts call methods of your applications objects.
Could you point out such articles ? I tried to search CodePorject for them (with keywords like 'scriptable') but couldn't find any !
Thanks !
Jerome
|
|
|
|
|
|
mmmmhh looks like my weekend will be very enjoyable !
Thanks !
Jerome
|
|
|
|
|
Use pointer to function.
like this
{
void (*f[3])(int) = {function1, function2, function3};
int iParam;
(*f[2])(iParam); //calling function2
}
void function2(int c)
(
cout<<"hi"<
|
|
|
|
|
Hi there,
I have an ATL control with some color properties (get/set) that can be changed by a property page. For the colors I use the MS Stock Color Property Page (CLSID_StockColorPage).
The problem with this property page is that the list, showing the colors that can be changed, does not have a horizontal scrollbar, so the final part of long property names is chopped off, and you can't see the difference anymore, if there are properties that only differ in the final part of the name.
Anyone else also seen this problem and solved it? Should I be using a different property page?
Any suggestions are welcome.
Marco Voorwinden
|
|
|
|
|
Hello
I've got a client/server application that sends small packets 10-50 bytes.
The server, running win2000, uses IOCP and WSARecv + WSASend.
The client uses an ownmade socket class also using WSARecv/WSASend and overlapped IO.
Both the client/server waits for a Read, handles it and invoked WSARecv again. WSASend is only invoked when something is waiting in the outbuffer.
Serverside:
The first two transactions are handled ok (both transactions are sent at the same time and is recieved with the same WSARecv). But the second transaction, sent a couple of seconds later, will not be read by the server.
The IOCP function gets called by the WSARecv but 0 bytes read are reported.
ClientSide:
After the last send I do a WSAGetOverlappedResult and it reports that the bytes were sent.
I've tried to disable the nagle algorithm and setting SO_SNDBUF + SO_RCVBUF to 0 in the client. I've also tried to set SO_SNDBUF/SO_RCVBUF to zero in the server.
client log:
Socket(3)(Connect): WSAConnect() OK!
Socket(3)(Read): WSARecv
Socket(3)(Read): pending read...
Send Trans: 0
Send Trans: 2
Socket(3)(Send): New data triggered.
Socket(1)(Send): WSASend
Socket(3)(Send): Write completed
Socket(3)(Read): Read completed.
Socket(2)(Read): WSAGetOverlappedResult
Recieve, Trans: 0
Socket(2)(Read): 71/71 bytes handled
Socket(3)(Read): WSARecv
Socket(1)(Read): Completed directly 14 bytes
Recieve, Trans: 2
Socket(2)(Read): 14/14 bytes handled
Socket(3)(Read): WSARecv
Socket(3)(Read): pending read...
Send Trans: 3
Socket(3)(Send): New data triggered.
Socket(1)(Send): WSASend
Socket(3)(Send): Write completed
Socket(3)(Read): Read completed.
Socket(2)(Read): WSAGetOverlappedResult <- returns 0 bytes
serverlog:
prio: 1 client: 4 Connect from 127.0.0.1:1201
prio: 1 client: 4 Read -> Incomming bytes: 29
prio: 3 client: 4 Recieve, Trans: 0
prio: 3 client: 4 Send, Trans: 0
prio: 1 client: 4 Send -> WSASend
prio: 2 client: 4 Send ->Sent 71/71 bytes. (flags: 0)
prio: 3 client: 4 Recieve, Trans: 2
prio: 3 client: 4 Send, Trans: 2
prio: 1 client: 4 Send -> WSASend
prio: 2 client: 4 Send ->Sent 14/14 bytes. (flags: 0)
prio: 2 client: 4 Read -> 29/29 bytes handled
prio: 1 client: 4 Read -> WSARecv
prio: 2 client: 4 Read -> Pending read inited
prio: 0 client: 4 0 bytes read!
prio: 1 client: 4 Read -> aborting, dead or shutting down...
What am I doing wrong?
|
|
|
|
|