Importing third party interfaces that have the same name into an IDL file 
Author Message
 Importing third party interfaces that have the same name into an IDL file

There's a previous post that touches on this but doesn't really have a
conclusion.

Say you wanted to have an interface with two properties that expose third
party interfaces with the same name.

For example:
---------------------------------------------------------------------
library ContactSensor
{
 importlib("stdole32.tlb");
 importlib("stdole2.tlb");
 importlib("Excel.tlb");
 importlib("Word.tlb");

 [
  object,
  uuid(2944AA54-5B91-409E-A8C6-162D987D35DA),
  dual,
  pointer_default(unique)
 ]
 interface IMyInterface : IDispatch
 {
  [propget, id(1)] HRESULT ExcelApp([out, retval] IApplication **pVal);  //
here we want Excel::IApplication
  [propget, id(2)] HRESULT WordApp([out, retval] IApplication **pVal);  //
here we want Word::IApplication
 };

 [
  uuid(E99BFDBE-4018-4A37-BA87-6559C320518A)
 ]
 coclass MyClass
 {
  [default] interface IMyInterface;
 };

Quote:
};

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

Obviously there's a problem in the property definitions.  There doesn't seem
to be a way to indicated which 'IApplication' interface is desired where
since IDL doesn't support namespaces.  Is there any way around this?

Thanks,
Clint

please reply to via email as well.



Sat, 12 Feb 2005 02:08:32 GMT  
 Importing third party interfaces that have the same name into an IDL file
Move the interface declaration inside the library block. importlib()
the two type libraries for Word and Excel. Then use Word.IApplication
and Excel.IApplication respectively. The type library is the COM
equivalent of a namespace. Your problems likely won't end here
though. The generated header file will be useless to you, so you'll
have to use "#import raw_interfaces_only" and namespaces inside
your code...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> There's a previous post that touches on this but doesn't really have a
> conclusion.

> Say you wanted to have an interface with two properties that expose third
> party interfaces with the same name.

> For example:
> ---------------------------------------------------------------------
> library ContactSensor
> {
>  importlib("stdole32.tlb");
>  importlib("stdole2.tlb");
>  importlib("Excel.tlb");
>  importlib("Word.tlb");

>  [
>   object,
>   uuid(2944AA54-5B91-409E-A8C6-162D987D35DA),
>   dual,
>   pointer_default(unique)
>  ]
>  interface IMyInterface : IDispatch
>  {
>   [propget, id(1)] HRESULT ExcelApp([out, retval] IApplication **pVal);  //
> here we want Excel::IApplication
>   [propget, id(2)] HRESULT WordApp([out, retval] IApplication **pVal);  //
> here we want Word::IApplication
>  };

>  [
>   uuid(E99BFDBE-4018-4A37-BA87-6559C320518A)
>  ]
>  coclass MyClass
>  {
>   [default] interface IMyInterface;
>  };
> };
> -----------------------------------------------------------------------

> Obviously there's a problem in the property definitions.  There doesn't seem
> to be a way to indicated which 'IApplication' interface is desired where
> since IDL doesn't support namespaces.  Is there any way around this?

> Thanks,
> Clint

> please reply to via email as well.



Sat, 12 Feb 2005 02:44:57 GMT  
 Importing third party interfaces that have the same name into an IDL file

Quote:
> Move the interface declaration inside the library block. importlib()
> the two type libraries for Word and Excel.

I did this didn't I?

Quote:
> Then use Word.IApplication
> and Excel.IApplication respectively. The type library is the COM
> equivalent of a namespace.

Cool.  I haven't seen that in idl. before but now that you mention it, it
does mention that in the help for 'importlib'

Quote:
> Your problems likely won't end here
> though. The generated header file will be useless to you, so you'll
> have to use "#import raw_interfaces_only" and namespaces inside
> your code...

You're right - my problems don't end there.  Although, I'm not sure how
'raw_interfaces_only' applies.
I assume that the generated header file you're talking about is the one
generated from the IDL.  I do have a problem there because i get the error:
"syntax error : identifier 'IApplication'"
----------------------------------------------------------------------
#if defined(__cplusplus) && !defined(CINTERFACE)

    MIDL_INTERFACE("0B2EB2F4-E1BE-46E4-87E0-6D18E3E3800C")
    ITest2 : public IDispatch
    {
    public:
        virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE
get_ExcelApp(
            /* [retval][out] */ /* external definition not present */
IApplication **pVal) = 0;  // <<<<< error on this line

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

Firstly, why doesn't it translate Excel.IApplication to Excel::IApplication?
And second, where is IApplication supposed to be defined?  I don't see an
include or definition anywhere.  Even if I temporarily change IApplication
to Excel::IApplication it still says it is undefined.

I assume you were suggesting I put the #import statement in my cpp file.  It
seems more intuitive that it would be in the header file.  Are you
suggesting putting the import in the cpp file before the include for the
header?  The other option would appear to be to put a
'cpp_quote("#import...' in the idl so the import would be in the header.
Any clarification would be appreciated.

Thanks,
Clint



Sat, 12 Feb 2005 21:18:18 GMT  
 Importing third party interfaces that have the same name into an IDL file
I meant use #import in your CPP files _instead_of_ the MIDL-generated
header file. "#import <tlb> raw_interfaces_only named_guids" will be
roughly equivalent to the header file, but will define a namespace for
your definitions (you probably want it). You need to precede this with
Two #imports (same fashion) for the Word and Excel type libraries.

Now I admit I haven't done this personally :)...

--
=====================================
Alexander Nickolov
Microsoft MVP [VC], MCSD

MVP VC FAQ: http://www.mvps.org/vcfaq
=====================================

Quote:

> > Move the interface declaration inside the library block. importlib()
> > the two type libraries for Word and Excel.

> I did this didn't I?

> > Then use Word.IApplication
> > and Excel.IApplication respectively. The type library is the COM
> > equivalent of a namespace.

> Cool.  I haven't seen that in idl. before but now that you mention it, it
> does mention that in the help for 'importlib'

> > Your problems likely won't end here
> > though. The generated header file will be useless to you, so you'll
> > have to use "#import raw_interfaces_only" and namespaces inside
> > your code...

> You're right - my problems don't end there.  Although, I'm not sure how
> 'raw_interfaces_only' applies.
> I assume that the generated header file you're talking about is the one
> generated from the IDL.  I do have a problem there because i get the error:
> "syntax error : identifier 'IApplication'"
> ----------------------------------------------------------------------
> #if defined(__cplusplus) && !defined(CINTERFACE)

>     MIDL_INTERFACE("0B2EB2F4-E1BE-46E4-87E0-6D18E3E3800C")
>     ITest2 : public IDispatch
>     {
>     public:
>         virtual /* [helpstring][id][propget] */ HRESULT STDMETHODCALLTYPE
> get_ExcelApp(
>             /* [retval][out] */ /* external definition not present */
> IApplication **pVal) = 0;  // <<<<< error on this line

> ----------------------------------------------------------------------

> Firstly, why doesn't it translate Excel.IApplication to Excel::IApplication?
> And second, where is IApplication supposed to be defined?  I don't see an
> include or definition anywhere.  Even if I temporarily change IApplication
> to Excel::IApplication it still says it is undefined.

> I assume you were suggesting I put the #import statement in my cpp file.  It
> seems more intuitive that it would be in the header file.  Are you
> suggesting putting the import in the cpp file before the include for the
> header?  The other option would appear to be to put a
> 'cpp_quote("#import...' in the idl so the import would be in the header.
> Any clarification would be appreciated.

> Thanks,
> Clint



Sun, 13 Feb 2005 02:14:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Importing some functions from a third-party DLL

2. Importing some functions from a third-party DLL

3. Importing some functions from a third-party DLL

4. importing mshtml.idl in IDL file

5. How to link third party .LIB files

6. How to link third party .LIB files

7. Third Party DLLs with Header file

8. Import interface in IDL

9. import ###.idl and exposing interfaces

10. IDL question - import "msxml2.idl";

11. Third party component set opinions

12. First-chance exception in third-party DLL

 

 
Powered by phpBB® Forum Software