Hello There,
Finally I have decided to rewrite an API from C++ to C#.
So far all worked good but some things I do not really understand in C#. Maybe somebody can help me out!
Imagine I have the following Code in C++:
what would be the equivalent in C#? e.g. in respect to this
void* which indicates the address of some data of unknown type?
code:--------------------------------------------------------------------------------
bool Command::Send(void* PacketStart, long PacketSize)
{
if (!socket.Send(PacketStart, PacketSize))
return false;
return true;
}
--------------------------------------------------------------------------------
How would you translate such a C++ struct?
create a class?
What about the array allocation?
code:--------------------------------------------------------------------------------
struct GetRT
{
struct BRTInfo;
enum EType Type;
double Offset;
unsigned short Name[32]; };
--------------------------------------------------------------------------------
What can I do to have constants in a separate file.
consts are no longer available i guess...
In C++ :
code:--------------------------------------------------------------------------------
// Unit-Conversion related constants:
const double LengthFactor = 1000.0;
--------------------------------------------------------------------------------
What about these adress opertaors and sizeof function
Can i use the System.Runtime.InteropServices.Marshal.SizeOf() Method?
code:--------------------------------------------------------------------------------
bool inline Initi() {CInit Data; return SP(&Data.DataPacket, sizeof(Data.DataPacket));}
--------------------------------------------------------------------------------
I really do not understand how to handle my pointers in c#.
Any help is greatly appreciated,
stonee
Finally I have decided to rewrite an API from C++ to C#.
So far all worked good but some things I do not really understand in C#. Maybe somebody can help me out!
Imagine I have the following Code in C++:
what would be the equivalent in C#? e.g. in respect to this
void* which indicates the address of some data of unknown type?
code:--------------------------------------------------------------------------------
bool Command::Send(void* PacketStart, long PacketSize)
{
if (!socket.Send(PacketStart, PacketSize))
return false;
return true;
}
--------------------------------------------------------------------------------
How would you translate such a C++ struct?
create a class?
What about the array allocation?
code:--------------------------------------------------------------------------------
struct GetRT
{
struct BRTInfo;
enum EType Type;
double Offset;
unsigned short Name[32]; };
--------------------------------------------------------------------------------
What can I do to have constants in a separate file.
consts are no longer available i guess...
In C++ :
code:--------------------------------------------------------------------------------
// Unit-Conversion related constants:
const double LengthFactor = 1000.0;
--------------------------------------------------------------------------------
What about these adress opertaors and sizeof function
Can i use the System.Runtime.InteropServices.Marshal.SizeOf() Method?
code:--------------------------------------------------------------------------------
bool inline Initi() {CInit Data; return SP(&Data.DataPacket, sizeof(Data.DataPacket));}
--------------------------------------------------------------------------------
I really do not understand how to handle my pointers in c#.
Any help is greatly appreciated,
stonee