cht電腦資訊LanguageC/C++
adm Find login register

混合 Managed and Unmanaged Code

eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
1subject: 混合 Managed and Unmanaged CodePromote 0 Bookmark 12008-02-27quote  

最近在 Windows Visual Studio 開發,不知道什麼時候加入了 ^ 這個怪東西,也就是可以 garbage collection 的 managed variable。.NET 的 environment 很多這種 managed variables,想用以前熟悉的 libc function 如 strncmp 結果都不行,因為這些是 Unmanaged function.  真是麻煩。呐喊

edited: 1
eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
2subject: Promote 0 Bookmark 02008-03-06quote  

本來想用 .NET 裡面的 function,很多 function 的 parameter 都是用 String,
更讓人發瘋的是 String 的 constructor parameter 只能用 wchar_t,16 bit 的 character (UTF-16) ??難道 .NET 全部是用 UTF-16

搞不懂的是 UTF-16 的 char 並不是 16-bit ,而是 16 or 32 bit。所以是否真的有把問題簡化 ?

Visual C++
// Unicode Mathematical operators
wchar_t charArray1[4] = {L'\x2200',L'\x2202',L'\x200F',L'\x2205'};
wchar_t * lptstr1 =  &charArray1[ 0 ];
String^ wszMathSymbols = gcnew String( lptstr1 );
// Unicode Letterlike Symbols
wchar_t charArray2[4] = {L'\x2111',L'\x2118',L'\x2122',L'\x2126'};
wchar_t * lptstr2 =  &charArray2[ 0 ];
String^ wszLetterLike = gcnew String( lptstr2 );
// Compare Strings - the result is false
Console::WriteLine( String::Concat( L"The Strings are equal? ", (0 == String::Compare( wszLetterLike, wszMathSymbols ) ? (String^)"TRUE" : "FALSE") ) );
edited: 1
企鵝狂
joined: 2008-04-01
posted: 185
promoted: 20
bookmarked: 7
3subject: Promote 0 Bookmark 02008-05-07quote  

可以把兩種code寫在一起

#pragma managed
managedHello(){
Console::Out::Write("Hello");
}

#pragma unmanaged
unmanagedHello(){
std::cout<<"Hello";
}

eliu

joined: 2007-08-09
posted: 11468
promoted: 617
bookmarked: 187
新竹, 台灣
4subject: Promote 0 Bookmark 02008-05-07quote  


問題是 function  的 variable 如果是宣告成 managed variable,call function 傳進去的 variable 就一定要是 managed variable.

CC: Windows
cht電腦資訊LanguageC/C++
adm Find login register
views:15422