vc ++.net2005 managed unmanaged mixing code
2007-11-30 14:11
197 查看
编译时,不要预编译头,要CLR,
//1111111111111111111111111111111111111111111111111111111111111111111111111111
#using <mscorlib.dll>
using namespace System;
#include "stdio.h"
void ManagedFunction()
{
System::Console::WriteLine("Hello, I'm managed in this section/n");
}
//#pragma unmanaged 本来下面是对应的managed或unmanaged code 但
//这里去掉了也没有报错
void UnmanagedFunction()
{
printf("Hello, I am unmanaged through the wonder of IJW!/n");
ManagedFunction();
}
//#pragma managed
int main()
{
UnmanagedFunction();
return 0;
}
//2222222222222222222222222222222222222222222222222222222222222222222222222222
#using <mscorlib.dll>
using namespace System;
#include <string>
class Container
{
int value_;
public:
Container() : value_(0) {}
void SetValue(int *val) { value_ = *val;}
const int& GetValue() { return value_; }
};
ref class ManagedContainer
{
Container *pContainer;
public:
ManagedContainer()
{
pContainer = new Container();
}
void SetValue(int val)
{
int someValue = val;
pContainer->SetValue(&someValue);
}
~ManagedContainer()
{
delete pContainer;
}
};
void main()
{
ManagedContainer ^mc = gcnew ManagedContainer();
int someValue = 42;
mc->SetValue(someValue);
System::Console::WriteLine("The value is "+
someValue.ToString());
}
//3333333333333333333333333333333333333333333333333333333333333333333333333333333333
#using <mscorlib.dll>
using namespace System;
#include <string>
class Container
{
int value_;
public:
Container() : value_(0) {}
void SetValue(int *val) { value_ = *val;}
const int& GetValue() { return value_; }
};
ref class ManagedContainer
{
Container* pContainer;
public:
ManagedContainer()
{
pContainer = new Container();
}
void SetValue(int val)
{
int someValue = val;
pin_ptr<int> pinnedInt = &someValue;
pContainer->SetValue(pinnedInt);
}
~ManagedContainer()
{
delete pContainer;
}
};
void main()
{
ManagedContainer ^mc = gcnew ManagedContainer();
int someValue = 42;
mc->SetValue(someValue);
System::Console::WriteLine("The value is " + someValue.ToString());
}
//4444444444444444444444444444444444444444444444444444444444444444444444444444
#using <mscorlib.dll>
#include <vcclr.h>
using namespace System;
class CppClass {
public:
gcroot<String^> str; // can use str as if it were String*
CppClass() {}
};
int main() {
CppClass c;
c.str = gcnew String("hello");
Console::WriteLine( c.str ); // no cast required
}s
//1111111111111111111111111111111111111111111111111111111111111111111111111111
#using <mscorlib.dll>
using namespace System;
#include "stdio.h"
void ManagedFunction()
{
System::Console::WriteLine("Hello, I'm managed in this section/n");
}
//#pragma unmanaged 本来下面是对应的managed或unmanaged code 但
//这里去掉了也没有报错
void UnmanagedFunction()
{
printf("Hello, I am unmanaged through the wonder of IJW!/n");
ManagedFunction();
}
//#pragma managed
int main()
{
UnmanagedFunction();
return 0;
}
//2222222222222222222222222222222222222222222222222222222222222222222222222222
#using <mscorlib.dll>
using namespace System;
#include <string>
class Container
{
int value_;
public:
Container() : value_(0) {}
void SetValue(int *val) { value_ = *val;}
const int& GetValue() { return value_; }
};
ref class ManagedContainer
{
Container *pContainer;
public:
ManagedContainer()
{
pContainer = new Container();
}
void SetValue(int val)
{
int someValue = val;
pContainer->SetValue(&someValue);
}
~ManagedContainer()
{
delete pContainer;
}
};
void main()
{
ManagedContainer ^mc = gcnew ManagedContainer();
int someValue = 42;
mc->SetValue(someValue);
System::Console::WriteLine("The value is "+
someValue.ToString());
}
//3333333333333333333333333333333333333333333333333333333333333333333333333333333333
#using <mscorlib.dll>
using namespace System;
#include <string>
class Container
{
int value_;
public:
Container() : value_(0) {}
void SetValue(int *val) { value_ = *val;}
const int& GetValue() { return value_; }
};
ref class ManagedContainer
{
Container* pContainer;
public:
ManagedContainer()
{
pContainer = new Container();
}
void SetValue(int val)
{
int someValue = val;
pin_ptr<int> pinnedInt = &someValue;
pContainer->SetValue(pinnedInt);
}
~ManagedContainer()
{
delete pContainer;
}
};
void main()
{
ManagedContainer ^mc = gcnew ManagedContainer();
int someValue = 42;
mc->SetValue(someValue);
System::Console::WriteLine("The value is " + someValue.ToString());
}
//4444444444444444444444444444444444444444444444444444444444444444444444444444
#using <mscorlib.dll>
#include <vcclr.h>
using namespace System;
class CppClass {
public:
gcroot<String^> str; // can use str as if it were String*
CppClass() {}
};
int main() {
CppClass c;
c.str = gcnew String("hello");
Console::WriteLine( c.str ); // no cast required
}s
相关文章推荐
- vc 6.0, Visual Studio.net 2005 , VC++ 6.0的MSDN下载链接
- VC++.Net2005的一些常识(转)
- VC++.NET2005中DataGridView控件中加入下拉框的编程实现
- VC++.NET2005中DataGridView控件中加入下拉框的编程实现
- 也谈VC++.NET2005中DataGrid控件的键盘事件响应
- VC.NET 2005 和VC6 中ON_STN_DBLCLK 消息映射格式不同
- VC++.NET 2005 几个比较难缠的问题及其解决方法(转)
- VC++.Net2005的一些常识(转)
- vc2005 mfc 使用ado.net
- 也谈VC++.NET2005中DataGrid控件的键盘事件响应
- VS 2005中VC.NET遇到的几个问题
- VC++.Net2005---叶帆学习初体验
- VC++ .net 2005运行库解析
- VC++.net 2005 SmartDevice 屏幕转向
- VC++.Net2005---叶帆学习初体验
- VC++.Net2005的一些常识
- VC++.Net2005---叶帆学习初体验
- VC++.NET2005中DataGridView控件中加入下拉框的编程实现
- VC/.NET,SQL SERVER 2000/2005的选择
- VC.net 2005 中CString转成char *