Select to view content in your preferred language

Run C++ DLL in ArcMap 10.3

3861
2
Jump to solution
07-22-2015 09:38 AM
FloD
by
Deactivated User

Hello everyone,

I've migrated a VB script that uses ArcObjects to a C++ Win32 DLL (using Visual Studio 2013).

And now I would like to test my DLL by launching it from my ArcMap 10.3 installation.

The problem is that when I try to add it through "Customize -> Customize Mode -> Add from file" it does not succeed and raise the following message: "Can't load type library from specified file", even when I run ArcMap as Administrator.

The same way, the "ESRIRegAsm.exe" I tried to use in command line also refuses to register my DLL.

I've made research but I could not find any answer to make it work.

But maybe I am not doing this the right way. Do I need to implement a COM component to add my DLL to ArcMap ?

Anything that would help is welcome.

Thanks in advance.

0 Kudos
1 Solution

Accepted Solutions
SamiEria
Deactivated User


Please follow this walkthrough:

Creating a Simple Command

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Walkthrough_Creating_a_simple_co...

Because this walkthrough was written for a previous version of ArcGIS (8.x and 9.x), make the following changes to update it for the 10.x versions of ArcObjects.

1. Ignore the part of the tutorial about the two attributes below:

  • [coclass, default(IZoomIn),

                threading(apartment),

               vi_progid("Walkthrough1VC8.ZoomIn"),

               progid("Walkthrough1VC8.ZoomIn.1"), version(1.0),

               uuid("C77B6C59-2A8A-4E0C-9877-5FEA1F4C02B4"), helpstring("ZoomIn Class")

        ]class ATL_NO_VTABLE CZoomIn: public IZoomIn

  • [object, uuid("297E96B4-D481-47C3-AEEB-CD526016DFDA"),

                    helpstring(

                     "IZoomIn Interface"),

                      pointer_default(unique)

          ]

Adding these attributes to your code will cause a compile error. Do not add these two attributes to your ZoomIn.h file.

2. Make sure to add the following "Additional Include" paths:

  • C:\Program Files (x86)\ArcGIS\DeveloperKit10.3\include\CPPAPI
  • C:\Program Files (x86)\ArcGIS\DeveloperKit10.3\include\CatIDs

This can be done by going to your Project properties dialog box (right click your project > Properties), > Configuration Properties > C/C++ > General > Additional Include Directories

3. Make a small change to your IDL file. Add the IUnknown interface to it as shown below.

coclass ZoomIn

{

     [default] interface IUnknown;

     interface IZoomIn;

};

4. In the section of the walkthrough where it says, "Reference the ESRI Object libraries," make a small change to the esriSystem object library reference; add "XMLSerializer" at the end of list in parentheses:

"C:\\Program Files (x86)\\ArcGIS\\Desktop10.3\\com\\esriSystem.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_COLOR", "OLE_HANDLE", "VARTYPE", "XMLSerializer")

5. In the "Adding a bitmap" section of the Walkthrough, ignore the part about naming your Bitmap resource IDB_ZOOMIN. Simply give your bitmap the resource name that is assigned to it automatically when you create it. This will probably be something like IDB_BITMAP1. Thus, you should reference your bitmap in your ZoomIn.h file as shown below:

CZoomIn()

{

     LoadBitmap(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDB_BITMAP1));

}

6. In the "Adding COM category registration" part of the walkthrough, ignore the code provided:

[coclass, threading("apartment"), vi_progid("Walkthrough1VC8.ZoomIn"),

     progid(Walkthrough1VC8.ZoomIn.1"), version(1.0),

     uuid("E86E1877-82F5-4560-AF99-1987E23047CD"), helpstring("ZoomIn Class"),

     implements_category(__uuidof(CATID_MxCommands)),

     implements_category(__uuidof(CATID_ControlsCommands))

]

Do not add the above block of code. Instead, add the following code to your ZoomIn.h file, right below the line of code, END_COM_MAP():

struct __declspec(uuid("B56A7C42-83D4-11d2-A2E9-080009B6F22B")) CATID_MxCommands;

struct__declspec(uuid("{B284D891-22EE-4F12-A0A9-B1DDED9197F4}")) CATID_ControlsCommands;

BEGIN_CATEGORY_MAP(__uuidof(CATID_ControlsCommands))

     IMPLEMENTED_CATEGORY(__uuidof(CATID_MxCommands))

END_CATEGORY_MAP()

The above code (the macros) performs the automatic registration of your COM component.

7. With the above changes, the walkthrough should lead to the successful creation of custom COM component using ATL/VC++.

You can find the above steps in the ESRI Github repository located here:

Creating a Simple Command using ATL Using Visual Studio 2013

https://github.com/Esri/developer-support/tree/master/arcobjects-c%2B%2B/create-command-atl

View solution in original post

2 Replies
SamiEria
Deactivated User


Please follow this walkthrough:

Creating a Simple Command

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/#/Walkthrough_Creating_a_simple_co...

Because this walkthrough was written for a previous version of ArcGIS (8.x and 9.x), make the following changes to update it for the 10.x versions of ArcObjects.

1. Ignore the part of the tutorial about the two attributes below:

  • [coclass, default(IZoomIn),

                threading(apartment),

               vi_progid("Walkthrough1VC8.ZoomIn"),

               progid("Walkthrough1VC8.ZoomIn.1"), version(1.0),

               uuid("C77B6C59-2A8A-4E0C-9877-5FEA1F4C02B4"), helpstring("ZoomIn Class")

        ]class ATL_NO_VTABLE CZoomIn: public IZoomIn

  • [object, uuid("297E96B4-D481-47C3-AEEB-CD526016DFDA"),

                    helpstring(

                     "IZoomIn Interface"),

                      pointer_default(unique)

          ]

Adding these attributes to your code will cause a compile error. Do not add these two attributes to your ZoomIn.h file.

2. Make sure to add the following "Additional Include" paths:

  • C:\Program Files (x86)\ArcGIS\DeveloperKit10.3\include\CPPAPI
  • C:\Program Files (x86)\ArcGIS\DeveloperKit10.3\include\CatIDs

This can be done by going to your Project properties dialog box (right click your project > Properties), > Configuration Properties > C/C++ > General > Additional Include Directories

3. Make a small change to your IDL file. Add the IUnknown interface to it as shown below.

coclass ZoomIn

{

     [default] interface IUnknown;

     interface IZoomIn;

};

4. In the section of the walkthrough where it says, "Reference the ESRI Object libraries," make a small change to the esriSystem object library reference; add "XMLSerializer" at the end of list in parentheses:

"C:\\Program Files (x86)\\ArcGIS\\Desktop10.3\\com\\esriSystem.olb" raw_interfaces_only raw_native_types no_namespace named_guids exclude("OLE_COLOR", "OLE_HANDLE", "VARTYPE", "XMLSerializer")

5. In the "Adding a bitmap" section of the Walkthrough, ignore the part about naming your Bitmap resource IDB_ZOOMIN. Simply give your bitmap the resource name that is assigned to it automatically when you create it. This will probably be something like IDB_BITMAP1. Thus, you should reference your bitmap in your ZoomIn.h file as shown below:

CZoomIn()

{

     LoadBitmap(_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(IDB_BITMAP1));

}

6. In the "Adding COM category registration" part of the walkthrough, ignore the code provided:

[coclass, threading("apartment"), vi_progid("Walkthrough1VC8.ZoomIn"),

     progid(Walkthrough1VC8.ZoomIn.1"), version(1.0),

     uuid("E86E1877-82F5-4560-AF99-1987E23047CD"), helpstring("ZoomIn Class"),

     implements_category(__uuidof(CATID_MxCommands)),

     implements_category(__uuidof(CATID_ControlsCommands))

]

Do not add the above block of code. Instead, add the following code to your ZoomIn.h file, right below the line of code, END_COM_MAP():

struct __declspec(uuid("B56A7C42-83D4-11d2-A2E9-080009B6F22B")) CATID_MxCommands;

struct__declspec(uuid("{B284D891-22EE-4F12-A0A9-B1DDED9197F4}")) CATID_ControlsCommands;

BEGIN_CATEGORY_MAP(__uuidof(CATID_ControlsCommands))

     IMPLEMENTED_CATEGORY(__uuidof(CATID_MxCommands))

END_CATEGORY_MAP()

The above code (the macros) performs the automatic registration of your COM component.

7. With the above changes, the walkthrough should lead to the successful creation of custom COM component using ATL/VC++.

You can find the above steps in the ESRI Github repository located here:

Creating a Simple Command using ATL Using Visual Studio 2013

https://github.com/Esri/developer-support/tree/master/arcobjects-c%2B%2B/create-command-atl

FloD
by
Deactivated User

Hi Sami,

Thank you very much for this answer, it helped a lot.

Regards.

0 Kudos