HOW TO

Create new instance of the MapObjects MapControl without the MO license using CoCreate

Last Published: April 25, 2020

Summary

** Internal Publish Only! This article may contain information that is not intended for external circulation. **

Instructions below contain a C++ code sample that shows how to programmatically create a new instance of the MapControl without the MO license using CoCreate.

Procedure



  1. Add the following code to stdafx.h. Note: the double quotes are included.

    Code:
    #import "c:\program files\common files\esri\mo2x.ocx" raw_interfaces_only no_implementation no_namespace

  2. The code snippet below shows how to create the new instance of the MapControl.

    Code:

    void COcxcreateDlg::OnButton1()
    {
    // Standard IClassFactory2 interface. Used to create instances
    // of objects which are licensed.
    IClassFactory2Ptr ipCF2;

    // Standard COM creation function. Used to obtain a class
    // factory for a particular object
    // (in this case, the map control i.e. Map.)
    HRESULT hr = ::CoGetClassObject(__uuidof(Map), CLSCTX_ALL,
    0,
    IID_IClassFactory2, (void**)&ipCF2);

    if (FAILED(hr))
    return;

    // The license key.
    _bstr_t bKey (L"Copyright (c) 1999 ESRI, Inc.");

    // Create an instance of the Map control, request IOleControl
    //interface initially.
    IOleControlPtr ipOleControl;
    ipCF2->CreateInstanceLic(0, 0, IID_IOleControl, bKey,
    (void**)&ipOleControl);

    // IOleControl is used to add controls into their
    // containing frame application.
    }

Article ID:000006264

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic