将C#类型更改为c ++ [英] change C# type to c++

查看:80
本文介绍了将C#类型更改为c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,下面:

c#:string filePath =c:\\tu.txt;

c ++:string filePath [] =c :\\tu.txt;



如何将c#类型更改为c ++,因为我使用dllimport调用c ++函数,函数参数是字符串filePath [] =c:\\ tu.txt;那么如何改变或如何解决?



谢谢。

For example,below:
c#: string filePath = "c:\\tu.txt";
c++: string filePath[] = "c:\\tu.txt";

how to change c# type to c++,because i use dllimport to invoke the c++ function,the function parameter is string filePath[] = "c:\\tu.txt";then how to change or how to solve?

thanks.

推荐答案

查看这些链接。



Win32 API:C ++ to .NET [ ^ ]



http://msdn.microsoft .com / en-in / library / 4xwz0t37(v = vs.90).aspx [ ^ ]
Check these links.

Win32 API: C++ to .NET[^]

http://msdn.microsoft.com/en-in/library/4xwz0t37(v=vs.90).aspx[^]


如上所述,这个问题毫无意义。您不是在谈论C ++ / CLI,而是关于C ++,它以本机平台为目标,而不是.NET。大多数类型不同,无法比较;它们不能在P / Invoke之外的任何地方一起工作。



你的问题只在一个方面有意义:类型是函数参数。当您使用P / Invoke调用C ++函数时,某些类型是封送。默认情况下,按值 char * char [] )参数被编组为 System.String ,并通过引用参数编组为 System.Text.StringBuilder 。 (这是因为 System.String immutable ;而 System.Text.StringBuilder 可以被视为字符串的可变版本。)



-SA
The question, as it is stated, makes no sense. You are not talking about C++/CLI, but about C++, which target native platforms, not .NET. Most types are different and cannot be compared; they don't work together anywhere beyond P/Invoke.

Your question makes sense only in one aspect: types are function parameters. When you call a C++ function using P/Invoke, some types are marshaled. By default, a by-value char* (char[]) parameter is marshaled as System.String, and by reference parameter is marshaled as System.Text.StringBuilder. (This is because System.String is immutable; and System.Text.StringBuilder can be considered as a mutable version of string.)

—SA


C ++类型C#类型大小

BOOL bool 1字节

字节字节1字节

CHAR字节1字节

DECIMAL十进制16字节

DOUBLE双8字节

DWORD uint,UInt32 4字节

FLOAT浮点数,单个4字节

INT,签名int int,Int32 4 bytes

INT16,signed short int short,Int16 2 bytes

INT32,signed int int,int32 4 bytes

INT64 long,Int64 8字节

LONG int,Int32 4字节s

LONG32,signed int int,Int32 4 bytes

LONG64 long,Int64 8 bytes

LONGLONG long,Int64 8 bytes

SHORT,签名短int短,Int16 2字节

UCHAR,无符号字节1字节

UINT,unsigned int uint,UInt32 4字节

UINT16 ushort,UInt16 2字节

UINT32,unsigned int uint,UInt32 4字节

UINT64 ulong,UInt64 8字节
C++ Type C# Type Size
BOOL bool 1 byte
BYTE byte 1 byte
CHAR byte 1 byte
DECIMAL Decimal 16 bytes
DOUBLE double 8 bytes
DWORD uint, UInt32 4 bytes
FLOAT float, single 4 bytes
INT, signed int int, Int32 4 bytes
INT16, signed short int short, Int16 2 bytes
INT32, signed int int, Int32 4 bytes
INT64 long, Int64 8 bytes
LONG int, Int32 4 bytes
LONG32, signed int int, Int32 4 bytes
LONG64 long, Int64 8 bytes
LONGLONG long, Int64 8 bytes
SHORT, signed short int short, Int16 2 bytes
UCHAR, unsigned char byte 1 byte
UINT, unsigned int uint, UInt32 4 bytes
UINT16 ushort, UInt16 2 bytes
UINT32, unsigned int uint, UInt32 4 bytes
UINT64 ulong, UInt64 8 bytes


这篇关于将C#类型更改为c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆