When MapInfo runs it registers itself with something called the running
object table (ROT). In VB the GetObject method works by finding MapInfo in
the ROT. In C++ you need to iterate over all the objects in the ROT until
you find one for MapInfo. The only drawback is that if you have two copies
of MapInfo running you can only get the object for one of them.

The follow code should point you in the right direction. I haven't tested
it, but there shouldn't be any major problems.

Hope this helps

Gavin

// Import the mapinfo type lib
#import "mapinfow.exe" named_guids raw_interfaces_only
rename_namespace("MapInfo")

CComPtr<MapInfo::IMapInfo> pMapInfo;
CComPtr<IRunningObjectTable> pROT;
if( SUCCEEDED( ::GetRunningObjectTable( 0, &pROT ) ) )
{
        CComPtr<IEnumMoniker> pEnumMon;
        if( SUCCEEDED( pROT->EnumRunning( &pEnumMon ) ) )
        {
                CComPtr<IMoniker> pMon;
                while( S_OK == pEnumMon->Next( 1L, &pMon, NULL ) )
                {
                        CComPtr<IUnknown> pUnk;
                        HRESULT hr;
                        hr = pROT->GetObject( pMon, &pUnk );
                        if( SUCCEEDED( hr ) )
                        {
                                hr = pUnk->QueryInterface( MapInfo::IID_IMapInfo,
reinterpret_cast<void**>( &pMapInfo ) );
                                if( SUCCEEDED( hr ) )
                                {
                                        break;
                                }
                        }
                }
        }
}

-----Original Message-----
From: Bamber, David (D) [mailto:[EMAIL PROTECTED]]
Sent: 23 September 2002 14:22
To: [EMAIL PROTECTED]
Subject: RE: MI-L calling mapbasic from C++


I don't really know much about C++, but in VB you can connect to a current
instance of MapInfo by using the 'Getobject' instead of the 'Createobject'
command.

e.g.

Set mapinfo = GetObject(, "MapInfo.Application")

mapinfo.do "Open Table ""Q:\file1\mapping2.TAB"" Interactive
mapinfo.do "Map From m_ml1_dcb_dur"

David

> -----Original Message-----
> From: Kenn Garroch [SMTP:[EMAIL PROTECTED]]
> Sent: Monday, September 23, 2002 9:48 AM
> To:   [EMAIL PROTECTED]
> Subject:      RE: MI-L calling mapbasic from C++
>
> I should say at the outset that I am not an expert on C++. All of my
> Mapinfo COM experience is from Visual FoxPro.
>
> However, you should be able to use something like
> createobject("Mapinfo.Application") to start Mapinfo as a COM object
> (depends on your flavour of C++ i.e. createobject returns the object. You
> can then use this object to execute MapBasic commands with DO
>
> e.g. if your object is called mm then mm.do('Print "Hi"') will execute
> Mapbasic's print command. mm.visible=true will bring up the Mapinfo
> application window. The problem I have found with all this is that
> createobject always starts a new instance of the application. It would be
> really useful to simply connect to the current instance - so I'm unable to
> help with the second part of your question.
>
> Regards
>
> Kenn
>
> > -----Original Message-----
> > From: Martin Tyberg [mailto:[EMAIL PROTECTED]]
> > Sent: 20 September 2002 18:49
> > To: [EMAIL PROTECTED]
> > Subject: MI-L calling mapbasic from C++
> >
> >
> >
> > Hi,
> >
> > Is it possible to call a MapBasic program function from
> > within a DLL. The
> > setup is the following. I have a DLL that exports a function that is
> > called by a MapBasic function. The DLL invokes a dialog that receives
> > input from the user. Based on the input, I would like to call
> > a MapBasic
> > function in my MapBasic program to update the mapinfo view. Is there
> > some way to achieve this?
> >
> > Also, is there some way to obtain the current instance of
> > MapInfo and pass
> > that instance to a DLL from MapBasic so that a DLL can be a client to
> > MapInfo during the execution of the DLL function call?
> >
> > Thanks.
> >
> > Martin
> >
> >
> > ---------------------------------------------------------------------
> > List hosting provided by Directions Magazine | www.directionsmag.com |
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > Message number: 3175
> >

---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 3197



---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 3198

Reply via email to