我正在使用vs2015开发一个在C#win表单应用程序中打开google earth插件的应用程序。基于codeproject网站: https://www.codeproject.com/Articles/31603/Embedding-Google-Earth-in-a-C-Application
我尝试了下面的代码:
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);
}
}
}
但每次我运行该应用程序时,Google地球都会成功打开,但代码会立即抛出以下错误:
完整的错误消息是:
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)).
但我不知道如何解决这个问题。 缺少什么?
编辑:
我可以通过右键单击EARTHLib属性并设置Embed interop Types = False来解决这个问题,并且google earth pro插件会打开但不会嵌入到我的表单中。
我按照codeproject解决方案继续,并在下一行再次遇到同样的问题:ShowWindowAsync(ge.GetMainHwnd(), 0);
缺少什么?