Winfried
Winfried

Reputation: 11

Visual C++ Outlook automation

I want to automate some maintenance in Public Folders in Exchange with a VS C++ console application. I use VS Community 2017 and Outlook 2016 (with Exchange 2016).

After much searching I created a small application with the following relevant lines:

#import "C:/Program Files (x86)/Common Files/Microsoft Shared/OFFICE16/mso.dll" no_namespace \
rename("DocumentProperties", "OlkDocProps") rename("RGB", "OlkRGB")
    #import "C:\\Program Files (x86)\\Microsoft Office\\Office16\\msoutl.olb" \
rename_namespace("Outlook") \
rename("Folder", "OlkFolder") rename("CopyFile", "OlkCopyFile") \
rename("GetOrganizer", "GetOrganizerAE") rename("PlaySound", "OlkPlaySound")

and

_ApplicationPtr spApp( "Outlook.Application");

On compile I got loads of errors by Intellisense on the mso.tlh and msoutl.tlh, which I ignored (370 times "Forward declaration of enum type is nonstandard"). I got some errors on the #import lines, which I fixed with extra renames.

Now the application builds, but produces an exception where spAPP is declared and constructed:

Unhandled exception at 0x00007FF8879D5549 in DelDoubleMail.exe: Microsoft C++ exception: _com_error at memory location 0x00000015F3F0EFF0. occurred

How do I fix this?

Upvotes: 0

Views: 523

Answers (1)

Winfried
Winfried

Reputation: 11

I found the cause: a call CoInitializeEx() was missing before the sApp was created.

@Karthik: thank you for your suggestion, tinkering with different catch actions finally gave me the information I needed.

Upvotes: 1

Related Questions