Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
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.
Posted
Comments
Philippe Mori 17-Nov-14 0:22am    
A string is essentially an array of characters with some extra information so your example is incorrect Either std::string is used or an array of char...

 
Share this answer
 
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
 
Share this answer
 
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
 
Share this answer
 
Comments
[no name] 16-Nov-14 14:05pm    
unusable +1 (+?)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900