Select to view content in your preferred language

How can I create a MapView control that I can consume in an MFC application

2729
6
12-20-2016 07:30 AM
ChrisBarrington_Brown
Emerging Contributor

One can normally host a WPF control in MFC using teh Interop described in like http://weblogs.thinktecture.com/cnagel/2010/04/mfc-and-wpf-interop.html.  When I try this I get an exception in RuntimeCoreNet.GeneratedWrappers.CoreWrapperBase.  It appears that the .NET Runtime assumes there is some XAML to initialise the control.  Has anyone successfully hosted a Runtime MapView in an MFC application?

Code snippet:

HWND GetHwnd(HWND parent, int x, int y, int width, int height)
{
   System::Windows::Interop::HwndSourceParameters^ sourceParams = gcnew    System::Windows::Interop::HwndSourceParameters("MFCWPFApp");
   sourceParams->PositionX = x;
   sourceParams->PositionY = y;
   sourceParams->Height = height;
   sourceParams->Width = width;
   sourceParams->ParentWindow = IntPtr(parent);
   sourceParams->WindowStyle = WS_VISIBLE | WS_CHILD;
   Globals::gHwndSource = gcnew System::Windows::Interop::HwndSource(*sourceParams);

   Globals::gwcMapView = gcnew Esri::ArcGISRuntime::UI::Controls::MapView; // Fails here with
   // Additional information : The type initializer for 'RuntimeCoreNet.GeneratedWrappers.CoreWrapperBase' threw an    exception.

   FrameworkElement^ myPage = Globals::gwcMapView;

   Globals::gHwndSource->RootVisual = myPage;
   return (HWND)Globals::gHwndSource->Handle.ToPointer();
}

0 Kudos
6 Replies
AnttiKajanus1
Deactivated User

Can you see runtime folder under your bin folder? This should contain all the needed libraries to work with runtime and if it missing, runtime wont work.

ChrisBarrington_Brown
Emerging Contributor

Only some were copied.  I now have a complete set and I can create a blank MapView in a dialog.

However, I can't create a Map or a Raster as I would expect using code like this (using namespace Esri::ArcGISRuntime)

   Mapping::Map^ myMap = gcnew Mapping::Map(Mapping::Basemap::CreateStreets());

   Globals::gwcMapView->Map = myMap;

or

   Globals::myRaster = gcnew Rasters::Raster("E:\\Raw_Mapping\\Tif\\rgb\\Brisbane_Raster_250_RGB.tif");

   Mapping::RasterLayer^ rasterLayer = gcnew Mapping::RasterLayer(Globals::myRaster);

In both cases the error is this (in the Map case)

1>BBTest_MFCDlg.cpp(59): error C3252: 'RuntimeCoreNet::GeneratedWrappers::CoreWrapperBase::Finalize': cannot reduce accessibility of a virtual method in a managed type
1> BBTest_MFCDlg.cpp(59): note: This diagnostic occurred while importing type 'RuntimeCoreNet::GeneratedWrappers::CoreWrapperBase ' from assembly 'Esri.ArcGISRuntime, Version=100.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'.
1> BBTest_MFCDlg.cpp(59): note: This diagnostic occurred while importing type 'RuntimeCoreNet::GeneratedWrappers::CoreMap ' from assembly 'Esri.ArcGISRuntime, Version=100.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'.
1> BBTest_MFCDlg.cpp(59): note: This diagnostic occurred while importing type 'Esri::ArcGISRuntime::Mapping::Map ' from assembly 'Esri.ArcGISRuntime, Version=100.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86'.

Searching the web for error C3252 doesn't help, and the Map (and Raster) are public so shouldn't throw this error.

Any clues as to how to proceed?

0 Kudos
AnttiKajanus1
Deactivated User

I'm not sure what is the support situation with MFC and WPF based ArcGIS Runtime integration but it has never been tested at least. I'll check out what is the situation with that and get back to you.

0 Kudos
AnttiKajanus1
Deactivated User

Can you provide me a simple solution with step by step guide how to run it? You can send it to akajanus@esri.com. Thanks.

0 Kudos
MichaelBranscomb
Esri Frequent Contributor

Hi Chris,

It took a while to get to the bottom of this, but we are unfortunately not able to currently support use of our SDK within an MFC app. We have an ongoing thread with Microsoft on this issue. It appears it may be a compiler problem, or similar.

Cheers

Mike

0 Kudos
dotMorten_esri
Esri Notable Contributor

Microsoft has confirmed the bug and even made a fix for an upcoming version of their compiler:

https://connect.microsoft.com/VisualStudio/feedback/details/3145157/unexpected-c3252-error-in-c-clr-...

0 Kudos