Hi,

I have an existing .ocx file which contains a map. I need to open this file in C++ and not in MFC. MSDN help suggested me that it can be done throuch " #import "file_name" " However, the description is not descriptive and helpful. If anyone can provide me some ideas or sample code to read this file would be greatful.

Hope someone will give reply to this :-)

Thanks & regards,
Swetha

a #import directive like
#import "<name of the ocx file or typelibrary>" no_namespace, raw_interfaces_only \
named_guids raw_native_types <any other #import attributes>

will generate a header file with the name <base name of tlb/ocx>.tlh. and this header is impliciltly #included.
the #import attributes specify options for generating the header file. this header contains C++ definitions of COM interfaces, types etc and can be directly used in your code.
instantiate the object using a CoCreateInstance. COM methods are seen by C++ as virtual functions. open the .tlh file to see the declarations and use the methods like normal virtual functions. once you are done, call Release instead of using delete.

Hi,

Thanku very much for giving quick reply.
Actually I am very new to c++.So now I am having .ocx file.
Using #import "filename" ?I am trying to read that file.If I use #import directive it created *.tlh and .tli files.But it is giving some errors while using CoCreateInstandce function.
If you dont mind can any one send some simple sample code related to this?
Or where to call this CoCreateInstance function and which parameters need to give?

I hope will give reply as early as possible.

Thanks And Regards,
swetha.

> ...some simple sample code related to this

#include <iostream>
#include <windows.h>
#include <cassert>

// disable a whole bunch of unnecessary (for me) stuff  by no_*
#import "C:\\Program Files\\iTunes\\ITDetector.ocx"  \
        no_namespace no_smart_pointers raw_interfaces_only \
        raw_native_types no_implementation named_guids

int main()
{
  CoInitialize(0) ;
  {
      IiTunesDetector* pitd = 0 ;
      // CLSID_iTunesDetector, IID_IiTunesDetector are 
      // picked up from itdetector.tlh (named_guids)
      HRESULT hr = CoCreateInstance( CLSID_iTunesDetector,
                    0, 
                    CLSCTX_ALL,
                    IID_IiTunesDetector, // interface uuid 
                    reinterpret_cast<void**>(&pitd) ) ;
      assert( SUCCEEDED(hr) ) ;
      
      
      // iTunesVersion is a property (raw_interfaces_only)
      long version = 0 ;
      hr = pitd->get_iTunesVersion( &version ) ;
      assert( SUCCEEDED(hr) ) ;
      std::cout << "iTunes version is " << std::hex 
               << std::showbase << version << '\n' ;
      
      pitd->Release() ;
  }
  CoUninitialize() ;
}

Hi vijayan,
Thanks a lot for ur prompt response.I will try tomarrow.

The .ocx file contains the map.So I need to read that file and display that map.I think using ur code I can achieve this one.

Thanks And Regards,
swetha.

Hi vijayan,

How did you define "IID_IiTunesDetector" variable in your header file? I tried defining this variable from all possible ways .However, while compiling I am getting error as unexpected identifier for this variable.

Following is my code.
//////////////////////////////////////////////////

#import "c:\WINNT\system32\mmap.ocx"
int main()
{
CoInitialize(NULL);
 _DMMap* pMP = 0;
HRESULT hr = CoCreateInstane(CLSID_DMMap,0,CLSCTX_ALL,IID_DMMap,reinterpret_cast  <void**>(&pMP));
.........
.........
CoUninitialize();
}

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I think u got my doubt.Can you clarify and send the sollution?Hope u will send the reply.

Thanks in Advance,
swetha.

> How did you define "IID_IiTunesDetector" variable in your header file?
it was defined for me in the generated .tlh header due to the presence
of the named_guids attribute in the #import directive

this is (an extract from) the .tlh header generated:

// ...
// Forward references and typedefs
struct __declspec(uuid("d6995525-b33a-4980-a106-9df58570cc66"))
/* LIBID */ __ITDETECTORLib;
struct /* coclass */ iTunesDetector;
struct __declspec(uuid("45d2c838-0137-4e6a-aa3b-d39b4a1a1a28"))
/* dual interface */ IiTunesDetector;

// Type library items
struct __declspec(uuid("d719897a-b07a-4c0c-aea9-9b663a28dfcb"))
iTunesDetector;
    // [ default ] interface IiTunesDetector

struct __declspec(uuid("45d2c838-0137-4e6a-aa3b-d39b4a1a1a28"))
IiTunesDetector : IDispatch
{
    // Raw methods provided by interface
    // ...
      virtual HRESULT __stdcall get_iTunesVersion (
        /*[out,retval]*/ long * pVal ) = 0;
    // ...
};

// Named GUID constants initializations
extern "C" const GUID __declspec(selectany) LIBID_ITDETECTORLib =
    {0xd6995525,0xb33a,0x4980,{0xa1,0x06,0x9d,0xf5,0x85,0x70,0xcc,0x66}};
extern "C" const GUID __declspec(selectany) CLSID_iTunesDetector =
    {0xd719897a,0xb07a,0x4c0c,{0xae,0xa9,0x9b,0x66,0x3a,0x28,0xdf,0xcb}};
extern "C" const GUID __declspec(selectany) IID_IiTunesDetector =
    {0x45d2c838,0x0137,0x4e6a,{0xaa,0x3b,0xd3,0x9b,0x4a,0x1a,0x1a,0x28}};
// ...

so i could use the named constants as in

CoCreateInstance( CLSID_iTunesDetector, 0, 
                    CLSCTX_ALL,
                    IID_IiTunesDetector,
                    reinterpret_cast<void**>(&pitd) ) ;

alternatively i could have written

CoCreateInstance( __uuidof(iTunesDetector), 0, 
                    CLSCTX_ALL,
                    __uuidof(IiTunesDetector),
                    reinterpret_cast<void**>(&pitd) ) ;

this would not require generation of named guid constants.

if you want to generate named guid constants, use named_guids attribute in the #import directive

#import "c:\WINNT\system32\mmap.ocx" named_guids no_namespace

without the no_namespace attribute for the #import,
all names imported would be inside a namespace (with the base name of the typelib).

or else use the __uuidof operator
in your case the uuid for the interface would be given by __uuidof( _DMMap )
in all cases, look in the generated .tlh file to get the correct identifiers.
eg. if you see struct /* coclass */ <name of class> ; in the header,
for the CLSID you should use __uuidof( <name of class> )

you don't know anything about using COM in C++, do you?
even if you get to somehow do this part now, you are going to face more problems
somewhere else sooner rather than later. perhaps you should take some time to
first read http://www.amazon.com/Inside-Microsoft-Programming-Dale-Rogerson/dp/1572313498
and then http://www.amazon.com/Essential-COM-Don-Box/dp/0201634465

Hi vijayan,

this is (an extract from) my "MMap.tlh" header generated:

/////////.........................................///////////
	
struct __declspec(uuid("d5f63c22-b3d3-11d0-b8f0-0020af344e0a"))
/* dispinterface */ _DMMap;

struct __declspec(uuid("d5f63c23-b3d3-11d0-b8f0-0020af344e0a"))
/* dispinterface */ _DMMapEvents;
struct /* coclass */ MMap;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_DMMap, __uuidof(IDispatch));
_COM_SMARTPTR_TYPEDEF(_DMMapEvents, __uuidof(IDispatch));

//
struct __declspec(uuid("d5f63c22-b3d3-11d0-b8f0-0020af344e0a"))
_DMMap : IDispatch
{
    //
    // Property data
    //

    __declspec(property(get=GetMapNorth,put=PutMapNorth))
    double MapNorth;
    __declspec(property(get=GetMapSouth,put=PutMapSouth))
    double MapSouth;
    __declspec(property(get=GetMapEast,put=PutMapEast))
    double MapEast;
......
......
......
};
struct __declspec(uuid("d5f63c23-b3d3-11d0-b8f0-0020af344e0a"))
_DMMapEvents : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    // Methods:
    HRESULT MovePosition (
        double X,
        double Y );
    HRESULT Click ( );
  .....
  ......
  .....
};
struct __declspec(uuid("d5f63c24-b3d3-11d0-b8f0-0020af344e0a"))
MMap;
// [ default ] dispinterface _DMMap
    // [ default, source ] dispinterface _DMMapEvents
//
// Named GUID constants initializations
//

extern "C" const GUID __declspec(selectany) LIBID_MMAPLib =
    {0xd5f63c21,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) DIID__DMMap =
    {0xd5f63c22,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) DIID__DMMapEvents =
    {0xd5f63c23,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) CLSID_MMap =
    {0xd5f63c24,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};

so now I am using the named constants as

///mmap.cpp
#import "c:\WINNT\system32\MMap.ocx" 

void  main()
{
	CoInitialize( NULL);
		
		_DMMap* pMP = 0;
		HRESULT hr  = CoCreateInstance( __uuidof(MMap), 
					  NULL,
					  CLSCTX_ALL,
					  IID_DMMap,     
					  reinterpret_cast <void**>(&pMP));  
		assert(SUCCEEDED(hr));
		hr	= pMP->GetMapID();
		assert(SUCCEEDED(hr));
		pMP ->Release();
	  CoUninitialize();
}

But while compiling error is getting errors like
'MMap' :undeclared identifier
_DMMap' : no GUID has been associated with this object

Actually I am not having idea about COM in C++. Surely I will see those links and I will try to learn about this.

Please tell me what I did wrong?Or you tell me how u r generating named guid constants using # import directive?

Thankyou very much for ur prompt reply.

Thanks in advance,
swetha.

> But while compiling error is getting errors like 'MMap' :undeclared identifier
looks like you have not used the no_namespace attribute; so the identifiers are in a namespace in the .tlh
also looks like you have not read my previous post or if you have read it, you haven't understood it.

in any case, to avoid getting into what in programming would be called an infinite loop, post the entire contents of the generated .tlh file. also the actual #import statement that you used.
on second thoughts, don't post it; just attach it to your post as a plain text file. that way, we would not have to contend with the intricacies of using code tags and the perversities indulged in by aniweb's code formatter and the preview facility provided.

/*************************************************/
This is mmap.tlh header file
/***********************************************************/

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

namespace MMAPLib {

//
// Forward references and typedefs
//

struct __declspec(uuid("d5f63c22-b3d3-11d0-b8f0-0020af344e0a"))
/* dispinterface */ _DMMap;
struct __declspec(uuid("d5f63c23-b3d3-11d0-b8f0-0020af344e0a"))
/* dispinterface */ _DMMapEvents;
struct /* coclass */ MMap;

//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_DMMap, __uuidof(IDispatch));
_COM_SMARTPTR_TYPEDEF(_DMMapEvents, __uuidof(IDispatch));

//
// Type library items
//

enum enumMoveMapMode
{
    Stationary = 0,
    Floating = 1
};

enum enumBevelStyle
{
    BevelNone = 0,
    BevelRaised = 1,
    BevelLowered = 2
};

enum enumObjectSymbol
{
    SymbolWaypoint = 0,
    SymbolNavAid = 1,
    SymbolAirport = 2,
    SymbolAirplane = 3,
    SymbolPicture = 4,
    SymbolUserDefined = 5
};

enum enumObjectStyle
{
    Transparent = 0,
    Opaque = 1
};

enum enumLineStyle
{
    Solid = 0,
    Dash = 1,
    Dot = 2,
    DashDot = 3,
    DashDotDot = 4
};

enum enumWaypointLineStyle
{
    WaypointLineNone = 0,
    WaypointLineSolid = 1,
    WaypointLineDash = 2,
    WaypointLineDot = 3,
    WaypointLineDashDot = 4,
    WaypointLineDashDotDot = 5
};

enum enumObjectFOVStyle
{
    NoFOV = 0,
    BoundedFOV = 1,
    ShadedFOV = 2
};

enum enumGridStyle
{
    NoGrid = 0,
    HorizontalGrid = 1,
    VerticalGrid = 2,
    BothGrid = 3
};

enum enumCaptionOrientation
{
    HorizontalCaption = 0,
    VerticalLeftCaption = 1,
    VerticalRightCaption = 2
};

struct __declspec(uuid("d5f63c22-b3d3-11d0-b8f0-0020af344e0a"))
_DMMap : IDispatch
{
    //
    // Property data
    //

    __declspec(property(get=GetMapNorth,put=PutMapNorth))
    double MapNorth;
    __declspec(property(get=GetMapSouth,put=PutMapSouth))
    double MapSouth;
    __declspec(property(get=GetMapEast,put=PutMapEast))
    double MapEast;
    __declspec(property(get=GetMapWest,put=PutMapWest))
    double MapWest;
    __declspec(property(get=GetMappingMode,put=PutMappingMode))
    enum enumMoveMapMode MappingMode;
    __declspec(property(get=GetMaps,put=PutMaps))
    short Maps;
    __declspec(property(get=GetMapID,put=PutMapID))
    short MapID;
    __declspec(property(get=GetCaption,put=PutCaption))
    _bstr_t Caption;
    __declspec(property(get=GetCaptionColor,put=PutCaptionColor))
    OLE_COLOR CaptionColor;
    __declspec(property(get=GetCaptionID,put=PutCaptionID))
    short CaptionID;
    __declspec(property(get=GetCaptionFontID,put=PutCaptionFontID))
    short CaptionFontID;
    __declspec(property(get=GetCaptions,put=PutCaptions))
    short Captions;
    __declspec(property(get=GetCaptionX,put=PutCaptionX))
    double CaptionX;
    __declspec(property(get=GetCaptionY,put=PutCaptionY))
    double CaptionY;
    __declspec(property(get=GetBackPicture,put=PutBackPicture))
    PicturePtr BackPicture;
    __declspec(property(get=GetBevelInner,put=PutBevelInner))
    enum enumBevelStyle BevelInner;
    __declspec(property(get=GetBevelOuter,put=PutBevelOuter))
    enum enumBevelStyle BevelOuter;
    __declspec(property(get=GetBevelWidth,put=PutBevelWidth))
    short BevelWidth;
    __declspec(property(get=GetBorderWidth,put=PutBorderWidth))
    short BorderWidth;
    __declspec(property(get=GetFontName,put=PutFontName))
    _bstr_t FontName;
    __declspec(property(get=GetFontSize,put=PutFontSize))
    float FontSize;
    __declspec(property(get=GetFontID,put=PutFontID))
    short FontID;
    __declspec(property(get=GetFont,put=PutFont))
    FontPtr Font;
    __declspec(property(get=GetFonts,put=PutFonts))
    short Fonts;
    __declspec(property(get=GetFontBold,put=PutFontBold))
    VARIANT_BOOL FontBold;
    __declspec(property(get=GetFontItalic,put=PutFontItalic))
    VARIANT_BOOL FontItalic;
    __declspec(property(get=GetFontStrikethru,put=PutFontStrikethru))
    VARIANT_BOOL FontStrikethru;
    __declspec(property(get=GetFontUnderline,put=PutFontUnderline))
    VARIANT_BOOL FontUnderline;
    __declspec(property(get=GetAutoRedraw,put=PutAutoRedraw))
    VARIANT_BOOL AutoRedraw;
    __declspec(property(get=GetMapPicture,put=PutMapPicture))
    PicturePtr MapPicture;
    __declspec(property(get=GetBackColor,put=PutBackColor))
    OLE_COLOR BackColor;
    __declspec(property(get=GetViewCenterX,put=PutViewCenterX))
    double ViewCenterX;
    __declspec(property(get=GetViewCenterY,put=PutViewCenterY))
    double ViewCenterY;
    __declspec(property(get=GetViewRadius,put=PutViewRadius))
    double ViewRadius;
    __declspec(property(get=GetViews,put=PutViews))
    short Views;
    __declspec(property(get=GetViewID,put=PutViewID))
    short ViewID;
    __declspec(property(get=GetObjects,put=PutObjects))
    short Objects;
    __declspec(property(get=GetObjectID,put=PutObjectID))
    short ObjectID;
    __declspec(property(get=GetObjectSymbol,put=PutObjectSymbol))
    enum enumObjectSymbol ObjectSymbol;
    __declspec(property(get=GetObjectColor,put=PutObjectColor))
    OLE_COLOR ObjectColor;
    __declspec(property(get=GetObjectOrientation,put=PutObjectOrientation))
    double ObjectOrientation;
    __declspec(property(get=GetObjectShape,put=PutObjectShape))
    _bstr_t ObjectShape;
    __declspec(property(get=GetObjectCaption,put=PutObjectCaption))
    _bstr_t ObjectCaption;
    __declspec(property(get=GetObjectScale,put=PutObjectScale))
    double ObjectScale;
    __declspec(property(get=GetWaypoints,put=PutWaypoints))
    short Waypoints;
    __declspec(property(get=GetWaypointStyle,put=PutWaypointStyle))
    enum enumObjectStyle WaypointStyle;
    __declspec(property(get=GetWaypointID,put=PutWaypointID))
    short WaypointID;
    __declspec(property(get=GetWaypointCaption,put=PutWaypointCaption))
    _bstr_t WaypointCaption;
    __declspec(property(get=GetWaypointOrientation,put=PutWaypointOrientation))
    double WaypointOrientation;
    __declspec(property(get=GetWaypointScale,put=PutWaypointScale))
    double WaypointScale;
    __declspec(property(get=GetWaypointSymbol,put=PutWaypointSymbol))
    enum enumObjectSymbol WaypointSymbol;
    __declspec(property(get=GetWaypointX,put=PutWaypointX))
    double WaypointX;
    __declspec(property(get=GetWaypointY,put=PutWaypointY))
    double WaypointY;
    __declspec(property(get=GetWaypointColor,put=PutWaypointColor))
    OLE_COLOR WaypointColor;
    __declspec(property(get=GetObjectStyle,put=PutObjectStyle))
    enum enumObjectStyle ObjectStyle;
    __declspec(property(get=GetObjectX,put=PutObjectX))
    double ObjectX;
    __declspec(property(get=GetObjectY,put=PutObjectY))
    double ObjectY;
    __declspec(property(get=GetWaypointLineColor,put=PutWaypointLineColor))
    OLE_COLOR WaypointLineColor;
    __declspec(property(get=GetWaypointLineStyle,put=PutWaypointLineStyle))
    enum enumWaypointLineStyle WaypointLineStyle;
    __declspec(property(get=GetObjectBreadTrail,put=PutObjectBreadTrail))
    VARIANT_BOOL ObjectBreadTrail;
    __declspec(property(get=GetObjectHeading,put=PutObjectHeading))
    double ObjectHeading;
    __declspec(property(get=GetObjectHeadingLineColor,put=PutObjectHeadingLineColor))
    OLE_COLOR ObjectHeadingLineColor;
    __declspec(property(get=GetObjectHeadingLineRange,put=PutObjectHeadingLineRange))
    double ObjectHeadingLineRange;
    __declspec(property(get=GetObjectHeadingLineWidth,put=PutObjectHeadingLineWidth))
    short ObjectHeadingLineWidth;
    __declspec(property(get=GetObjectHeadingShow,put=PutObjectHeadingShow))
    VARIANT_BOOL ObjectHeadingShow;
    __declspec(property(get=GetObjectFOVStyle,put=PutObjectFOVStyle))
    enum enumObjectFOVStyle ObjectFOVStyle;
    __declspec(property(get=GetObjectFOV,put=PutObjectFOV))
    double ObjectFOV;
    __declspec(property(get=GetObjectFOVLineColor,put=PutObjectFOVLineColor))
    OLE_COLOR ObjectFOVLineColor;
    __declspec(property(get=GetObjectFOVLineRange,put=PutObjectFOVLineRange))
    double ObjectFOVLineRange;
    __declspec(property(get=GetObjectFOVLineWidth,put=PutObjectFOVLineWidth))
    short ObjectFOVLineWidth;
    __declspec(property(get=GetObjectPicture,put=PutObjectPicture))
    PicturePtr ObjectPicture;
    __declspec(property(get=GetGridStyle,put=PutGridStyle))
    enum enumGridStyle GridStyle;
    __declspec(property(get=GetGridXDelta,put=PutGridXDelta))
    double GridXDelta;
    __declspec(property(get=GetGridYDelta,put=PutGridYDelta))
    double GridYDelta;
    __declspec(property(get=GetGridColor,put=PutGridColor))
    OLE_COLOR GridColor;
    __declspec(property(get=GetViewObjectID,put=PutViewObjectID))
    short ViewObjectID;
    __declspec(property(get=GetWaypointLineWidth,put=PutWaypointLineWidth))
    short WaypointLineWidth;
    __declspec(property(get=GetGridLineWidth,put=PutGridLineWidth))
    short GridLineWidth;
    __declspec(property(get=GetGridLineStyle,put=PutGridLineStyle))
    enum enumLineStyle GridLineStyle;
    __declspec(property(get=GetGridRefY,put=PutGridRefY))
    double GridRefY;
    __declspec(property(get=GetGridRefX,put=PutGridRefX))
    double GridRefX;
    __declspec(property(get=GetObjectZ,put=PutObjectZ))
    double ObjectZ;
    __declspec(property(get=GetWaypointZ,put=PutWaypointZ))
    double WaypointZ;
    __declspec(property(get=GetWaypointShape,put=PutWaypointShape))
    _bstr_t WaypointShape;
    __declspec(property(get=GetWaypointPicture,put=PutWaypointPicture))
    PicturePtr WaypointPicture;
    __declspec(property(get=GetZoomEnabled,put=PutZoomEnabled))
    VARIANT_BOOL ZoomEnabled;
    __declspec(property(get=GetPanEnabled,put=PutPanEnabled))
    VARIANT_BOOL PanEnabled;
    __declspec(property(get=GetCaptionOrientation,put=PutCaptionOrientation))
    enum enumCaptionOrientation CaptionOrientation;
    __declspec(property(get=GetOutline,put=PutOutline))
    VARIANT_BOOL Outline;
    __declspec(property(get=GetOutlineTitle,put=PutOutlineTitle))
    _bstr_t OutlineTitle;
    __declspec(property(get=GetOutlineColor,put=PutOutlineColor))
    OLE_COLOR OutlineColor;
    __declspec(property(get=GetOutlineWidth,put=PutOutlineWidth))
    short OutlineWidth;
    __declspec(property(get=GetOutlineAlign,put=PutOutlineAlign))
    short OutlineAlign;
    __declspec(property(get=GetEnabled,put=PutEnabled))
    VARIANT_BOOL Enabled;
    __declspec(property(get=GetSingleBuffer,put=PutSingleBuffer))
    VARIANT_BOOL SingleBuffer;
    __declspec(property(get=GetFocusOutline,put=PutFocusOutline))
    VARIANT_BOOL FocusOutline;
    __declspec(property(get=GetConfiguration,put=PutConfiguration))
    _bstr_t Configuration;

    //
    // Wrapper methods for error-handling
    //

    // Methods:
    HRESULT Redraw ( );
    HRESULT RedrawStatic ( );
    HRESULT ShowPropertyPage ( );
    HRESULT SetWaypointData (
        const _variant_t & array );
    HRESULT SetPositionData (
        short ObjectID,
        double X,
        double Y,
        double Z );
    HRESULT AboutBox ( );

    // Properties:
    double GetMapNorth ( );
    void PutMapNorth ( double _val );
    double GetMapSouth ( );
    void PutMapSouth ( double _val );
    double GetMapEast ( );
    void PutMapEast ( double _val );
    double GetMapWest ( );
    void PutMapWest ( double _val );
    enum enumMoveMapMode GetMappingMode ( );
    void PutMappingMode ( enum enumMoveMapMode _val );
    short GetMaps ( );
    void PutMaps ( short _val );
    short GetMapID ( );
    void PutMapID ( short _val );
    _bstr_t GetCaption ( );
    void PutCaption ( _bstr_t _val );
    OLE_COLOR GetCaptionColor ( );
    void PutCaptionColor ( OLE_COLOR _val );
    short GetCaptionID ( );
    void PutCaptionID ( short _val );
    short GetCaptionFontID ( );
    void PutCaptionFontID ( short _val );
    short GetCaptions ( );
    void PutCaptions ( short _val );
    double GetCaptionX ( );
    void PutCaptionX ( double _val );
    double GetCaptionY ( );
    void PutCaptionY ( double _val );
    PicturePtr GetBackPicture ( );
    void PutBackPicture ( struct Picture * _val );
    enum enumBevelStyle GetBevelInner ( );
    void PutBevelInner ( enum enumBevelStyle _val );
    enum enumBevelStyle GetBevelOuter ( );
    void PutBevelOuter ( enum enumBevelStyle _val );
    short GetBevelWidth ( );
    void PutBevelWidth ( short _val );
    short GetBorderWidth ( );
    void PutBorderWidth ( short _val );
    _bstr_t GetFontName ( );
    void PutFontName ( _bstr_t _val );
    float GetFontSize ( );
    void PutFontSize ( float _val );
    short GetFontID ( );
    void PutFontID ( short _val );
    FontPtr GetFont ( );
    void PutFont ( struct Font * _val );
    short GetFonts ( );
    void PutFonts ( short _val );
    VARIANT_BOOL GetFontBold ( );
    void PutFontBold ( VARIANT_BOOL _val );
    VARIANT_BOOL GetFontItalic ( );
    void PutFontItalic ( VARIANT_BOOL _val );
    VARIANT_BOOL GetFontStrikethru ( );
    void PutFontStrikethru ( VARIANT_BOOL _val );
    VARIANT_BOOL GetFontUnderline ( );
    void PutFontUnderline ( VARIANT_BOOL _val );
    VARIANT_BOOL GetAutoRedraw ( );
    void PutAutoRedraw ( VARIANT_BOOL _val );
    PicturePtr GetMapPicture ( );
    void PutMapPicture ( struct Picture * _val );
    OLE_COLOR GetBackColor ( );
    void PutBackColor ( OLE_COLOR _val );
    double GetViewCenterX ( );
    void PutViewCenterX ( double _val );
    double GetViewCenterY ( );
    void PutViewCenterY ( double _val );
    double GetViewRadius ( );
    void PutViewRadius ( double _val );
    short GetViews ( );
    void PutViews ( short _val );
    short GetViewID ( );
    void PutViewID ( short _val );
    short GetObjects ( );
    void PutObjects ( short _val );
    short GetObjectID ( );
    void PutObjectID ( short _val );
    enum enumObjectSymbol GetObjectSymbol ( );
    void PutObjectSymbol ( enum enumObjectSymbol _val );
    OLE_COLOR GetObjectColor ( );
    void PutObjectColor ( OLE_COLOR _val );
    double GetObjectOrientation ( );
    void PutObjectOrientation ( double _val );
    _bstr_t GetObjectShape ( );
    void PutObjectShape ( _bstr_t _val );
    _bstr_t GetObjectCaption ( );
    void PutObjectCaption ( _bstr_t _val );
    double GetObjectScale ( );
    void PutObjectScale ( double _val );
    short GetWaypoints ( );
    void PutWaypoints ( short _val );
    enum enumObjectStyle GetWaypointStyle ( );
    void PutWaypointStyle ( enum enumObjectStyle _val );
    short GetWaypointID ( );
    void PutWaypointID ( short _val );
    _bstr_t GetWaypointCaption ( );
    void PutWaypointCaption ( _bstr_t _val );
    double GetWaypointOrientation ( );
    void PutWaypointOrientation ( double _val );
    double GetWaypointScale ( );
    void PutWaypointScale ( double _val );
    enum enumObjectSymbol GetWaypointSymbol ( );
    void PutWaypointSymbol ( enum enumObjectSymbol _val );
    double GetWaypointX ( );
    void PutWaypointX ( double _val );
    double GetWaypointY ( );
    void PutWaypointY ( double _val );
    OLE_COLOR GetWaypointColor ( );
    void PutWaypointColor ( OLE_COLOR _val );
    enum enumObjectStyle GetObjectStyle ( );
    void PutObjectStyle ( enum enumObjectStyle _val );
    double GetObjectX ( );
    void PutObjectX ( double _val );
    double GetObjectY ( );
    void PutObjectY ( double _val );
    OLE_COLOR GetWaypointLineColor ( );
    void PutWaypointLineColor ( OLE_COLOR _val );
    enum enumWaypointLineStyle GetWaypointLineStyle ( );
    void PutWaypointLineStyle ( enum enumWaypointLineStyle _val );
    VARIANT_BOOL GetObjectBreadTrail ( );
    void PutObjectBreadTrail ( VARIANT_BOOL _val );
    double GetObjectHeading ( );
    void PutObjectHeading ( double _val );
    OLE_COLOR GetObjectHeadingLineColor ( );
    void PutObjectHeadingLineColor ( OLE_COLOR _val );
    double GetObjectHeadingLineRange ( );
    void PutObjectHeadingLineRange ( double _val );
    short GetObjectHeadingLineWidth ( );
    void PutObjectHeadingLineWidth ( short _val );
    VARIANT_BOOL GetObjectHeadingShow ( );
    void PutObjectHeadingShow ( VARIANT_BOOL _val );
    enum enumObjectFOVStyle GetObjectFOVStyle ( );
    void PutObjectFOVStyle ( enum enumObjectFOVStyle _val );
    double GetObjectFOV ( );
    void PutObjectFOV ( double _val );
    OLE_COLOR GetObjectFOVLineColor ( );
    void PutObjectFOVLineColor ( OLE_COLOR _val );
    double GetObjectFOVLineRange ( );
    void PutObjectFOVLineRange ( double _val );
    short GetObjectFOVLineWidth ( );
    void PutObjectFOVLineWidth ( short _val );
    PicturePtr GetObjectPicture ( );
    void PutObjectPicture ( struct Picture * _val );
    enum enumGridStyle GetGridStyle ( );
    void PutGridStyle ( enum enumGridStyle _val );
    double GetGridXDelta ( );
    void PutGridXDelta ( double _val );
    double GetGridYDelta ( );
    void PutGridYDelta ( double _val );
    OLE_COLOR GetGridColor ( );
    void PutGridColor ( OLE_COLOR _val );
    short GetViewObjectID ( );
    void PutViewObjectID ( short _val );
    short GetWaypointLineWidth ( );
    void PutWaypointLineWidth ( short _val );
    short GetGridLineWidth ( );
    void PutGridLineWidth ( short _val );
    enum enumLineStyle GetGridLineStyle ( );
    void PutGridLineStyle ( enum enumLineStyle _val );
    double GetGridRefY ( );
    void PutGridRefY ( double _val );
    double GetGridRefX ( );
    void PutGridRefX ( double _val );
    double GetObjectZ ( );
    void PutObjectZ ( double _val );
    double GetWaypointZ ( );
    void PutWaypointZ ( double _val );
    _bstr_t GetWaypointShape ( );
    void PutWaypointShape ( _bstr_t _val );
    PicturePtr GetWaypointPicture ( );
    void PutWaypointPicture ( struct Picture * _val );
    VARIANT_BOOL GetZoomEnabled ( );
    void PutZoomEnabled ( VARIANT_BOOL _val );
    VARIANT_BOOL GetPanEnabled ( );
    void PutPanEnabled ( VARIANT_BOOL _val );
    enum enumCaptionOrientation GetCaptionOrientation ( );
    void PutCaptionOrientation ( enum enumCaptionOrientation _val );
    VARIANT_BOOL GetOutline ( );
    void PutOutline ( VARIANT_BOOL _val );
    _bstr_t GetOutlineTitle ( );
    void PutOutlineTitle ( _bstr_t _val );
    OLE_COLOR GetOutlineColor ( );
    void PutOutlineColor ( OLE_COLOR _val );
    short GetOutlineWidth ( );
    void PutOutlineWidth ( short _val );
    short GetOutlineAlign ( );
    void PutOutlineAlign ( short _val );
    VARIANT_BOOL GetEnabled ( );
    void PutEnabled ( VARIANT_BOOL _val );
    VARIANT_BOOL GetSingleBuffer ( );
    void PutSingleBuffer ( VARIANT_BOOL _val );
    VARIANT_BOOL GetFocusOutline ( );
    void PutFocusOutline ( VARIANT_BOOL _val );
    _bstr_t GetConfiguration ( );
    void PutConfiguration ( _bstr_t _val );
};

struct __declspec(uuid("d5f63c23-b3d3-11d0-b8f0-0020af344e0a"))
_DMMapEvents : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    // Methods:
    HRESULT MovePosition (
        double X,
        double Y );
    HRESULT Click ( );
    HRESULT DblClick ( );
    HRESULT KeyDown (
        short * KeyCode,
        short Shift );
    HRESULT KeyPress (
        short * KeyAscii );
    HRESULT KeyUp (
        short * KeyCode,
        short Shift );
    HRESULT MouseDown (
        short Button,
        short Shift,
        OLE_XPOS_PIXELS X,
        OLE_YPOS_PIXELS Y );
    HRESULT MouseMove (
        short Button,
        short Shift,
        OLE_XPOS_PIXELS X,
        OLE_YPOS_PIXELS Y );
    HRESULT MouseUp (
        short Button,
        short Shift,
        OLE_XPOS_PIXELS X,
        OLE_YPOS_PIXELS Y );
    HRESULT ClickPosition (
        short ObjectID,
        double X,
        double Y );
};

struct __declspec(uuid("d5f63c24-b3d3-11d0-b8f0-0020af344e0a"))
MMap;
    // [ default ] dispinterface _DMMap
    // [ default, source ] dispinterface _DMMapEvents

//
// Named GUID constants initializations
//

extern "C" const GUID __declspec(selectany) LIBID_MMAPLib =
    {0xd5f63c21,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) DIID__DMMap =
    {0xd5f63c22,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) DIID__DMMapEvents =
    {0xd5f63c23,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) CLSID_MMap =
    {0xd5f63c24,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};

//
// Wrapper method implementations
//

#include "MMap.tli"

} // namespace MMAPLib

#pragma pack(pop)





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

/************************************************/
This is my image.cpp file

/************************************************/


//
#import "c:\WINNT\system32\MMap.ocx" \
			named_guids LIBID_MMAPLib,DIID_DMMap,DIID_DMMapEvents,CLSID_MMap \
			no_namespace MMAPLib

#include "stdafx.h"
#include "image.h"
#include <windows.h>
#include <winerror.h>
#include <stdio.h>
#include <iostream>
#include <assert.h>
#include <cassert>


void  main()
{
	

	CoInitialize( NULL);
		
		_DMMap* pMP = 0;
		HRESULT hr  = CoCreateInstance( __uuidof(MMap),//class identifier of the object
						     		    NULL,
					                    CLSCTX_ALL,// context for running executable code
					                    DIID__DMMap,//reference to the identifier of the inerface
					                    reinterpret_cast <void**>(&pMP));//interface pointer requested in riid
		assert(SUCCEEDED(hr));		
		hr	= pMP->GetMapID();
		hr  = pMP->GetMapNorth();
		hr	= pMP->GetMapEast();
		hr	= pMP->GetMapWest();
		hr	= pMP->GetMapSouth();
		assert(SUCCEEDED(hr));
		printf("reading the activeX control file ");
		pMP ->Release();
		
	CoUninitialize();	

}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


/******************************************************/
This is my image.h file

/*********************************************************/

#include <windows.h>
#include <iostream.h>



class  _DMMap 
{
	public:
		_DMMap();
		double GetMapID();
		void PutMapID(double);
		double GetMapEast();
		void PutMapEast(double);
		double GetMapWest();
		void PutMapWest(double);
		double GetMapNorth();
		void PutMapNorth(double);
		double GetMapSouth();
		void PutMapSouth(double);
		double Release();
		~_DMMap();

};
_DMMap DIID__DMMap;

class _DMMapEvents
{
	public:
		 HRESULT MovePosition ( double X,double Y );
		 HRESULT Click ( );
		 HRESULT DblClick ( );

};
_DMMapEvents DIID__DMMapEvents;

/////////////////////////////////////////////////////////////////
These three are files which i am using now.

Thanks in Advance,
swetha.

the generated header file that you posted contains

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

namespace MMAPLib {
// ...
} // namespace MMAPLib

and your #import is

#import "c:\WINNT\system32\MMap.ocx" \
named_guids LIBID_MMAPLib,DIID_DMMap,DIID_DMMapEvents,CLSID_MMap \
no_namespace MMAPLib

these are not consistent with each other (no_namespace => do not generate a namespace)

you need to recompile your code after making any modification to the #import to get the
newly generated header file. i suspect you have not done that.

if (and only if) your header generates definitions inside namespace MMAPLib { add a using namespace MMAPLib; directive right after the #import
then either of these should work

CoCreateInstance(     CLSID_MMap,
                       0,
                       CLSCTX_ALL,
                       DIID__DMMap,
                       reinterpret_cast <void**>(&pMP) );

or

CoCreateInstance(     __uuidof( MMap ),
                       0,
                       CLSCTX_ALL,
                       __uuidof( _DMMap ),
                       reinterpret_cast <void**>(&pMP) );

How u told in previous mail like that only I did modifications in my code.Again same problem is coming.Now , I am sending the mmap.cpp,mmap.h and also mmap.tlh.

If you dont mind can you tell what changes again need to do.

/************************mmap.tlh file***************************/

#pragma once
#pragma pack(push, 8)

#include <comdef.h>

namespace MMAPLib {

//
// Forward references and typedefs
//

struct __declspec(uuid("d5f63c22-b3d3-11d0-b8f0-0020af344e0a"))
/* dispinterface */ _DMMap;
struct __declspec(uuid("d5f63c23-b3d3-11d0-b8f0-0020af344e0a"))
/* dispinterface */ _DMMapEvents;
struct /* coclass */ MMap;
//
// Smart pointer typedef declarations
//

_COM_SMARTPTR_TYPEDEF(_DMMap, __uuidof(IDispatch));
_COM_SMARTPTR_TYPEDEF(_DMMapEvents, __uuidof(IDispatch));

//
// Type library items
//

struct __declspec(uuid("d5f63c22-b3d3-11d0-b8f0-0020af344e0a"))
_DMMap : IDispatch
{
    //
    // Property data
    //

    __declspec(property(get=GetMapNorth,put=PutMapNorth))
    double MapNorth;
    __declspec(property(get=GetMapSouth,put=PutMapSouth))
    double MapSouth;
..........................
....
..
..
..
};

struct __declspec(uuid("d5f63c23-b3d3-11d0-b8f0-0020af344e0a"))
_DMMapEvents : IDispatch
{
    //
    // Wrapper methods for error-handling
    //

    // Methods:
    HRESULT MovePosition (
        double X,
        double Y );
    HRESULT Click ( );
    HRESULT DblClick ( );
	....
	.....
	.....
};

struct __declspec(uuid("d5f63c24-b3d3-11d0-b8f0-0020af344e0a"))
MMap;
    // [ default ] dispinterface _DMMap
    // [ default, source ] dispinterface _DMMapEvents

//
// Named GUID constants initializations
//

extern "C" const GUID __declspec(selectany) LIBID_MMAPLib =
    {0xd5f63c21,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) DIID__DMMap =
    {0xd5f63c22,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) DIID__DMMapEvents =
    {0xd5f63c23,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};
extern "C" const GUID __declspec(selectany) CLSID_MMap =
    {0xd5f63c24,0xb3d3,0x11d0,{0xb8,0xf0,0x00,0x20,0xaf,0x34,0x4e,0x0a}};

//
// Wrapper method implementations
//

#include "c:\mmap-nov-16\mmap\debug\MMap.tli"

} // namespace MMAPLib

#pragma pack(pop)

/******************************end the mmap.tlh file***************************/

/*****************************mmap.cpp*************************************/

#import "c:\WINNT\system32\MMap.ocx" \
				named_guids LIBID_MMAPLib,CLSID_MMap,DIID__DMMap,DIID__DMMapEvents 


using namespace MMAPLib;

#include "stdafx.h"
#include <cassert>
#include<windows.h>
#include "mmap.h"


void main()
{
	CoInitialize( NULL );
	_DMMap* pMap = 0;
	
		HRESULT hr = CoCreateInstance(CLSID_MMap,
					      0,
					      CLSCTX_ALL,
					      DIID__DMMap,
					      reinterpret_cast <void **>(&pMap));

		assert(SUCCEEDED(hr));
		hr = pMap->GetMapID();
		assert(SUCCEEDED(hr));
		pMap ->Release();
	CoUninitialize();
	
}

/**********************end the mmap.cpp file**********************************/

/********************************mmap.h***************************/

class _DMMap
{
	public:
		double GetMapID();
		void PutMapID(double);
		double Release();
};
//_DMMap DIID__DMMap;


/**********************end the mmap.h file******************************/

Now also again I am getting error is that 'CLSID_MMap' : undeclared identifier
'DIID__DMMap' : undeclared identifier


I have one doubt that is it necessary to do changes in mmap.h file also?
Please tell me the sollution what I did wrong.Hope you will give the reply.


Thanks & Regards,
swetha

looks like you are compiling with the /Yu"stdafx.h" compiler option. new projects in Visual C++ set this option by default to increase compilation speed. (to change the option, use the Project.Settings.C++.Precompiled Headers dialog.)

the Visual C++ Programmer's Guide explains the behavior you see:

"The compiler treats all code occurring before the .h file as precompiled. It skips to just beyond the #include directive associated with the .h file, uses the code contained in the .pch file, and then compiles all code after filename.."

http://msdn2.microsoft.com/en-us/library/z0atkd6c(VS.71).aspx
this means, everything in your code file before the #include "stdafx.h" line is completely ignored, because the compiler assumes that the necessary information is in your precompiled header.

you can fix the problem by one of these ways
a. move the #import directive and the using namespace directive after the other #include statements. in particular #include "stdafx.h"
b. move the #import directive and the using namespace directive into stdafx.h
c. turn off precompiled headers option (set it to not using precompiled headers)

then clean (or delete the .pch file) and rebuild you project.

Hi vijayan,

Thank you very much for ur prompt replies.

I tried all your suggestions. However, I am getting syntax errors in mmap.tlh file while reading it like the following

error C2146: syntax error : missing ';' before identifier 'BackPicture'
error C2501: 'PicturePtr' : missing storage-class or type specifiers
etc...

I am including #import and namespace in image.cpp file. Similarly, do I need to include anything in image.h file? Whether I include definition of _DMMap(dispinterface in mmap.tlh) as class in image.h file or doesn't inculde image.h in cpp file, it didn't make any difference to the result.

MDSN help suggested to the following. However, I am not sure on how to do it and whether to do it or not.

"The path specified by the /I (additional include directories) compiler option, except it the compiler is searching for a type library that was referenced from another type library with the no_registry attribute"
http://msdn2.microsoft.com/en-us/library/8etzzkb6(vs.80).aspx

Thanks a lot for ur prompt responses and listening to my queries. I am new to this and there are no expertize in this small company where I am working.

Regards,
Swetha

first do this. create a small project which contains only a main.cpp as follows.

#include <cassert>
#include<windows.h>
#import "c:\WINNT\system32\MMap.ocx" named_guids 
using namespace MMAPLib;

void main()
{
   CoInitialize( 0 );
   _DMMap* pMap = 0;

  HRESULT hr = CoCreateInstance(CLSID_MMap, 0, CLSCTX_ALL,
                DIID__DMMap,reinterpret_cast <void**>(&pMap));
  assert(SUCCEEDED(hr));
  pMap->Release();
  CoUninitialize();
}

does this compile and link without errors?
if no, post the complete error message(s) generated by the compiler/linker and the complete .tlh file that was generated.
if yes, run the program. does it run without errors?

Hi vijayan,

How u told like that only i was doing from starting onwards.But the errors are coming.
I think I already sent MMap.tlh file in previous mails.So,now I am sending while compiling which errors I am getting.


/********************ERRORS**************************/

C:\mmap-nov-16\Radar\Radar.cpp(8) : error C2017: illegal escape sequence
c:\mmap-nov-16\radar\debug\mmap.tlh(148) : error C2146: syntax error : missing ';' before identifier 'BackPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(148) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(148) : error C2501: 'BackPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(164) : error C2146: syntax error : missing ';' before identifier 'Font'
c:\mmap-nov-16\radar\debug\mmap.tlh(164) : error C2501: 'FontPtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(164) : error C2501: 'Font' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(178) : error C2146: syntax error : missing ';' before identifier 'MapPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(178) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(178) : error C2501: 'MapPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(260) : error C2146: syntax error : missing ';' before identifier 'ObjectPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(260) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(260) : error C2501: 'ObjectPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(288) : error C2146: syntax error : missing ';' before identifier 'WaypointPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(288) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(288) : error C2501: 'WaypointPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(360) : error C2146: syntax error : missing ';' before identifier 'GetBackPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(360) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(376) : error C2146: syntax error : missing ';' before identifier 'GetFont'
c:\mmap-nov-16\radar\debug\mmap.tlh(376) : error C2501: 'FontPtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(390) : error C2146: syntax error : missing ';' before identifier 'GetMapPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(390) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(472) : error C2146: syntax error : missing ';' before identifier 'GetObjectPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(472) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(500) : error C2146: syntax error : missing ';' before identifier 'GetWaypointPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(500) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tli(180) : error C2143: syntax error : missing ';' before 'tag::id'
c:\mmap-nov-16\radar\debug\mmap.tli(180) : error C2433: 'PicturePtr' : 'inline' not permitted on data declarations
c:\mmap-nov-16\radar\debug\mmap.tli(180) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tli(180) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\Radar.sbr': No such file or directory
Error executing bscmake.exe.

Radar.exe - 31 error(s), 0 warning(s)


/*****************************************End the errors*********************************/


One more thing is that if I am trying with other *.ocx file, it is compiling with out any errors.But if Iam trying with mmap.ocx file only these errors are getting.
What may be the reason?

Please give reply as early as possible.
Thanks And Regards,
swetha.

> C:\mmap-nov-16\Radar\Radar.cpp(8) : error C2017: illegal escape sequence
this is the first error reported by the compiler. what is this Radar.cpp file? and what does it contain? in paticular what does line 8 look like?
i repeat: create a small project which contains only a main.cpp. with only these 16 lines of code

#include <cassert>
#include<windows.h>
#import "c:\WINNT\system32\MMap.ocx" named_guids 
using namespace MMAPLib;

void main()
{
   CoInitialize( 0 );
   _DMMap* pMap = 0;

  HRESULT hr = CoCreateInstance(CLSID_MMap, 0, CLSCTX_ALL,
                DIID__DMMap,reinterpret_cast <void**>(&pMap));
  assert(SUCCEEDED(hr));
  pMap->Release();
  CoUninitialize();
}

and post the results.
also rename mmap.ocx as mmap.ocx.txt and upload that too. (click on the 'Manage Attachments' button)

radar.cpp is new/modified file name of earlier image.cpp. Both of them are same. Very sorry for the confusion. When I keep attribute named_guids, I am getting the 1st error. And, if I remove it, I am not getting it.

I am getting the following errors in mmap.tlh with the code what you mentioned. I am getting the same errors even if I keep empty main function with #import.

I sent the OCX file to your gmail ID as it's confidential file.

c:\mmap-nov-16\radar\debug\mmap.tlh(148) : error C2146: syntax error : missing ';' before identifier 'BackPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(148) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(148) : error C2501: 'BackPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(164) : error C2146: syntax error : missing ';' before identifier 'Font'
c:\mmap-nov-16\radar\debug\mmap.tlh(164) : error C2501: 'FontPtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(164) : error C2501: 'Font' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(178) : error C2146: syntax error : missing ';' before identifier 'MapPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(178) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(178) : error C2501: 'MapPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(260) : error C2146: syntax error : missing ';' before identifier 'ObjectPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(260) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(260) : error C2501: 'ObjectPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(288) : error C2146: syntax error : missing ';' before identifier 'WaypointPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(288) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(288) : error C2501: 'WaypointPicture' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(360) : error C2146: syntax error : missing ';' before identifier 'GetBackPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(360) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(376) : error C2146: syntax error : missing ';' before identifier 'GetFont'
c:\mmap-nov-16\radar\debug\mmap.tlh(376) : error C2501: 'FontPtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(390) : error C2146: syntax error : missing ';' before identifier 'GetMapPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(390) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(472) : error C2146: syntax error : missing ';' before identifier 'GetObjectPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(472) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tlh(500) : error C2146: syntax error : missing ';' before identifier 'GetWaypointPicture'
c:\mmap-nov-16\radar\debug\mmap.tlh(500) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tli(180) : error C2143: syntax error : missing ';' before 'tag::id'
c:\mmap-nov-16\radar\debug\mmap.tli(180) : error C2433: 'PicturePtr' : 'inline' not permitted on data declarations
c:\mmap-nov-16\radar\debug\mmap.tli(180) : error C2501: 'PicturePtr' : missing storage-class or type specifiers
c:\mmap-nov-16\radar\debug\mmap.tli(180) : fatal error C1004: unexpected end of file found
Error executing cl.exe.
Creating browse info file...
BSCMAKE: error BK1506 : cannot open file '.\Debug\Radar.sbr': No such file or directory
Error executing bscmake.exe.

there is nothing wrong with the mmap.ocx file.
i have been able to #import the file and build it without errors.
note: i am NOT using precompiled headers.

however, it appears that the file is licensed, and so i get a
run-time error 'Class is not licensed for use' when i try to instantiate it.
i suppose that you have the license key with you, and you would be
able to instantiate it.

#include <iostream>
#include <windows.h>

#import "C:\\cygwin\\home\\projects\\ocx_read\\mmap_read\\MMap.ocx"  \
  no_namespace no_smart_pointers raw_native_types named_guids

int main()
{
  CoInitialize(0) ;
  {
      _DMMap* pmmap = 0 ;
      HRESULT hr = CoCreateInstance( CLSID_MMap, 0, 
                       CLSCTX_ALL,  DIID__DMMap,
                       reinterpret_cast<void**>(&pmmap) ) ;
      if( SUCCEEDED(hr) )
      {
         std::cout << "succeeded in creating an instance "
                     "of mmap\n" ;
         pmmap->Release() ;
      }
      else
      {
         char strerror[128] ;
         FormatMessageA( FORMAT_MESSAGE_FROM_SYSTEM,
                  0, hr, 0, strerror, sizeof(strerror), 0 ) ;
         std::cout << "error: " << strerror ;
      }
  }
  CoUninitialize() ;
}
/***
output:
error: Class is not licensed for use
*/

Hi Vijayan,

I got licensed version of the file and able to compile it successfuly. While executing it, program is quitting with "Abnormal program termination". I debugged it and it's terminating at the ollowing line/function call. Program entered into the function definition in .tlh header file and then terminated immediately.

pMP->GetMapID();

If I don't call above function in the code, it's working fine without doing anything. Also, if I keep alone pMP ->Release(); function call at the end, it's still working fine without doing anything.

Am I missing something in above function call? Or do I need to call the function differently?

Thanks a lot for ur help,
Regards,
Swetha

> pMP->GetMapID();
> Am I missing something in above function call? Or do I need to call the function differently?
no. you would have got a compile time error otherwise.

> While executing it, program is quitting with "Abnormal program termination".
try this

try
{
  pMP->GetMapID() ;
}
catch( const _com_error& ce )
{
  std::wcout << L"com error: " << ce.Description() << std::endl ;
}
catch( ... )
{
  std::cout << "some other error" << std::endl ;
}

if the error is a 'com error', look at what the error description is.

if the error is 'some other error', run the program in the visual studio debugger.
it will tell you what is the cause of the abnormal termination.
most likely, it would be an access violation.
the probable reason then is that you are accessing the object after a call to
either Release() or CoUninitialize().

Hi Vijayan,

I tried what ever you mentioned. I am getting access violation and memory could not be read errors while debugging.

Am I missing or doing something wrong in the following two lines?

CoInitialize( NULL);
	{	
		_DMMap* pMP = 0;

Thanks,
Swetha

Hi vijayan,

I tried with try and catch method like

try
   {
      pMp->GetMapID();
    }
    catch(const _com_error ce)
    {
      cout<<"com error:"<<ce.ErrorMessage()<<endl;
     }

Then that error I am getting like "CATASTROPHIC ERROR" :-(

Instead of ce.ErrorMessage() if I give ce.Description() it is not printing any error description.Simply that error is like application error-memory could not be read

Please what to do to come out from this problem.

Thakns And Regards,
swetha

> Then that error I am getting like "CATASTROPHIC ERROR" :-(

this (along with the fact that CoCreateInstance and Release succeed)
usually means that the activex control is one that requires hosting.
for this you must provide an ActiveX control container.
You can use ATL for this purpose; this is a lot simpler
than implementing an ActiveX Control container from scratch.

see this msdn article on how to do this:
http://msdn2.microsoft.com/en-us/library/bb262335.aspx

as the control that you are trying to use not only requires
hosting, but also a license, you would need to use the CAxWindow2T
class instead of the CAxWindow used in the example. and use
CAxWindow2T::CreateControlLic
see http://msdn2.microsoft.com/en-us/library/328984a2(VS.80).aspx
and http://msdn2.microsoft.com/en-us/library/bycs8wcd(VS.80).aspx

with your current level of exposure to com, this is going to be a daunting task.
probably, the easiest way for you to right now would be to copy this
msdn sample Hosting ActiveX Controls Using ATL AXHost
http://msdn2.microsoft.com/en-us/library/9d0714y1(VS.80).aspx
into a file and build and test it. then chop off the parts you do not need,
modify the parts that you need (choose one of the USE_METHOD == n options
as the one you want to use and change the control/interface to your activex control).
as you want a console application with no windows, also change this (right at the end)

int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int nShowCmd)
{
   return _AtlModule.WinMain(nShowCmd);
}

to

int main()
{
   return _AtlModule.WinMain( SW_HIDE ); // window is invisible
   // so the control will not be visible
}

and choose 'win32 console application' as your project type.

Hi vijayan,

The links which u sent are referring to MFC code and not C++.Actually I want to read that file using C++ and with out using MFC.ActiveXcontrol code also should be in c++.
Just I got the book "Essential Of COM"which you refered.

You have basically two choices: either MFC or ATL, per this article. Read the whole article for a more in-depth discussion.

C++ is a great language for writing performance-critical ActiveX components. With C++, you can create small, fast objects, if you take your time and are careful. MFC can get you up and running fast, but you may take a one-time download hit using its run-time library. ATL might be the answer for you if you want to create compact and fast ActiveX controls. ATL 2.0, which provides all of the updated ActiveX support, is currently in beta release and will soon be available on the Web

Note the article was writen in 1996 so that last sentence is outdated.

> The links which u sent are referring to MFC code and not C++.
the links refer to ATL and not MFC. and with the change from WinMain to main, what you would have is a console application that uses the ATL library.

it is easy to access an activex control from C++ without using ATL or MFC (which are C++ libraries). you access it like any other com object. that is what you had been attempting to do. for example, this small piece of code http://msdn2.microsoft.com/en-us/library/bb249582.aspx will work. and it is quite easy to do away with the ATL wrapper for BSTR and the com smart pointer.

however, it is an entirely different matter to host a control in a control container. and that is what you need to do; the control that you are trying to use seems to require being hosted. this link http://msdn2.microsoft.com/en-us/library/aa768175.aspx#Container_Requirements gives the requirements for a control container. and without library support, implementing all this is going to be a huge and difficult task.

#include "stdafx.h"

#import "C:\Program Files\GMS\Bin\MMap.ocx"  no_namespace \
		 raw_native_types named_guids 

#include "atlbase.h"
#include "atlwin.h"

int _tmain(int argc, _TCHAR* argv[])
{
	CoInitialize(NULL);
		HRESULT hr =S_OK;
		CComBSTR bstrmapid;
		CComPtr<_DMMap> pMap;
		hr = pMap.CoCreateInstance(__uuidof(MMap),0,CLSCTX_INPROC_SERVER);
		if(SUCCEEDED(hr))
		{
			MessageBox(NULL,pMap->GetMapID(),_T("map"),MB_OK);
			hr = pMap->GetMapID();

		}
		pMap.Release();
	CoUninitialize();
	return 0;
}




Again same error like "abnormal program termination".If i am tryinrg to debug the program,then getting error like
"unhandled exception in mmap.exe(KERNEL32.DLL):0XE06D7363:Microsoft C++ Exception".This error also looks like that previous error only.


inline short _DMMap::GetMapID ( ) {
    short _result;
    _com_dispatch_propget(this, 0x7, VT_I2, (void*)&_result);
    return _result;
}

This exception is coming after the compiler is going into that above function which is the definition of GetMapID.
I am using Microsoft visual C++ 6.0 compiler.Is it any problem with this compiler also?what to do vijayan?Please tell me the sollution for this problem.Is it possible to solve this one?

Thankyou very much for ur help,
swetha.

> I am using Microsoft visual C++ 6.0 compiler.Is it any problem with this compiler also? ... Is it possible to solve this one?

it would be a good idea to switch to a more modern compiler (eg. Visual Studio 2005 or Visual C++ Express 2005). but this particular problem is not because of the compiler. it seems that the activeX control that you want to use demands hosting. and if it is not hosted, fails requests to it. (you could verify this by trying to call the method in the activex control test container which ships with visual studio.) if that is the case, you need to write hosting code for the control. see post #24 for details.

Hi vijayan,

Instead of reading .ocx file using activeXcontrol container in C++ I am trying to read the bitmap image (which I got from screen shot while reading the .ocx file in MFC) and also I am planning to implement some properties.

Now I am able to read bitmap file and able to display that file.But I want to zoom the same image. Is it possible to zooming this bitmap image?

I think its not an good idea but just I am trying to do like this. Mean while I will also try to read some thing about activeXcontrol container and hosting it.

Thnka a lot for ur help.
swetha.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.