Visual C ++代码在Code :: Blocks中不起作用 [英] Visual C++ code not working in Code::Blocks
问题描述
我目前使用以下代码从C#Dll调用函数,该代码在Visual C ++中可以很好地工作.
I have the following code that I am currently using to call functions from a C# Dll, which works perfectly in Visual C++.
#include <mscoree.h>
#include <stdio.h>
#pragma comment(lib, "mscoree.lib")
void Bootstrap()
{
ICLRRuntimeHost *pHost = NULL;
HRESULT hr = CorBindToRuntimeEx(L"v4.0.30319", L"wks", 0, CLSID_CLRRuntimeHost, IID_ICLRRuntimeHost, (PVOID*)&pHost);
pHost->Start();
printf("HRESULT:%x\n", hr);
// target method MUST be static int method(string arg)
DWORD dwRet = 0;
hr = pHost->ExecuteInDefaultAppDomain(L"c:\\temp\\test.dll", L"Test.Hello", L"SayHello", L"Person!", &dwRet);
printf("HRESULT:%x\n", hr);
hr = pHost->Stop();
printf("HRESULT:%x\n", hr);
pHost->Release();
}
int main()
{
Bootstrap();
}
问题是,当我将其移到Code :: Blocks(我更熟悉-因为我做的小C ++是本机的)时,会引发很多编译器错误.
The problem is, when I move this into Code::Blocks (which I am more familiar with - as the little C++ I have done has been native) throws a lot of compiler errors.
最初的编译器错误是因为找不到头文件mscoree.h
.我在.NET SDK中找到了它,所以我将其复制到解决该问题的mingw include目录中,然后对找不到的所有其他标头执行相同的操作.
The original compiler errors were because it couldn't find the header mscoree.h
. I found this in the .NET SDK, so I copied it over to the mingw include directory which solved that, and then I did the same for all the other headers it couldn't find.
在复制所有标头之后,它随后开始提供其他全部错误,与我刚移动的标头中的代码有关-与下面的代码无关.
After copying over all the headers it then started giving a whole load of other errors, to do with the code in the headers I had just moved - nothing to do with the code below.
为什么当VS直接运行时,Code :: Blocks很难如此运行?
Why is Code::Blocks having such a hard time running this when VS runs it straight off the bat?
谢谢
推荐答案
Code :: Blocks 是用于C ++编程的出色IDE,但是您显然在这里进行Windows编程.尽管它是相同的编程语言,但它们之间的编译器不兼容.
Code::Blocks is a great IDE for C++ programming, but you are clearly doing Windows programming here. Though it is the same programming language, compilers are not compatible among them.
无论您是使用gcc编译器下载了CodeBlocks版本,还是使用单个CodeBlocks IDE,都需要配置CodeBlocks才能使用MS C ++编译器.为此,请转到设置>>编译器和调试器>>工具链可执行文件.
Either if you have downloaded the CodeBlocks version with the gcc compiler, or the single CodeBlocks IDE, you need to configure CodeBlocks in order to use the MS C++ compiler. In order to do that, go to Settings >> Compiler and debugger >> Toolchain executables.
此外,在同一选项中,查找搜索目录,然后在其中放置MS C ++编译器标头的路径.
Also, in the same option, look for Search directories and place there the path to the MS C++ compiler headers.
完成后,您将可以编译程序.
Once that is done, you will be able to compile your program.
这篇关于Visual C ++代码在Code :: Blocks中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!