首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

C/C# 托管與非托管代碼變數類型對照表

     編輯:關於C語言

下表列出 Win32 API (Wtypes.h) 與 C 風格函數常用資料類型,以及對應的 .NET 內建值類型/類別。第三欄為托管代碼對應類型,某些情況可用大小相同的類型替代。

Wtypes.h 非托管類型非托管 C 型別托管類型說明
handlevoid*System.IntPtr32 位元
byteunsigned charSystem.Byte8 位元
shortshortSystem.Int1616 位元
Wordunsigned shortSystem.UInt1616 位元
intintSystem.Int3232 位元
uintunsigned intSystem.UInt3232 位元
longlongSystem.Int3232 位元 (Win32 long 為 32 位)
boollongSystem.Int3232 位元 (Win32 BOOL 為 4 位元組)
dWordunsigned longSystem.UInt3232 位元
ulongunsigned longSystem.UInt3232 位元
charcharSystem.Char需加 MarshalAs(UnmanagedType.U1) 或 ANSI 修飾
lpstrchar*System.String / StringBuilderANSI 字串指標
lpcstrconst char*System.String / StringBuilderANSI 常數字串指標
lpwstrwchar_t*System.String / StringBuilderUnicode 字串指標
lpcwstrconst wchar_t*System.String / StringBuilderUnicode 常數字串指標
floatfloatSystem.Single32 位元
doubledoubleSystem.Double64 位元

使用提醒

  • 平台呼叫 (DllImport) 時務必對應正確 MarshalAs 屬性,特別是字串與布林型別。
  • IntPtr 用於指標/控制代碼,32/64 位元自動適配。
  • Win32 long 與 BOOL 均為 32 位元,對應 Int32,切勿誤用 Int64。
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved