아래의 속성 수정

프로젝트->속성->구성속성->일반->프로젝트 기본값->공용 언어 런타임 지원 = 공용 언어 런타임 지원(/clr)

(컴파일 하면 에러 발생하면 하나하나씩 컴파일 옵션 처리해주면 된다)

 

#include <iostream>

#include <stdlib.h>

#include <string.h>

#include "msclr\marshal_cppstd.h" 

 

using std::cout;

using std::endl;

using std::string;

 

using namespace System;

using namespace msclr::interop;

 

void main()

{

         String ^s = "abc";

        

         string unmanaged = marshal_as<std::string>(s->ToUpper());

 

         cout << unmanaged << endl;

}

 

 

'기타 > C++' 카테고리의 다른 글

Native C++에서 C++/CLR 클래스 사용하기  (0) 2015.03.06
콘솔싸이월드  (0) 2011.01.20
비트학생관리  (0) 2011.01.20

 

C++/CLR 클래스

 

Calculrator.cpp

#include "Calculator.h"

 

 

Calculator::Calculator()

{

}

 

 

int Calculator::Sum(int aint b)

{

         return a + b;

}

 

int Calculator::Max(int aint b)

{

         return System::Math::Max(ab);

}

 

string Calculator::HelloWorld(string text)

{

         return text.append("\tHello World!");

}

 

 

 

Calculrator.h

#pragma once

 

#include <string>

 

using std::string;

 

ref class Calculator

{

public:

         Calculator();

         int Sum(int a, int b);

         int Max(int a, int b);

         string HelloWorld(string text);   

};

 

 

 

C++/CLR Native 랩퍼 클래스

 

CalculratorWrapper.cpp

 

#include "CalculatorWrapper.h"

 

CalculatorWrapper::CalculatorWrapper()

{

         _managedObject = gcnew Calculator();

}

CalculatorWrapper::~CalculatorWrapper()

{

 

}

 

int CalculatorWrapper::Sum(int aint b)

{

         return _managedObject->Sum(ab);

}

int CalculatorWrapper::Max(int aint b)

{

         return _managedObject->Max(ab);

}

string CalculatorWrapper::HelloWorld(string text)

{

         return _managedObject->HelloWorld(text);

}

 

ICalculatorWrapper        *ICalculatorWrapper::CreateInstance()

{

         return ((ICalculatorWrapper *)new CalculatorWrapper());

}

 

void ICalculatorWrapper::Destroy(ICalculatorWrapper *instance)

{

         delete instance;

}

 

 

CalculratorWrapper.h

#pragma once

 

#include <vcclr.h>

#include <string>

#include "ICalculatorWrapper.h"

#include "Calculator.h"

 

 

class DLLAPI CalculatorWrapper : ICalculatorWrapper

{

private:

         gcroot<Calculator ^>  _managedObject;

public:

         CalculatorWrapper();

         ~CalculatorWrapper();

         int Sum(int a, int b);

         int Max(int a, int b);

         string HelloWorld(string text);

};

※ gcroot 템플릿 이용해서 C++/CLR 개체 사용

 

 

C++/CLR 랩퍼 인터페이스

ICalculratorWrapper.h

 

#pragma once

 

#include <string>

using std::string;

 

#ifdef CPLUSPLUSCLR_EXPORTS

#define DLLAPI  __declspec(dllexport)

#else

#define DLLAPI  __declspec(dllimport)

#pragma comment (lib"CPlusPlusCLR.lib"

#endif

 

class DLLAPI ICalculatorWrapper

{

public:

         virtual int Sum(int a, int b) = 0;

         virtual string HelloWorld(string text) = 0;

         virtual int Max(int a, int b) = 0;

         static ICalculatorWrapper *CreateInstance();

         static void      Destroy(ICalculatorWrapper *instance);

};

 

 

 

랩퍼 클래스를 이용해 사용하는 Native 클래스

 

#include <iostream>
#include "ICalculatorWrapper.h"
 
using std::cout;
using std::endl;
 
void main()
{
	ICalculatorWrapper *wrapper = ICalculatorWrapper::CreateInstance();
 
	int sum = wrapper->Sum(12, 12);
	int max = wrapper->Max(100, 9);
	string text = wrapper->HelloWorld("test");
	
	cout << sum << endl;
	cout << text << endl;
 
	ICalculatorWrapper::Destroy(wrapper);
} 

 

'기타 > C++' 카테고리의 다른 글

Native C++에서 C++/CLR 클래스 사용하기(CLR 옵션)  (0) 2015.03.06
콘솔싸이월드  (0) 2011.01.20
비트학생관리  (0) 2011.01.20

1. RockMargin

 

 

 - vs2010, vs2012, vs2013 지원 (2014.12.24 현재)

 - 전시 중인 영역을 우측에서 확인

 - 더블 클릭하여 선택시 단어 현재 사용중인 영역 우측에 빨간색으로 표시

 - 책갈피, 중단점 우측 표시

 

 

https://visualstudiogallery.msdn.microsoft.com/1b0d7360-40dd-447e-8bef-90e2cf52f683

 

 

2.1 Productivity Power Tools VS2010

2.1 Productivity Power Tools VS2012

2.2 Productivity Power Tools VS2013

 - vs2010, vs2012, vs2013 지원(2014.12.24 현재)

 - {} 컬럼 그리드 표시

 - 솔루션의 사용중이지 않은 Using 제거

 - 마우스 Middle 클릭 스크롤링 지원

 - 닫았던 문서 다시 띄우기(Ctrl + Shift + Z)

 - 정의로 이동(Ctrl + 클릭)

 - 정렬

 

 

 - 솔루션 에러 표시

 

+ Recent posts