>[2.2] コンパイラ名 : VC++ 2008EE
VC++ 2008EEのmsclrディレクトリにはmarshal.hがないようですね。VC++ 2008 pro にはあるようです。
VS2007Communityには存在して下記のように実行できます。
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.10.25017\include\msclr\marshal.h
に存在する
c1.cpp
コード:
// list-11-3-2.cpp : メイン プロジェクト ファイルです。
//#include "stdafx.h" <=== プリコンパイル・ヘッダ使用しない
#include <iostream>
#include <msclr/marshal.h> // マーシャリング用
using namespace System;
//using namespace std; <=== c1.cpp(11): error C2976: 'std::array': テンプレート 引数の数が少なすぎますエラー をさける
using namespace msclr::interop; // マーシャリング用
int main(array<System::String ^> ^args) // c1.cpp(11): error C2976: 'std::array': テンプレート 引数の数が少なすぎますエラー
{
char * cstr = "Hello/char";
std::cout << "char * --> " << cstr << std::endl;
String ^ Str = marshal_as<String ^>(cstr);
Console::WriteLine("String --> " + Str);
String ^ Str1 = %String("Hello/String");
Console::WriteLine("String --> " + Str1);
marshal_context ^ context = gcnew marshal_context();
const char * cstr1 = context->marshal_as<const char *>(Str1);
std::cout << "char * --> " << cstr1 << std::endl;
Console::WriteLine();
Console::WriteLine("Enterキーを押して終了。");
Console::ReadLine();
return 0;
}
c.bat
コード:
rem コンパイル後リンク
cl /clr c1.cpp
rem 実行結果
c1.exe
実行結果
コード:
D:\z17c\clr\0923>c
D:\z17c\clr\0923>rem コンパイル後リンク
D:\z17c\clr\0923>cl /clr c1.cpp
Microsoft(R) C/C++ Optimizing Compiler Version 19.10.25019
for Microsoft(R) .NET Framework Version 4.07.2110.0
Copyright (C) Microsoft Corporation. All rights reserved.
c1.cpp
Microsoft (R) Incremental Linker Version 14.10.25019.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:c1.exe
c1.obj
D:\z17c\clr\0923>rem 実行結果
D:\z17c\clr\0923>c1.exe
char * --> Hello/char
String --> Hello/char
String --> Hello/String
char * --> Hello/String
Enterキーを押して終了。