在VS2010中构建DLL c#.NET 2.0,并在VS2005中使用它 [英] Build DLL c# .NET 2.0 in VS2010 and use it in VS2005
问题描述
你好
我有问题:
我在带有.NET 2.0目标项目的VS2010上的c#中有一个DLL.我会在VS 2005的natif代码C ++中使用它.
接下来,我将如何处理有关网络上的信息:
DLL dllTest.dll(c#VS2010)
[CODE]
使用系统;
命名空间NamespaceDLL
{
公共课程MaDll
{
...
公共静态int SimpleTest(int值)
{
返回++值;
}
...
}
}
[/CODE]
包装器wrapper.cpp(C ++ VS2010)
[CODE]
#include" stdafx.h"
#include" wrapperDll.h"
#using``.. \ bin \ Debug \ dllTest.dll''
使用名称空间System;
使用名称空间NamespaceDLL;
外部"C"
{
__declspec(dllexport)int __cdecl SimpleTest(int值)
{
MaDll __gc * test;
测试=新的MaDll;
return test-> SimpleTest(value);
}
}
[/CODE]
应用程序测试test.cpp(WIN32 App consol VS2005)
[CODE]
#include"stdafx.h"
使用名称空间std;
外部"C"
{
int __cdecl SimpleTest(int value);
}
int _tmain(int argc,_TCHAR * argv [])
{
SimpleTest(100);
返回0;
}
[/CODE]
存在所有文件(DLL,LIB),因为构建时没有错误.但是在执行时,由于调用DLL函数,因此调用包装器函数时会出错.
当我从VS2010运行此测试时,我没有出现错误,并且得到了不错的结果.但是从VS2005 ...错误.
我将Framework 2.0上的DLL项目正确地定向到VS2010中,但问题没有解决.
运行时出现错误:"Exception non gé ré eà 0x75419617 dans test.exe *:0xE0434352:0xe0434352.
很明显,在c#DLL级别出现错误是因为,如果我在包装器中执行一个简单的函数(不调用DLL),就不会出错.
+在测试代码中,我这样做了:
代码:
#pragma comment(lib," wrapper.lib")
如果有人可以帮助我.
此致
如果使用VS 2005构建wrapper类wrapper.lib会发生什么?
我对您的描述感到困惑,因为事实是使用Visual Studio 2010 C ++无法将.NET Framework 2.0作为目标.只能针对.NET Framework 4.0.
Hello,
There is my problem:
I have one DLL in c# build on VS2010 with .NET 2.0 target project. I would use it in natif code C++ from VS 2005.
Look next how I proceed regarding information on web:
DLL dllTest.dll (c# VS2010)
[CODE]
using System;
namespace NamespaceDLL
{
public class MaDll
{
...
public static int SimpleTest(int value)
{
return ++value;
}
...
}
}
[/CODE]
Wrapper wrapper.cpp (C++ VS2010)
[CODE]
#include "stdafx.h"
#include "wrapperDll.h"
#using "..\bin\Debug\dllTest.dll"
using namespace System;
using namespace NamespaceDLL;
extern "C"
{
__declspec(dllexport) int __cdecl SimpleTest (int value)
{
MaDll __gc *test;
test = new MaDll;
return test->SimpleTest (value);
}
}
[/CODE]
Application test test.cpp (WIN32 App consol VS2005)
[CODE]
#include "stdafx.h"
using namespace std;
extern "C"
{
int __cdecl SimpleTest(int value);
}
int _tmain(int argc, _TCHAR* argv[])
{
SimpleTest(100);
return 0;
}
[/CODE]
All file are present (DLL, LIB) because there is no error at building. But at executing, there is an error when it call the wrapper function because it call DLL function.
When I run this test from VS2010, I did not a error and I had the good result. But from VS2005 ... error.
I correctly target DLL project on Framework 2.0 into VS2010 but problems not solve.
There is the error at running: "Exception non gérée à 0x75419617 dans test.exe*: 0xE0434352: 0xe0434352."
It's clearly at c# DLL level that error comes because if I do a simple function (that don't call the DLL) in the wrapper, there is no error.
+ In test code I do:
Code :
#pragma comment(lib, "wrapper.lib")
If someone can help me please.
Regards,
What happens if you build the wrapper class wrapper.lib using VS 2005?
I'm puzzled by your description, because of the fact that one cannot target .NET Framework 2.0 using Visual Studio 2010 C++. One can only target the the .NET Framework 4.0.
这篇关于在VS2010中构建DLL c#.NET 2.0,并在VS2005中使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!