Type correspondence between C # and C + + __c++

Source: Internet
Author: User
Tags object object

DLL function prototypes in C + + are
extern "C" __declspec (dllexport) bool method name one (const char* variable name 1, unsigned char* variable name 2)
extern "C" __declspec (dllexport) bool Method name two (const unsigned char* variable name 1, char* variable name 2)
C # Call the C + + DLL to compile all data type conversions, there may be duplication or multiple scenarios, test yourself
C++:handle (void *)--C#:system.intptr
C++:byte (unsigned char)--C#:system.byte
C++:short (short)--c#:system.int16
C++:word (unsigned short)--c#:system.uint16
C++:int (INT)--c#:system.int16
C++:int (INT)--C#:system.int32
C++:uint (unsigned int)--c#:system.uint16
C++:uint (unsigned int)--C#:system.uint32
C++:long (LONG)--C#:system.int32
C++:ulong (unsigned long)--C#:system.uint32
C + +:D Word (unsigned long)-C#:system.uint32
C + +:D ecimal--c#:system.decimal
C++:bool (Long)--C#:system.boolean
C++:char (CHAR)--C#:system.char
C++:lpstr (char *)--c#:system.string
C++:LPWSTR (wchar_t *)--c#:system.string
C++:LPCSTR (const char *)--c#:system.string
C++:LPCWSTR (const wchar_t *)--c#:system.string
C + +:P Cahr (char *)--c#:system.string
c++:bstr--c#:system.string
C++:float (FLOAT)--C#:system.single
C + +:D ouble (DOUBLE)--c#:system.double
c++:variant--C#:system.object
C + +:P byte (byte *)--c#:system.byte[]
c++:bstr--C#:stringbuilder
c++:lpctstr--C#:stringbuilder
c++:lpctstr--c#:string
c++:lptstr--C#:[marshalas (UNMANAGEDTYPE.LPTSTR)] string
C++:LPTSTR output Variable name--c#:stringbuilder Output variable name
c++:lpcwstr--c#:intptr
c++:bool--C#:bool
c++:hmodule--c#:intptr
c++:hinstance--c#:intptr
C + +: Structural body--C #:p ublic struct Structure {};
C + +: struct * * Variable name--c#:out variable name//c# in advance the name of the variable after a struct is instantiated
C + +: struct & variable name--c#:ref structural body variable name

c++:word--C#:ushort
C + +:D word--c#:uint
C + +:D word--c#:int
c++:uchar--C#:int
c++:uchar--C#:byte
c++:uchar*--c#:string
c++:uchar*--c#:intptr
c++:guid--C#:guid
c++:handle--c#:intptr
c++:hwnd--c#:intptr
C + +:D word--c#:int
c++:colorref--C#:uint

c++:unsigned char--C#:byte
c++:unsigned Char *--c#:ref byte
c++:unsigned Char *--C#:[marshalas (UnmanagedType.LPArray)] byte[]
c++:unsigned Char *--C#:[marshalas (UnmanagedType.LPArray)] Intptr
c++:unsigned Char &--c#:ref byte
c++:unsigned char variable name--c#:byte variable name
c++:unsigned short variable name--c#:ushort variable name
c++:unsigned int variable name--c#:uint variable name
c++:unsigned Long variable name--c#:ulong variable name
C++:char variable name--c#:byte variable name//c++ a character is represented in a byte, and a character in C # is represented in two bytes
C++:char array name [array size]--C#:marshalas (unmanagedtype.byvaltstr, SizeConst = array size)] public string array name; UShort
C++:char *--c#:string//Incoming parameters
C++:char *--c#:stringbuilder//Outgoing parameters
C++:char * Variable Name--c#:ref string variable name
C++:char * Input variable name--c#:string input variable name
C++:char * Output Variable name--C#:[marshalas (UNMANAGEDTYPE.LPSTR)] StringBuilder output variable name
C++:char **--c#:string
C++:char * * Variable name--c#:ref string variable name
C++:const Char *--c#:string
c++:char[]--c#:string
C++:char variable name [array size]--C#:[marshalas (unmanagedtype.byvaltstr,sizeconst= array size)] public string variable name;
C++:struct Structural Body Name * Variable name--c#:ref structural body name Variable name
C + +: Delegate variable name--C #: Delegate variable name
c++:int--C#:int
c++:int--C#:ref int
C++:int &--C#:ref int
C++:int *--c#:ref int//c# must be defined before calling int variable name = 0;
C + +:* int--c#:intptr
C++:int32 piptr *--c#:int32[]
C++:float piptr *--c#:float[]

C + +:d ouble** array name--C#:ref double array name
C + +:d ouble*[] Array name--C#:ref double array name
c++:long--C#:int
c++:ulong--C#:int

The byte variable name = new byte () is defined before c++:uint8 *--c#:ref byte//c#;

c++:handle--c#:intptr
c++:hwnd--c#:intptr

C++:void *--C#:intptr
C++:void * user_obj_param--c#:intptr User_obj_param
C++:void * Object Name-C #:([MarshalAs (unmanagedtype.asany)]object object name

C++:char, INT8, SBYTE, char--c#:system.sbyte
C++:short, short int, INT16, short--c#:system.int16
C++:int, long, long int, INT32, LONG32, BOOL, int--C#:system.int32
C++:__int64, INT64, longlong--C#:system.int64
c++:unsigned Char, UINT8, Uchar, byte--c#:system.byte
c++:unsigned short, UINT16, USHORT, WORD, ATOM, WCHAR, __wchar_t--c#:system.uint16
c++:unsigned, unsigned int, UINT32, ULONG32, DWORD32, ULONG, DWORD, uint--C#:system.uint32
C++:unsigned __int64, UINT64, Dwordlong, ulonglong--C#:system.uint64
C++:float, float--C#:system.single
C + +:d ouble, long double, double--c#:system.double
Win32 types--CLR Type

struct need to redefine a struct in C #
The callback callback function needs to be encapsulated in a delegate, delegate static extern int Funcallback (string str);
unsigned char** ppimage replaced with IntPtr ppimage
int& nwidth replaced with ref int nwidth
int*, Int&, then all can be ref int corresponding
The double needle refers to the type parameter, which can be IntPtr with ref
function pointers use C + +: TypeDef double (*FUN_TYPE1) (double); Corresponds to the C #:p ublic delegate Double fun_type1 (double);
char* Operations C + +: char*; corresponding to C#:stringbuilder;
Use pointers in C #: Add unsafe where you want to use pointers

unsigned char corresponds to public byte
/*
* typedef void (CALLBACKFUN1W) (wchar_t, void* parg);
* typedef void (CALLBACKFUN1A) (char, void* parg);
* BOOL Bioprint_sensor_api dllFun1 (CALLBACKFUN1 pCallbackFun1, void* parg);
* Call mode is
* [Unmanagedfunctionpointer (CALLINGCONVENTION.CDECL)]
* Public delegate void CallbackFunc1 ([MarshalAs (UNMANAGEDTYPE.LPWSTR)] StringBuilder strName, IntPtr parg);
*
*
*/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.