问题描述
我想利用在node.js中的.NET的DLL这是否意味着我需要提供与C / C ++使用CLR托管这些dll,一拉
- 的或
- 的
校正做到这一点文章正义。这表明更改选项没有公共语言运行库支持只为你添加将CLR支持启用(对于CLR项目的默认)文件 SharpAddon.cpp
,所以其他的.cpp-文件,这意味着你其实可以使用.NET的DLL与其他.cpp文件。
这问题其实是的,这是在写的时候甚至没有节点的本地Windows端口,所以时间可能会有所改变,虽然谷歌让我怀疑。它
更新:节点石膏可以在下面做自动的手动步骤时, binding.gyp
文件是正确安装。请参见。
原来是相当容易的。与CLR托管挣扎,进出主机的同时获取数据后,原来的你其实可以启用您的节点扩展/ CLR没有问题(到目前为止)。具体方法如下:
- 按照上的生成项目文件
- 打开在Visual Studio生成的.sln(我在VS 2010),并启用/ CLR在项目设置
- 现在,它可能不会建立,你必须让 - 在这种情况下,其实是相当有帮助的 - 错误信息引导你的标志
$ b:使用/ clr
这是我不得不改变,使其工作的标志冲突$ b
- 禁用/ EHSC(C ++异常)
- 禁用/ RTC1和/ RTCsu
- 发布:变化/ MT到/ MD
- 调试:改变/ MTD到/ MDD
- 发布:改变/ GR-到/ GR
然后你可以混合托管和非托管代码这样,引用您的.NET的DLL。
的#pragma管理
使用#using< managed.dll>
无效callManaged()
{
::管理的Class1 ^ C1 = gcnew管理:: 1级();
系统:字符串^结果= C1->回声(HOLA);
系统::控制台:的WriteLine(它的工作原理:+结果);
}
的#pragma非托管
手柄< VALUE>方法(常量参数和放大器;参数){
HandleScope范围;
callManaged();
返回scope.Close(字符串::新(世界));
}
更新刚发现这与简单的HOWTO链接:
I want to make use of .net dlls in node.js. Does that mean I need to make those dlls available with c/c++ using 'clr hosting', a la
Correction to do that article justice: It suggests to change that option to "No Common Language RunTime Support" only for the file SharpAddon.cpp
, so other .cpp-files you add will have CLR support enabled (the default for a CLR project), which means you can in fact use .net dlls from those other .cpp files.
This question is actually a duplicate of Using a .NET DLL in Node.js / serverside javascript, which was written at a time when there was not even a native Windows port of node, so times might have changed, although google makes me doubt it.
Update: node-gyp can do the manual steps below automatically when the binding.gyp
file is setup properly. See this answer for this simplified procedure.
It turned out to be rather easy. After struggling with CLR hosting and getting data in and out of the host for a while, it turns out you can actually enable /clr for your node extension no problem (so far). Here's how:
- follow the instructions on http://nodejs.org/api/addons.html to generate the project files
- open the generated .sln in Visual Studio (I'm on VS 2010) and enable /clr in the project settings
- now it probably won't build and you have to let the - in this case actually quite helpful - error messages guide you to the flags that conflict with /clr
The flags that I had to change to make it work:
- disable /EHsc (C++ exceptions)
- disable /RTC1 and /RTCsu
- Release: change /MT to /MD
- Debug: change /MTd to /MDd
- Release: change /GR- to /GR
Then you can mix managed and unmanaged code like this, referencing your .net dlls.
#pragma managed
#using <managed.dll>
void callManaged()
{
managed::Class1^ c1 = gcnew managed::Class1();
System::String^ result = c1->Echo("hola");
System::Console::WriteLine("It works: " + result);
}
#pragma unmanaged
Handle<Value> Method(const Arguments& args) {
HandleScope scope;
callManaged();
return scope.Close(String::New("world"));
}
Update Just discovered this link with an easy howto: http://joseoncode.com/2012/04/10/writing-your-first-native-module-for-node-dot-js-on-windows/
这篇关于.NET原生扩展的node.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!