using namespace System::Runtime::InteropServices;
の宣言追加が必要です。
int leng;
char *cptr;
char buf[64];
String ^str1;
String ^str2;
String ^str3;
leng = 0;
str1 = gcnew String("string_moji");
str2 = gcnew String("");
// (String*) -> char
memset(buf, 0x00, sizeof(buf));
cptr = (char *)(void *)Marshal::StringToHGlobalAnsi(str1);
leng = strlen(cptr);
if(leng < sizeof(buf) )
strncpy(buf, cptr, leng);
else
strncpy(buf, cptr, (sizeof(buf)-1));
Marshal::FreeHGlobal((System::IntPtr)cptr); //アンマネージ メモリから割り当てられたメモリを解放
// char -> String
str2 = Marshal::PtrToStringAnsi((System::IntPtr)buf);
str3 = gcnew String(buf);
( WindowsアプリケーションForm (Framework3.5) VS2008 VC++環境でのお話しです。 )