Embedding google earth plugin into C# WinForm Application

0

I am using vs2015 to develop an application that opens google earth plugin in a C# win form application. Based on codeproject website : https://www.codeproject.com/Articles/31603/Embedding-Google-Earth-in-a-C-Application

I tried the folowing code:

using EARTHLib;
using System;
using System.Windows.Forms;

namespace googleEarth
{
    public partial class Form2 : Form
    {
        [DllImport("user32.dll")]
        private static extern bool ShowWindowAsync(
        int hWnd,
        int nCmdShow);

        EARTHLib.ApplicationGE ge = null;

        public Form2()
        {
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            ge = new ApplicationGE();
            ShowWindowAsync(ge.GetMainHwnd(), 0);
        }
    }
}

But every time I run the application, google earth opens successfully but the code immediately throws following error:

:enter image description here

The full error message is:

An unhandled exception of type 'System.InvalidCastException' occurred in googleEarth.exe

Additional information: Unable to cast COM object of type 'System.__ComObject' to interface type 'EARTHLib.ApplicationGE'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{2830837B-D4E8-48C6-B6EE-04633372ABE4}' failed due to the following error: Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).

But I dont know how to solve this issue. What is missing?

EDIT: I could get rid of that problem by right click EARTHLib properties and set Embed interop Types = False and google earth pro plugin opens but not embedded in my form. I continued as per codeproject solution and again got the same problem in the next line: ShowWindowAsync(ge.GetMainHwnd(), 0); What is missing?

c#
winforms
embedding
asked on Stack Overflow Nov 13, 2017 by Hilal Al-Rajhi • edited Nov 15, 2017 by Hilal Al-Rajhi

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0