C與net數(shù)據(jù)類型對照_第1頁
C與net數(shù)據(jù)類型對照_第2頁
C與net數(shù)據(jù)類型對照_第3頁
C與net數(shù)據(jù)類型對照_第4頁
C與net數(shù)據(jù)類型對照_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、C+與.net數(shù)據(jù)類型對應(yīng)表 (在硬件開發(fā)時(shí)很重要)C#調(diào)用DLL文件時(shí)參數(shù)對應(yīng)表Wtypes.h 中的非托管類型非托管 C 語言類型托管類名說明HANDLEvoid*System.IntPtr32 位BYTEunsigned charSystem.Byte8 位SHORTshortSystem.Int1616 位WORDunsigned shortSystem.UInt1616 位INTintSystem.Int3232 位UINTunsigned intSystem.UInt3232 位LONGlongSystem.Int3232 位BOOLlongSystem.Int3232 位DWOR

2、Dunsigned longSystem.UInt3232 位ULONGunsigned longSystem.UInt3232 位CHARcharSystem.Char用 ANSI 修飾。LPSTRchar*System.String 或 System.StringBuilder用 ANSI 修飾。LPCSTRConst char*System.String 或 System.StringBuilder用 ANSI 修飾。LPWSTRwchar_t*System.String 或 System.StringBuilder用 Unicode 修飾。LPCWSTRConst wchar_t*Sy

3、stem.String 或 System.StringBuilder用 Unicode 修飾。FLOATFloatSystem.Single32 位DOUBLEDoubleSystem.Double64 位  類別類名說明Visual Basic 數(shù)據(jù)類型C# 數(shù)據(jù)類型C+ 托管擴(kuò)展數(shù)據(jù)類型JScript 數(shù)據(jù)類型整數(shù)Byte8 位的無符號整數(shù)。BytebytecharByte   SByte8 位的有符號整數(shù)。 不符合 CLS。SByte 無內(nèi)置類型。sbytesigned charSByte   Int1616

4、 位的有符號整數(shù)。Shortshortshortshort   Int3232 位的有符號整數(shù)。Integerintint - 或 -longint   Int6464 位的有符號整數(shù)。Longlong_int64long   UInt1616 位的無符號整數(shù)。 不符合 CLS。UInt16 無內(nèi)置類型。ushortunsigned shortUInt16   UInt3232 位的無符號整數(shù)。 不符合 CLS。UInt32 無內(nèi)置類型。uintunsigned int -

5、或 -unsigned longUInt32   UInt6464 位的無符號整數(shù)。 不符合 CLS。UInt64 無內(nèi)置類型。ulongunsigned _int64UInt64浮點(diǎn)Single單精度(32 位)浮點(diǎn)數(shù)字。Singlefloatfloatfloat   Double雙精度(64 位)浮點(diǎn)數(shù)字。Doubledoubledoubledouble邏輯Boolean布爾值(真或假)。Booleanboolboolbool其他CharUnicode(16 位)字符。Charcharwchar_tchar  

6、 Decimal96 位十進(jìn)制值。DecimaldecimalDecimalDecimal   IntPtr大小取決于基礎(chǔ)平臺(32 位平臺上為 32 位值,64 位平臺上為 64 位值)的有符號整數(shù)。IntPtr 無內(nèi)置類型。IntPtr 無內(nèi)置類型。IntPtr 無內(nèi)置類型。IntPtr   UIntPtr大小取決于基礎(chǔ)平臺的無符號整數(shù)(32 位平臺上為 32 位值,64 位平臺上為 64 位值)。 不符合 CLS。UIntPtr 無內(nèi)置類型。UIntPtr 無內(nèi)置類型。UIntPtr 無內(nèi)置類型。UIntPtr類對象O

7、bject對象層次結(jié)構(gòu)的根。ObjectobjectObject*Object   StringUnicode 字符的不變的定長串。StringstringString*StringC# 與 C+ 數(shù)據(jù)類型比較及結(jié)構(gòu)體轉(zhuǎn)換作者:菜鳥的宣言  來源:博客園  發(fā)布時(shí)間:2009-10-27 17:33  閱讀:583 次  原文鏈接   收藏   C+          

8、;  C#=WORD            ushortDWORD            uintUCHAR            int/byte   大部分情況都可以使用int代替,而如果需要嚴(yán)格對齊的話則應(yīng)該用bytebyte UCHAR*     &#

9、160;      string/IntPtrunsigned char*         MarshalAs(UnmanagedType.LPArray)byte/?(Intptr)char*            stringLPCTSTR            stringLPTSTR

10、0;           MarshalAs(UnmanagedType.LPTStr) stringlong            intulong               uintHandle          

11、  IntPtrHWND            IntPtrvoid*            IntPtrint            intint*            ref int*int   

12、;         IntPtrunsigned int        uintCOLORREF                uint   API與C#的數(shù)據(jù)類型對應(yīng)關(guān)系表API數(shù)據(jù)類型類型描述C#類型API數(shù)據(jù)類型類型描述C#類型WORD16位無符號整數(shù)ushortCHAR字符charLONG32位無符號

13、整數(shù)intDWORDLONG64位長整數(shù)longDWORD32位無符號整數(shù)uintHDC設(shè)備描述表句柄intHANDLE句柄,32位整數(shù)intHGDIOBJGDI對象句柄intUINT32位無符號整數(shù)uintHINSTANCE實(shí)例句柄intBOOL32位布爾型整數(shù)boolHWM窗口句柄intLPSTR指向字符的32位指針stringHPARAM32位消息參數(shù)intLPCSTR指向常字符的32位指針StringLPARAM32位消息參數(shù)intBYTE字節(jié)byteWPARAM32位消息參數(shù)int   BOOL=System.Int32BOOLEAN=System.In

14、t32BYTE=System.UInt16CHAR=System.Int16COLORREF=System.UInt32DWORD=System.UInt32DWORD32=System.UInt32DWORD64=System.UInt64FLOAT=System.FloatHACCEL=System.IntPtrHANDLE=System.IntPtrHBITMAP=System.IntPtrHBRUSH=System.IntPtrHCONV=System.IntPtrHCONVLIST=System.IntPtrHCURSOR=System.IntPtrHDC=System.IntPtr

15、HDDEDATA=System.IntPtrHDESK=System.IntPtrHDROP=System.IntPtrHDWP=System.IntPtrHENHMETAHHFONT=System.IntPtrHGDIOBJ=System.IntPtrHGLOBAL=System.IntPtrHHOOK=System.IntPtrHICON=System.IntPtrHIMAGELIST=System.IntPtrHIMC=System.IntPtrHINSTANCE=System.IntPtrHKEY=System.IntPtrHLOCAL=System.IntPtrHMENU=Syste

16、m.IntPtrHMETAHMODULE=System.IntPtrHMONITOR=System.IntPtrHPALETTE=System.IntPtrHPEN=System.IntPtrHRGN=System.IntPtrHRSRC=System.IntPtrHSZ=System.IntPtrHWINSTA=System.IntPtrHWND=System.IntPtrINT=System.Int32INT32=System.Int32INT64=System.Int64LONG=System.Int32LONG32=System.Int32LONG64=System.Int64LONG

17、LONG=System.Int64LPARAM=System.IntPtrLPBOOL=System.Int16LPBYTE=System.UInt16LPCOLORREF=System.UInt32LPCSTR=System.StringLPCTSTR=System.StringLPCVOID=System.UInt32LPCWSTR=System.StringLPDWORD=System.UInt32LPHANDLE=System.UInt32LPINT=System.Int32LPLONG=System.Int32LPSTR=System.StringLPTSTR=System.Stri

18、ngLPVOID=System.UInt32LPWORD=System.Int32LPWSTR=System.StringLRESULT=System.IntPtrPBOOL=System.Int16PBOOLEAN=System.Int16PBYTE=System.UInt16PCHAR=System.CharPCSTR=System.StringPCTSTR=System.StringPCWCH=System.UInt32PCWSTR=System.UInt32PDWORD=System.Int32PFLOAT=System.FloatPHANDLE=System.UInt32PHKEY=

19、System.UInt32PINT=System.Int32PLCID=System.UInt32PLONG=System.Int32PLUID=System.UInt32PSHORT=System.Int16PSTR=System.StringPTBYTE=System.CharPTCHAR=System.CharPTSTR=System.StringPUCHAR=System.CharPUINT=System.UInt32PULONG=System.UInt32PUSHORT=System.UInt16PVOID=System.UInt32PWCHAR=System.CharPWORD=S

20、ystem.Int16PWSTR=System.StringREGSAM=System.UInt32SC_HANDLE=System.IntPtrSC_LOCK=System.IntPtrSHORT=System.Int16SIZE_T=System.UInt32SSIZE_=System.UInt32TBYTE=System.CharTCHAR=System.CharUCHAR=System.ByteUINT=System.UInt32UINT32=System.UInt32UINT64=System.UInt64ULONG=System.UInt32ULONG32=System.UInt3

21、2ULONG64=System.UInt64ULONGLONG=System.UInt64USHORT=System.UInt16WORD=System.UInt16WPARAM=System.IntPtr<-補(bǔ)充->Wtypes.h 中的非托管類型    非托管C 語言類型    托管類名       說明 HANDLE            

22、            void*                   System.IntPtr  32 位 BYTE              &

23、#160;             unsigned char       System.Byte    8 位 SHORT                     &#

24、160;   short                    System.Int16   16 位 WORD                    

25、0;     unsigned short      System.UInt16  16 位 INT                               int 

26、                      System.Int32   32 位 UINT                       &

27、#160;     unsigned int         System.UInt32  32 位 LONG                            long

28、60;                   System.Int32   32 位 BOOL                         

29、0;  long                    System.Int32   32 位 DWORD                      

30、  unsigned long       System.UInt32  32 位 ULONG                          unsigned long      Sys

31、tem.UInt32  32 位 CHAR                            char                 

32、   System.Char    用 ANSI 修飾。 LPSTR                           char*            &#

33、160;     System.String 或 System.StringBuilder 用 ANSI 修飾。 LPCSTR                         Const char*         System.

34、String 或 System.StringBuilder 用 ANSI 修飾。 LPWSTR                        wchar_t*             System.String 或 System.Strin

35、gBuilder 用 Unicode 修飾。 LPCWSTR                      Const wchar_t*    System.String 或 System.StringBuilder 用 Unicode 修飾。 FLOAT       &#

36、160;                   Float                    System.Single 32 位 DOUBLE      &

37、#160;                 Double                 System.Double 64 位   C/C+中的結(jié)構(gòu)類型數(shù)據(jù)在C#下的轉(zhuǎn)換 在做項(xiàng)目移植的時(shí)候,經(jīng)常會碰到數(shù)據(jù)類型的轉(zhuǎn)換,而我這一次碰到的是C/

38、C+中的結(jié)構(gòu)怎樣轉(zhuǎn)換到C#。折騰了一個(gè)晚上終于有一個(gè)完美的方案。例如我們在C/C+下的結(jié)構(gòu)數(shù)據(jù)如下:typedef struct     char sLibName 256 ;    char sPathToLibrary 256 ;    INT32        iEntries;    INT32        iUsed;  &#

39、160; UINT16    iSort;    UINT16    iVersion;    BOOLEAN    fContainsSubDirectories;    INT32        iReserved; LIBHEADER;我們想把它轉(zhuǎn)成C#下的結(jié)構(gòu)類型如下:    public struct LIBHEADE

40、R            public char sLibName;        public char sPathToLibrary;        public Int32 iEntries;        public Int32 iUsed;        p

41、ublic UInt16 iSort;        public UInt16 iVersion;        public Boolean fContainsSubDirectories;        public Int32 iReserved;    看上去好像沒問題了,呵呵呵,其實(shí)這樣是不行的,我們得再給C#編譯器一些信息,告訴它一些字符數(shù)組的大小。然后它們在C#下面長得樣

42、子就變成這樣:    StructLayout(LayoutKind.Sequential)    public struct LIBHEADER            MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)        public char sLibName;     

43、0;  MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)        public char sPathToLibrary;        public Int32 iEntries;        public Int32 iUsed;        public UInt16 iSort

44、;        public UInt16 iVersion;        public Boolean fContainsSubDirectories;        public Int32 iReserved;    然后寫一個(gè)函數(shù)負(fù)責(zé)轉(zhuǎn)換。public StructType ConverBytesToStructure<StructType>(byte bytes

45、Buffer)                    / 檢查長度。            if (bytesBuffer.Length != Marshal.SizeOf(typeof(StructType)               

46、             throw new ArgumentException("bytesBuffer參數(shù)和structObject參數(shù)字節(jié)長度不一致。");                        IntPtr bufferHandler = Marshal.AllocHGlobal(bytesB

47、uffer.Length);            for (int index = 0; index < bytesBuffer.Length; index+)                            Marshal.WriteByte(bufferHandler, index, bytesBufferindex);                        StructType structObject = (StructTyp

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論