- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用以下配置创建一个 Visual C++ Win32 控制台应用程序:操作系统:Windows 7 Visual Studio :VS 2012公共(public)语言运行时支持:公共(public)语言运行时支持(/clr[项目属性]。
我还创建了一个 Visual C# WPF 应用程序,并使用该 dll 从下面提到的 c++ 程序中使用它。
我遵循此链接中的所有说明:https://code.msdn.microsoft.com/CppHostCLR-e6581ee0
问题是我无法启动 CLR,即 ICLRRunTimeHost:Start 方法返回 0x1 而不是 0x0。请帮助/指导我解决我的错误,如果我的代码在概念上是错误的,请指导我。
请在下面找到我粘贴的代码:
#include "stdafx.h"
#include <metahost.h>
#include <mscoree.h>
//#include <Windows.h>
//#using <WpfWithoutService.dll>
//using namespace System;
//using namespace System::Threading;
//using namespace WpfWithoutService;
#pragma comment(lib, "mscoree.lib")
/*ref class MainWinClass
{
public:
void MainForm()
{
MainWindow^ mainwin = gcnew MainWindow();
//mainwin->Activate();
//mainwin->InitializeComponent();
}
};*/
int _tmain(int argc, _TCHAR* argv[])
{
HRESULT hr;
//BOOL fLoadable;
ICLRMetaHost *pMetaHost = NULL;
LPCWSTR pwzVersion = (LPCWSTR)"v4.0.30319";
//hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_ICLRMetaHost, (LPVOID*)&pMetaHost);
hr = CLRCreateInstance(CLSID_CLRMetaHost, IID_PPV_ARGS(&pMetaHost));
if (FAILED(hr))
{
wprintf(L"CLRCreateInstance failed w/hr 0x%08lx\n", hr);
}
ICLRRuntimeInfo *pRuntimeInfo = NULL;
// Get the ICLRRuntimeInfo corresponding to a particular CLR version.
//hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_ICLRRuntimeInfo, (LPVOID *)&pRuntimeInfo);
hr = pMetaHost->GetRuntime(L"v4.0.30319", IID_PPV_ARGS(&pRuntimeInfo));
if (FAILED(hr))
{
wprintf(L"ICLRMetaHost::GetRuntime failed w/hr 0x%08lx\n", hr);
//goto Cleanup;
}
/*Check if the specified runtime can be loaded into the process. This
// method will take into account other runtimes that may already be
// loaded into the process and set pbLoadable to TRUE if this runtime can
// be loaded in an in-process side-by-side fashion.
hr = pRuntimeInfo->IsLoadable(&fLoadable);
if (FAILED(hr))
{
wprintf(L"ICLRRuntimeInfo::IsLoadable failed w/hr 0x%08lx\n", hr);
//goto Cleanup;
}
if (!fLoadable)
{
wprintf(L".NET runtime %s cannot be loaded\n", "4.0.30319.18063");
//goto Cleanup;
}*/
// Load the CLR into the current process and return a runtime interface pointer.
ICLRRuntimeHost *pClrRuntimeHost = NULL;
hr = pRuntimeInfo->GetInterface(CLSID_CLRRuntimeHost, IID_PPV_ARGS(&pClrRuntimeHost));
if (FAILED(hr))
{
wprintf(L"ICLRRuntimeInfo::GetInterface failed w/hr 0x%08lx\n", hr);
}
// Start the CLR.
if (hr == S_OK)
{
hr = pClrRuntimeHost->Start();
if (FAILED(hr))
{
wprintf(L"CLR failed to start w/hr 0x%08lx\n", hr);
//goto Cleanup;
}
}
//Load an assembly and call the required function
if (hr == S_OK) // if CLR is started successfully
{
DWORD dwRet;
hr = pClrRuntimeHost->ExecuteInDefaultAppDomain(L"WpfWithoutService.dll", L"WpfWithoutService.MainWindow", L"InitializeComponent", NULL, &dwRet);
if (FAILED(hr))
{
wprintf(L"CLR failed to start w/hr 0x%08lx\n", hr);
}
}
if (pMetaHost)
{
pMetaHost->Release();
pMetaHost = NULL;
}
if (pRuntimeInfo)
{
pRuntimeInfo->Release();
pRuntimeInfo = NULL;
}
if (pClrRuntimeHost)
{
// Please note that after a call to Stop, the CLR cannot be
// reinitialized into the same process. This step is usually not
// necessary. You can leave the .NET runtime loaded in your process.
//wprintf(L"Stop the .NET runtime\n");
pClrRuntimeHost->Stop()
pClrRuntimeHost->Release();
pClrRuntimeHost = NULL;
}
return 0;
}
最佳答案
ICLRRunTimeHost:Start method returns 0x1 instead of 0x0
即 S_FALSE,当 CLR 已经运行时返回。你不能启动它两次。
with following configuration ... Common Language Runtime Support
这是不合适的,它会强制 CLR 在此代码开始运行之前进行加载和初始化。您只能在不使用/clr 构建的 native C++ 程序中编写这样的 CLR 托管代码。
或者换句话说,你根本不需要写这段代码。并且没有明显的理由说明您想要从代码段中获取。从 Assembly::Load() 开始,您可以通过使用反射来实现完全相同的事情。或者更简单,通过添加对该程序集的引用。实际意图很难逆向工程。如果确实存在,则只需将/clr 选项设置回“否”即可。
关于c# - 无法使用/clr 选项从 Visual C++ 项目加载 CLR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31854323/
我了解堆栈和堆的基本概念,但如果有任何一个可以解决以下困惑,那就太好了: 是否为整个应用程序流程或项目中开始的每个线程都创建了一个新堆栈? 是否为整个应用程序进程或项目中开始的每个线程都创建了一个新堆
我已经阅读了无数关于 C# 4.0 新特性的博客、帖子和 StackOverflow 问题。甚至新的 WPF 4.0 功能也开始公开发布。我找不到并且想知道的: 从 C#/WPF 开发人员的角度来看,
最近,我的 asp.net 应用程序崩溃了。我在 Windows 上获得了事件日志,两种类型的异常消息: Application: w3wp.exe Framework Version: v4.0.3
我了解当前状态的 CLR 绑定(bind)到 Windows 操作系统,并通过在内部使用 Win32 API 提供各种服务。 由于 .NET Core 是独立于平台的,这基本上意味着相同的 IL 代码
AFAIK,try 和 finally block 用于执行一段可能会抛出一些异常的代码,我们还添加了 catch block ,如果我们准备处理某种类型的异常和/或将它们排除在外,比如 FileIO
问题: 线程中的未处理异常进入 CLR来自非托管代码不会触发“正常”未处理的异常 CLR 处理。 在下面的代码中,使用 C++ 调用 CSSimpleObject.GetstringLength()
JVM/CLR 如何执行 JIT 编译的原生代码?是通过一些代码注入(inject)还是通过将代码复制到可执行内存?允许动态代码执行的系统调用是什么? 最佳答案 我可以在 CACAO VM 中解释我们
我从事的项目需要 .Net 与非托管代码的互操作性。几周前我开始使用 .Net,虽然我在 C/C++ 方面有很多经验,但我很惊讶 CLR 如何处理 P/Invoke。这是详细信息。我的同事写了这个函数
在哪里可以找到 ODP 到 CLR 类型映射的列表?在 Oracle 数据库上,NUMBER(9,0) 类型在 .NET 应用程序中作为 MS Oracle 驱动程序的 System.Decimal
我有一个 Ubuntu 12.04。我尝试在我的 python 代码中导入 clr,但出现此错误。 我浏览了链接。但这一切都是徒劳的。有没有办法检查“clr”存在?如何查看模块是否存在? 最佳答案 您
我提到了 this somewhat similar question在问这个之前,但无法解决我的问题 我正在查看一个包含许多解决方案的旧应用程序。问题发生在其中一个解决方案中(比如 S)。这是情况:
假设我有一个旧的应用程序,它将尝试加载外部程序集。 旧应用程序编译为 CLR 2。 新程序集编译为 CLR 4。 我希望能够在 CLR 4 中运行那个旧应用程序。我记得有一些 xml manifest
我可以编写、编译并成功运行以下 IL 程序,并将 .maxstack 大小设置为 1,该值太低,因为该程序在某个时间点堆栈上有两个值(即 2+2==4) 。该程序不会在 CLR 中崩溃,并以“Hell
.Core CLR 与 Mono CLR 有什么区别?那么微软为什么要维护不同的运行时环境呢? 最佳答案 两者都是 .NET Standard 的实现,但它们具有不同的实现细节。 Mono从历史上看,
我正在尝试使用以下配置创建一个 Visual C++ Win32 控制台应用程序:操作系统:Windows 7 Visual Studio :VS 2012公共(public)语言运行时支持:公共(p
// This is the main DLL file. #include "stdafx.h" #include "Tga2DCLI.h" //#include #include Tga2DC
我有两个项目的解决方案。第一个是基本类库项目,其中包含在多个服务端点 (DataContract.dll) 之间共享的类的定义。第二个是将使用共享程序集中定义的类的 SQL CLR 项目。在我的本地机
我尝试创建一个使用 Windows 窗体的 .NET 控制台应用程序来创建和保存屏幕截图。在创建新的控制台应用程序项目时,我尝试使用 COM 引用通过依赖项导入 System.Windows.Form
DOS 变成 Windows 的方式是一样的吗? 我们似乎最终支持和开发了 Microsoft 的三个平台,我不确定边界应该在哪里。 为什么不能将 CLR 的好处(例如类型安全、内存保护等)内置到 W
在 VC++ .Net 中,Clr/Safe (/clr:safe) 和 Clr/Pure (/clr:pure) 是什么意思? 最佳答案 来自doc : /clr:pure Produces a M
我是一名优秀的程序员,十分优秀!