Solved

C++ and Outlook

Posted on 2004-09-15
25
563 Views
Last Modified: 2008-02-20
I have a VBScript that can check Outlook (without Outlook being open) and return the number of unread messages in the inbox.  Is there a way to do this, from console, using C++? :)

Thanks,
Tony
0
Comment
Question by:fattumsdad
  • 11
  • 10
  • 4
25 Comments
 
LVL 30

Expert Comment

by:Axter
ID: 12067406
>>Is there a way to do this, from console, using C++? :)

Yes.  You can use MAPI controls
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12067437
Axter,

Any examples you could share?  The only way I know how to use MAPI is with the MFC App Wizard...  I want to use Console only :)
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 12067485
Check out http://support.microsoft.com/default.aspx?scid=kb;en-us;171096 ("FILE: Simple MAPI Console Application")

This messaging application is a Simple MAPI client. It implements the following features:


Present the user with a menu
Logon to messaging system
Select a recipient/Get e-mail address
Enter e-mail address/Get recipient
Get details of recipient
Send mail message to recipient using default UI
Send mail message to recipient with no user interface
Send mail message with an attachment
Create a new message
List messages in the Inbox <------------------------------------
Read next unread message
Log off of the messaging system
Exit the client
Refresh the menu
0
 
LVL 30

Expert Comment

by:Axter
ID: 12067486
0
 
LVL 86

Expert Comment

by:jkr
ID: 12067559
>> Check out following links

Axter, *YOU* are starting that cr*p also?
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12067733
jkr,

I download the sample and the .exe works fine, but I get 7 errors when trying to compile the actual code...  can you help me with that?  It's a lot of code, that's why I ask....

0
 
LVL 30

Expert Comment

by:Axter
ID: 12067790
>>Axter, *YOU* are starting that cr*p also?

I was going to copy and paste some code, but as usuall, you beat me to it.

Usually, when I post a link, I also post some code.  I was trying to find somde that was more closely related to "unread messages query".
0
 
LVL 86

Expert Comment

by:jkr
ID: 12067966
>>Usually, when I post a link, I also post some code

Sorry, it's just that a lot of people start developing the habit of posting EE PAQ queries, maybe I am getting oversensitive to that :-(

fattumsdad,

What errors are you getting?
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12068004
Compiling source file(s)...
swap.cpp
In file included from swap.cpp:21:
swap.h:19:1: warning: "_WIN32" redefined
<built-in>:75:1: warning: this is the location of the previous definition
swap.h:35:19: mapix.h: No such file or directory
In file included from swap.cpp:21:
swap.h:56: warning: `class CApp' has virtual functions but non-virtual
destructor
swap.cpp: In member function `HRESULT CApp::cCaptureText(CHAR*, CHAR**)':
swap.cpp:195: error: `MAPIInitialize' undeclared (first use this function)
swap.cpp:195: error: (Each undeclared identifier is reported only once for each
function it appears in.)
swap.cpp:199: error: `MAPIAllocateBuffer' undeclared (first use this function)
swap.cpp:204: error: `MAPIUninitialize' undeclared (first use this function)
swap.cpp: In member function `HRESULT CApp::cCreateMessage(long unsigned int,
MapiMessage**, TCHAR**)':
swap.cpp:232: warning: initialization to non-pointer type `char' from NULL
swap.cpp:232: warning: argument to non-pointer type `char' from NULL
swap.cpp:255: error: `MAPIAllocateBuffer' undeclared (first use this function)
swap.cpp: In member function `HRESULT CApp::cFindMessageID(TCHAR*, long
unsigned int, TCHAR**)':
swap.cpp:373: error: `MAPIAllocateBuffer' undeclared (first use this function)
swap.cpp: In member function `HRESULT CApp::cSendAttachMail()':
swap.cpp:975: warning: initialization to non-pointer type `char' from NULL
swap.cpp:975: warning: argument to non-pointer type `char' from NULL
swap.cpp:971: warning: unused variable `ULONG cRecips'
swap.cpp: In member function `HRESULT CApp::cSendMessage(long unsigned int)':
swap.cpp:1110: warning: unused variable `ULONG cRecips'

Mail.exe - 7 error(s), 9 warning(s)

0
 
LVL 86

Expert Comment

by:jkr
ID: 12068033
Is this the sample's code or yours? It seems that

#include <mapix.h>

is missing somewhere.
0
 
LVL 30

Expert Comment

by:Axter
ID: 12068125
fattumsdad,

Do you have the latest SDK loaded on your computer.

If not, some of the MSDN code will not compile on your computer.

You can get the latest SDK free from MS.
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12068161
Axter,

I'm not using VC++, I'm using MinGW :)

jkr,

This is the samples code, I added #include <mapix.h> and I get "swap.h:35:19: mapix.h: No such file or directory".  I added it in swap.cpp, should I put it in the swap.h instead?
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 86

Expert Comment

by:jkr
ID: 12068205
Are there any header files that come with MinGW that start with 'MAPI*'? If MAPIX.h is missing, that means real trouble...
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12068323
Found "mapi.h" and added #include <mapi.h> in both swap.cpp and swapmain.cpp, still the same 7 errors 9 warnings :(
0
 
LVL 86

Expert Comment

by:jkr
ID: 12068706
Yes, but we'd need 'mapix.h' :-(

Can you see whether 'MAPIInitialize()' is in a different header file with MinGW?
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12068808
I'll check the header files and see if I can find that.  Also, I'll try running the code with VC++ when I get home :)
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12071540
jkr,

I just compiled the source with VC++ 6.0 and I'm still getting errors, I think there's something missing from the sample.  I'll just see what I can learn off of what's already there.  Thanks for your help :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 12076536
Compile fine here:

D:\tmp\Smplmapi>cl swap.cpp swpmain.cpp /link mapi32.lib
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8804 for 80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

swap.cpp
swap.h(19) : warning C4005: '_WIN32' : macro redefinition
        unknown(0) : see previous definition of '_WIN32'
swpmain.cpp
swap.h(19) : warning C4005: '_WIN32' : macro redefinition
        unknown(0) : see previous definition of '_WIN32'
Generating Code...
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:swap.exe
mapi32.lib
swap.obj
swpmain.obj
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12076676
I didn't do it from the command line...  I created a new project in VC++ and then added the source and header files.  Tried to build and got 3 errors.  I didn't even know that command line compiling was available in VC++ LOL not like I'd know how to use it anyway :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 12076700
Hmmm... What errors did you get, then?
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12076786
I'll have to get back to you on that one later this evening, I don't have VC++ here at work, only MinGW :(
0
 
LVL 86

Expert Comment

by:jkr
ID: 12076838
No prob, take you time :o)
0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12080961
jkr,

Here are the errors I get when trying to compile the sample with VC++:

Compiling...
swap.cpp
c:\swap.h(19) : warning C4005: '_WIN32' : macro redefinition
        unknown(0) : see previous definition of '_WIN32'
swpmain.cpp
c:\swap.h(19) : warning C4005: '_WIN32' : macro redefinition
        unknown(0) : see previous definition of '_WIN32'
Linking...
swap.obj : error LNK2001: unresolved external symbol _MAPIUninitialize@0
swap.obj : error LNK2001: unresolved external symbol _MAPIAllocateBuffer@8
swap.obj : error LNK2001: unresolved external symbol _MAPIInitialize@4
swap.obj : error LNK2001: unresolved external symbol _MAPIFreeBuffer@4
Debug/Test.exe : fatal error LNK1120: 4 unresolved externals
Error executing link.exe.

Test.exe - 5 error(s), 2 warning(s)

0
 
LVL 86

Expert Comment

by:jkr
ID: 12086512
All you need to add is mapi32.lib, as in the above command line:

cl swap.cpp swpmain.cpp /link mapi32.lib

:o)

0
 
LVL 1

Author Comment

by:fattumsdad
ID: 12087253
Alright, I'll give it  a shot this evening and let you know how it goes.  Thanks :)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

707 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now