Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

COM Interface definition

207 views
Skip to first unread message

Ashutosh

unread,
Apr 5, 2008, 11:48:32 AM4/5/08
to
Hi,
I am trying to define the interface for interface "IOlkErrorUnknown"
documented ONLY at
http://msdn2.microsoft.com/en-us/library/aa203932(office.11).aspx

I have created the .idl file and the definition looks something like
---------------------------------------------------------
[
uuid(797EE151-A04D-11d2-8072-00C04FC986D1),
helpstring("Provides extra information about the last error.")
]
interface IOlkErrorUnknown: IUnknown
{
[id(1), helpstring("method GetLastError")] HRESULT GetLastError( [in]
HRESULT hr, [out] LPWSTR *ppwszError);
};

---------------------------------------------------------
But when compiling I get this error

D:\My Documents\Programming\Visual C++\MAPI1\AccountManager.idl(8) :
error MIDL2025 : syntax error : expecting a type specification near
"HRESULT"
D:\My Documents\Programming\Visual C++\MAPI1\AccountManager.idl(8) :
error MIDL2026 : cannot recover from earlier syntax errors; aborting
compilation
---------------------------------------------------------

Please tell me how to resolve the issue.

Regards,
Ashutosh

Alex Blekhman

unread,
Apr 5, 2008, 1:26:32 PM4/5/08
to
"Ashutosh" wrote:
> I have created the .idl file and the definition looks something
> like
> ---------------------------------------------------------
> [
> uuid(797EE151-A04D-11d2-8072-00C04FC986D1),
> helpstring("Provides extra information about the last error.")
> ]
> interface IOlkErrorUnknown: IUnknown
> {
> [id(1), helpstring("method GetLastError")] HRESULT
> GetLastError( [in] HRESULT hr, [out] LPWSTR *ppwszError);
> };
>
> ---------------------------------------------------------
> But when compiling I get this error
>
> D:\My Documents\Programming\Visual
> C++\MAPI1\AccountManager.idl(8) : error MIDL2025 : syntax error
> : expecting a type specification near "HRESULT"

In the beginning of your IDL file put these directives:

import "oaidl.idl";
import "ocidl.idl";

It will bring common COM types and definitions.

HTH
Alex


Ashutosh

unread,
Apr 5, 2008, 2:44:58 PM4/5/08
to
Hi,
Thanks for you response. I have included those files but I still get
some errors.
The file now looks like
---------------------------------------------------------
import "oaidl.idl";
import "ocidl.idl";

//DEFINE_GUID(IID_IOlkErrorUnknown, 0x9240a6c0, 0xaf41, 0x11d2, 0x8c,
0x3b, 0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);
[
uuid(9240a6c0-af41-11d2-8C3B-00104B2A6676)
]
interface IOlkErrorUnknown: IUnknown
{


HRESULT GetLastError( [in] HRESULT hr, [out] LPWSTR *ppwszError);
};

---------------------------------------------------------
But, I get these errors

D:\My Documents\Programming\Visual C++\MAPI1\AccountManager.idl(9) :
error MIDL2311 : statements outside library block are illegal in
mktyplib compatability mode : [ Interface 'IOlkErrorUnknown' ]
D:\My Documents\Programming\Visual C++\MAPI1\AccountManager.idl(9) :
error MIDL2096 : duplicated attribute : [uuid] [ Interface
'IOlkErrorUnknown' ]
---------------------------------------------------------

The special thing about this interface is that its provided by the MAPI
system, but there doesn't exist any header file for this. I just want to
create an object of this interface/class and not create a COM server myself.

Regards,
Ashutosh Bhatt

Alex Blekhman

unread,
Apr 5, 2008, 4:02:38 PM4/5/08
to
"Ashutosh" wrote:
> The special thing about this interface is that its provided by
> the MAPI system, but there doesn't exist any header file for
> this. I just want to create an object of this interface/class
> and not create a COM server myself.

So you don't need any IDL files at all. Just find out which
EXE/DLL/OCX implements the object and #import it in your CPP file.
Then the compiler will generate all necessary headers.

Alex


Ashutosh

unread,
Apr 5, 2008, 4:38:42 PM4/5/08
to
Hi Alex,
Thanks for your prompt answers.

The thing is, I don't know which file actually implements these interfaces.

Please have a look at this
1) http://msdn2.microsoft.com/en-us/library/aa203900(office.11).aspx
(provided/implemented by outlook - IID is defined by Microsoft)
2) http://msdn2.microsoft.com/en-us/library/aa203932(office.11).aspx
(provided by CLIENT - IID is again fixed)

it contains interface references. I know the IID of the interface but
don't know the file. So, how do I implement/use them?

Regards,
A B

Alex Blekhman

unread,
Apr 5, 2008, 5:11:53 PM4/5/08
to
"Ashutosh" wrote:
> The thing is, I don't know which file actually implements these
> interfaces.
>
> Please have a look at this
> 1)
> http://msdn2.microsoft.com/en-us/library/aa203900(office.11).aspx
> (provided/implemented by outlook - IID is defined by Microsoft)
> 2)
> http://msdn2.microsoft.com/en-us/library/aa203932(office.11).aspx
> (provided by CLIENT - IID is again fixed)
>
> it contains interface references. I know the IID of the
> interface but don't know the file. So, how do I implement/use
> them?

I don't have the MS Office at hand right now. I'll look into it
tomorrow. I think there must be some kind of SDK for Office, too.

Alex


Alex Blekhman

unread,
Apr 5, 2008, 5:14:32 PM4/5/08
to
Also, you can launch OLE/COM Object Viewer utility and look for
specific interface. Then, if the interface is registered in the
system, you'll be able to see where it is implemented.

Alex


Igor Tandetnik

unread,
Apr 5, 2008, 10:06:33 PM4/5/08
to
"Alex Blekhman" <tkfx....@yahoo.com> wrote in message
news:e3NxAg1...@TK2MSFTNGP05.phx.gbl

> "Ashutosh" wrote:
>> The special thing about this interface is that its provided by
>> the MAPI system, but there doesn't exist any header file for
>> this. I just want to create an object of this interface/class
>> and not create a COM server myself.
>
> So you don't need any IDL files at all. Just find out which
> EXE/DLL/OCX implements the object and #import it in your CPP file.

The interface is not automation-compatible, and thus unlikely to be
described in any type library.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Igor Tandetnik

unread,
Apr 5, 2008, 10:09:30 PM4/5/08
to
"Ashutosh" <smbs...@newsgroup.nospam> wrote in message
news:uR0zo00l...@TK2MSFTNGP05.phx.gbl

> But, I get these errors
>
> D:\My Documents\Programming\Visual C++\MAPI1\AccountManager.idl(9) :
> error MIDL2311 : statements outside library block are illegal in
> mktyplib compatability mode : [ Interface 'IOlkErrorUnknown' ]

See if this helps:

http://support.microsoft.com/kb/243219

Charles Wang[MSFT]

unread,
Apr 7, 2008, 4:51:48 AM4/7/08
to
Hi Ashutosh,
Unfortunately the current release of Outlook Integration API does not
include any headers and DLLs that can be imported. If you want to use it,
you may have to create the header file by yourself and then use
CoCreateInstance() to create an instance. I think that you are on the right
way by creating your own IDL file for the API now.

You may refer to:
Introducing the Outlook Integration API
http://blogs.msdn.com/stephen_griffin/archive/2004/12/16/introducing-the-out
look-integration-api.aspx
Need help with IOlkAccount
http://groups.google.com/group/microsoft.public.office.developer.outlook.vba
/browse_thread/thread/933ab390f56aa206/3c28e2f44ac12dc1?hl=en&lnk=st&q=IOlkA
ccount+mapi#3c28e2f44ac12dc1

Regarding the error "statements outside library block are illegal in
mktyplib compatibility mode" in your second response, per my experiences,
you should be able to resolve it according to either of the following two
methods:
1. Put all the definitions of interfaces, coclasses and enums etc inside a
library block like this:
[
uuid(<library guid>),
version(<library version>),
helpstring(<library description>)
]
library MyLib
{
// interfaces, coclasses, enums etc
}

2. Configure the MIDL not to be mktyblib-compatible. In Visual Studio,
right-click the IDL file, click Properties, expand MIDL->General and set
"MkTypLib compatible" to No.

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.


Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msd...@microsoft.com.
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================

Ashutosh

unread,
Apr 7, 2008, 2:36:37 PM4/7/08
to
Hi,
Thanks for your response. I am have already gone through Dimstry's
article and I have already discussed the topic with him. I know the
interfaces to be used. But what I want to know is that "do I need to
create a .idl file or just a .h file with the interface definitions".


I have created the attached .h file, AccountManager.h (its not complete
thought but the interface IOlkAccountManager is complete) and trying
to create and object of IOlkAccountManager, by these lines

IOlkAccountManager * ppv;
CoCreateInstance(CLSID_OlkAccountManager,NULL, 0,
IID_IOlkAccountManager, (void**)&ppv);

For this I get Linker error,

MAPI1Dlg.obj : error LNK2001: unresolved external symbol
_CLSID_OlkAccountManager
MAPI1Dlg.obj : error LNK2001: unresolved external symbol
_IID_IOlkAccountManager

What should I do?? If I have to create a library for these, what will be
the Library's GUID? I didn't find any thing mentioned in the MSDN for
the library. Only Interfaces are mentioned.

Regards,
Ashutosh

AccountManager.h

Ashutosh

unread,
Apr 7, 2008, 2:41:11 PM4/7/08
to
Igor Tandetnik wrote:
> "Ashutosh" <smbs...@newsgroup.nospam> wrote in message
> news:uR0zo00l...@TK2MSFTNGP05.phx.gbl
>> But, I get these errors
>>
>> D:\My Documents\Programming\Visual C++\MAPI1\AccountManager.idl(9) :
>> error MIDL2311 : statements outside library block are illegal in
>> mktyplib compatability mode : [ Interface 'IOlkErrorUnknown' ]
>
> See if this helps:
>
> http://support.microsoft.com/kb/243219
>

I have created a header file and also followed the steps in the above
mentioned KB, but still no hope.

Please have a look at my reply to Charles Wang for the same issue.

Regards,
Ashutosh

Ashutosh

unread,
Apr 7, 2008, 2:44:51 PM4/7/08
to
HI,
In OLE Viewer, I can't see the interfaces. I have Dmistry's Outlook Spy
installed on my system. It's able to retrieve/create object for all
those interfaces for which I am trying. Probably it's not supposed to be
shown in that tool as decided by Microsoft.

Regards,
Ashutosh

Charles Wang[MSFT]

unread,
Apr 8, 2008, 10:48:43 AM4/8/08
to
Hi Ashutosh,
I think that you need not use the macro MIDL_INTERFACE in your header file.
Only having DEFINE_GUID and the interface declarations are enough. Please
try removing those MIDL_INTERFACE code lines to see if it helps.
Also I recommend that you define all GUIDs in a separate header file, so
does for those interface declarations. For example, you can simply copy all
the class identifiers and interface identifiers from Microsoft Office
Outlook 2003 Integration API Reference to a header file (guids.h):
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----
//{ed475410-b0d6-11d2-8c3b-00104b2a6676}
DEFINE_GUID(CLSID_OlkAccountManager, 0xed475410, 0xb0d6, 0x11d2, 0x8c,
0x3b, 0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{ed475411-b0d6-11d2-8c3b-00104b2a6676}
DEFINE_GUID(CLSID_OlkPOP3Account, 0xed475411, 0xb0d6, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{ed475412-b0d6-11d2-8c3b-00104b2a6676}

DEFINE_GUID(CLSID_OlkIMAP4Account, 0xed475412, 0xb0d6, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{ed475414-b0d6-11d2-8c3b-00104b2a6676}

DEFINE_GUID(CLSID_OlkMAPIAccount, 0xed475414, 0xb0d6, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{ed475418-b0d6-11d2-8c3b-00104b2a6676}

DEFINE_GUID(CLSID_OlkMail, 0xed475418, 0xb0d6, 0x11d2, 0x8c, 0x3b, 0x0,

0x10, 0x4b, 0x2a, 0x66, 0x76);

//{ed475419-b0d6-11d2-8c3b-00104b2a6676}

DEFINE_GUID(CLSID_OlkAddressBook, 0xed475419, 0xb0d6, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{ed475420-b0d6-11d2-8c3b-00104b2a6676}

DEFINE_GUID(CLSID_OlkStore, 0xed475420, 0xb0d6, 0x11d2, 0x8c, 0x3b, 0x0,

0x10, 0x4b, 0x2a, 0x66, 0x76);

//{4db5cbf0-3b77-4852-bc8e-bb81908861f3}

DEFINE_GUID(CLSID_OlkHotmailAccount, 0x4db5cbf0, 0x3b77, 0x4852, 0xbc,
0x8e, 0xbb, 0x81, 0x90, 0x88, 0x61, 0xf3);

//{4db5cbf2-3b77-4852-bc8e-bb81908861f3}

DEFINE_GUID(CLSID_OlkLDAPAccount, 0x4db5cbf2, 0x3b77, 0x4852, 0xbc, 0x8e,
0xbb, 0x81, 0x90, 0x88, 0x61, 0xf3);

//{9240A6C0-AF41-11d2-8C3B-00104B2A6676}

DEFINE_GUID(IID_IOlkErrorUnknown, 0x9240a6c0, 0xaf41, 0x11d2, 0x8c, 0x3b,
0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{9240A6C1-AF41-11d2-8C3B-00104B2A6676 }

DEFINE_GUID(IID_IOlkEnum, 0x9240a6c0, 0xaf41, 0x11d2, 0x8c, 0x3b, 0x0,

0x10, 0x4b, 0x2a, 0x66, 0x76);

//{9240a6c3-af41-11d2-8c3b-00104b2a6676}

DEFINE_GUID(IID_IOlkAccountNotify, 0x9240a6c3, 0xaf41, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{9240a6cb-af41-11d2-8c3b-00104b2a6676}

DEFINE_GUID(IID_IOlkAccountHelper, 0x9240a6cb, 0xaf41, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{9240a6cd-af41-11d2-8c3b-00104b2a6676}

DEFINE_GUID(IID_IOlkAccountManager, 0x9240a6cd, 0xaf41, 0x11d2, 0x8c, 0x3b,

0x0, 0x10, 0x4b, 0x2a, 0x66, 0x76);

//{9240a6d2-af41-11d2-8c3b-00104b2a6676}

DEFINE_GUID(IID_IOlkAccount, 0x9240a6d2, 0xaf41, 0x11d2, 0x8c, 0x3b, 0x0,

0x10, 0x4b, 0x2a, 0x66, 0x76);

----------------------------------------------------------------------------
----------------------------------------------------------------------------
---

and then declare all those functions in a separate header file (iolk.h)
according to Outlook 2003 Integration API Reference. After you finish these
jobs, rebuild and run your project again.

Hope this helps. If you have any other questions or concerns, please feel
free to let me know.

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================

Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: msd...@microsoft.com.
=========================================================

Ashutosh

unread,
Apr 8, 2008, 2:20:30 PM4/8/08
to
I think I need to include some libraries. Currently I have included
these libraries.

mapi32.lib Edkguid.lib Edkutils.lib Edkmapi.lib Addrlkup.lib
Edkdebug.lib Version.lib Mblogon.lib

Regards,
Ashutosh

Ashutosh wrote:
> Hi Charles,
> I have changed the code as you said. But I get Linker error when
> including these lines of code


>
> IOlkAccountManager * ppv;
> CoCreateInstance(CLSID_OlkAccountManager,NULL, 0,
> IID_IOlkAccountManager, (void**)&ppv);
>

> The errors I get are
>
> Linking...


> MAPI1Dlg.obj : error LNK2001: unresolved external symbol
> _CLSID_OlkAccountManager
> MAPI1Dlg.obj : error LNK2001: unresolved external symbol
> _IID_IOlkAccountManager

> Debug/MAPI1.exe : fatal error LNK1120: 2 unresolved externals
>
> The headers files I created are also attached.
>
> Please advice.
>
> Regards,
> Ashutosh
>

Charles Wang[MSFT]

unread,
Apr 10, 2008, 5:44:21 AM4/10/08
to
Hi Ashutosh,
This is a quick note to let you know that I am performing research on this
issue and may need more time to get back to you. I appreciate your patience.

Right now, could you please first read this KB article to see if it helps?
How to avoid error "LNK2001 unresolved external" by using DEFINE_GUID
http://support.microsoft.com/kb/130869

If you have any other questions or concerns, please feel free to let me

know. I am very glad to work with you for further research.

Charles Wang[MSFT]

unread,
Apr 11, 2008, 9:38:35 AM4/11/08
to
Hi Ashutosh,
Per my test, I found that the KB article indeed helped.

When I replaced "#include <guiddef.h>" by "#include "INITGUID.H" in your
header file AccountManagerGUIDs.h, it worked perfectly.
I also added "#pragma once" to the header of your header file.

Hope this helps. Please feel free to let me know if you have any other
questions or concerns. Have a nice day!

Ashutosh

unread,
Apr 14, 2008, 1:29:52 PM4/14/08
to
Hi Charles,
Thanks for you help. But, still I am not able to create the object. The
linker issue I mentioned is now solved, but the CoCreateInstance always
fails, don't know why???

IOlkAccountManager * ppv = NULL;
HRESULT hr= CoCreateInstance(CLSID_OlkAccountManager,NULL, 0,
IID_IOlkAccountManager, (void**)&ppv);

Object creation has nothing to do with the interface definition. It's
required only if the object is used and as far as GUIDs are concerned, I
don't think there is any problem with them. So, whys isn't the object
getting created? Can you please check?

Regards,
Ashutosh

Ashutosh

unread,
Apr 14, 2008, 10:15:43 PM4/14/08
to
The error code is Class not registered (80040154)
Regards,
Ashutosh

Ashutosh

unread,
Apr 15, 2008, 12:04:30 PM4/15/08
to
I don't understand one thing if the class is not registered (as evident
from the COM return code), how is Outlook Spy able to create the object
for the same interface/class?

Regards,
Ashutosh

SvenC

unread,
Apr 15, 2008, 12:15:43 PM4/15/08
to
Hi Ashutosh

> The error code is Class not registered (80040154)

Please check with regedit if you have this key on your
machine:

HKEY_CLASSES_ROOT\CLSID\
{ED475410-B0D6-11D2-8C3B-00104B2A6676}\InprocServer32

If yes, what values do you find underneath?

--
SvenC

Ashutosh

unread,
Apr 15, 2008, 12:37:19 PM4/15/08
to
The key exists and the values are

(default) = C:\PROGRA~1\MICROS~4\Office12\OLMAPI32.DLL
ThreadingModel = Both

I checked the dll, it exists but its not a com server. It's probably a
wrapper.

Regards,
Ashutosh

SvenC

unread,
Apr 15, 2008, 12:50:21 PM4/15/08
to
Hi Ashutosh,

> The key exists and the values are
>
> (default) = C:\PROGRA~1\MICROS~4\Office12\OLMAPI32.DLL
> ThreadingModel = Both
>
> I checked the dll, it exists but its not a com server. It's probably a
> wrapper.

How did you check that it is not a com server?
It does export DllGetClassObject.

--
SvenC

Ashutosh

unread,
Apr 15, 2008, 1:56:33 PM4/15/08
to
I just tried to open the dll in the object browser of the Visual studio
2005.

By the way, how did you check that it exports DllGetClassObject???

Regards,
Ashutosh

Alexander Nickolov

unread,
Apr 15, 2008, 1:53:42 PM4/15/08
to
That's normal - you didn't specify any context so COM cannot find
any server for that CLSID. In the third argument to CoCreateInstance
you can pass CLSCTX_ALL for any context.

May I gently suggest an introductory COM text here:

"Inside COM" by Dale Rogerson, MS Press

Finally, you are barking up the wrong tree since COM is out of topic
in the C/C++ group. The correct group for COM questions is:

microsoft.public.win32.programmer.ole

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD
email: agnic...@mvps.org
MVP VC FAQ: http://vcfaq.mvps.org
=====================================

"Ashutosh" <smbs...@newsgroup.nospam> wrote in message

news:endBpUln...@TK2MSFTNGP04.phx.gbl...

Ashutosh

unread,
Apr 15, 2008, 10:07:23 PM4/15/08
to
Hi Alexander,
Thanks for your response. About the com error in the code, when I was
writing the code, I though of putting that value later and totally
forgot. That time I was just trying to link the program, which was
creating problem. Its really silly that I never bothered to look at that
argument.

Regards,
Ashutosh

Charles Wang[MSFT]

unread,
Apr 17, 2008, 5:18:28 AM4/17/08
to
Hi Ashutosh,
I agree with Alexander. If this issue persists, please have a new post at
the community microsoft.public.win32.programmer.ole for more dedicated
support.
Also would you mind letting us know if this issue persist after you specify
CLSCTX_ALL in your CoCreateInstance?

Ashutosh

unread,
Apr 18, 2008, 3:20:17 AM4/18/08
to
Hi,
Thank you all for your help.
The issue has been resolved.

Regards,
Ashutosh

SvenC

unread,
Apr 22, 2008, 6:45:55 AM4/22/08
to
Hi,

> I just tried to open the dll in the object browser of the Visual
> studio 2005.

I doubt the object browser will open a dll

> By the way, how did you check that it exports DllGetClassObject???

Dependency Walker gives you a list of imports and exports.

--
SvenC

0 new messages