I don't know if this will be usefull or not to anyone but I couldn't
find any good documentation on  integrated mapping with MapInfo from C++
that doesn't use MFC. So I wrote up a small wrapper function that returns a
pointer to an instance of MapInfo for doing integrated mapping or just plain
automation. I just needed to pack a bunch of tables but I wanted more
control over some other stuff than MapBasic gives. I didn't actually want to
do any integrated mapping just some batch functions. Anyway here is the
function which I put in a header called "MapInfoPtr.h" and an example of
using it from a quick console app just to make sure it works (created with
VC++6 | tested on Windows 2000 ):

///////header file/////////////////////
#ifndef MAPINFO_PTR_INCLUDED
#define MAPINFO_PTR_INCLUDED
#include "windows.h"
#include <atlbase.h>
#include <atlconv.h>
#include <comutil.h>
#import "C:\\Program Files\\MapInfo\\Professional\\MAPINFOW.TLB"
raw_native_types
using namespace MapInfo;


DMapInfo *GetMapInfoPtr(){
                OleInitialize(NULL);
                CLSID      clsid;
                char *pszApp = "MapInfo.Application";
#if WIN32
                USES_CONVERSION;
                ::CLSIDFromProgID(A2W(pszApp), &clsid);
#else
                ::CLSIDFromProgID(pszApp, &clsid);
#endif
                IUnknown *pUnknown=0;
        //CLSCTX_ALL
                HRESULT
hret=CoCreateInstance(clsid,NULL,CLSCTX_ALL,IID_IUnknown,reinterpret_cast<vo
id**>(&pUnknown));
                switch(hret){
                        case S_OK:
                                break;
                        case REGDB_E_CLASSNOTREG:
                                return 0;
                                break;
                        case CLASS_E_NOAGGREGATION:
                                return 0;
                                break;
                        case E_NOINTERFACE:
                                return 0;
                                break;
                }
                DMapInfo *m_MapInfo;
                //Query the upper interface for the inner DMapInfo Interface
        
hret=pUnknown->QueryInterface(__uuidof(DMapInfo),reinterpret_cast<void**>(&m
_MapInfo));
                //Release the unknown as soon as we are done with it
                pUnknown->Release();
                if (FAILED(hret))
                {
                        return 0;
                }
        return m_MapInfo;
}



#endif
/////// end header file/////////////////////

//////////main console ////////////////////

#include "stdafx.h"
#include "MapInfoPtr.h"
#include <iostream>

int main(int argc, char* argv[])
{
        DMapInfo *dMi = GetMapInfoPtr();
        if(dMi){
                char* szName =
_com_util::ConvertBSTRToString(dMi->GetFullName());
                std::cout << szName << "\n";
                dMi->Release();
        }
        OleUninitialize();
        system("PAUSE");
        return 0;
}

////////////////////////////////////////


I hope that will help anyone still using COM out there as we still do here
where I work.

Andy


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

Reply via email to