Connecting Tech Pros Worldwide Help | Site Map

Little Problem

Angel J. Hernández M
Guest
 
Posts: n/a
#1: Nov 16 '05
Hi folks! I'm having a little problem and I'm a bit confused about it.
See... I'm working on this VoIP project (I need to use make direct calls to
Windows API). I started working using C# but since I've got to access the
API constantly I'd rather write all low-level stuff in C++ and create the UI
using C#. So far so good... I created a sniffer socket (in order to
determine if it's H.323 compliant). This routine was written firstly in C#
but since I want to have all low level stuff in C++ I ported it to. Ok... My
problem is the next...

I have somthing like this (This code works OK)...

protected virtual unsafe object[] ParseIPHeader(byte[] packet, int
length) {
short src_port = 0, dst_port = 0;
object[] retval = new object[6];

fixed(byte* packetdata = packet) {
CCommon.IPHeader* ipheader = (CCommon.IPHeader*) packetdata;
// Rest of code goes here...
}

Here IPHeader is a struct I use to store IP packet's header... Then I have
the new C++ code...

Object* CRawSocket::ParseIPHeader(Byte packet[], int length)[] {
short src_port = 0, dst_port = 0;
System::Text::StringBuilder *src_address, *dst_address;
Object *retval[] = new Object*[6];
src_address = new System::Text::StringBuilder();
dst_address = new System::Text::StringBuilder();

Byte *packeddata = __try_cast< Byte *>(&packet[0]) ;
CCommon::IPHeader *ipheader = (CCommon::IPHeader *) &packeddata;
// Rest of code goes here...
}

My problem is that I don't get the same results even though it's almost the
same code

As we all know in C# we pass "addresses" so there's no need to write

fixed(byte* packetdata = &packet) // wrong!

but in the C++ world I need to pass the address

I've tried this...

Byte* packeddata = packet; // I get error C2440: 'initializing' : cannot
convert from 'unsigned char __gc[]' to 'unsigned char __gc *'
Byte *packeddata = __try_cast< Byte *>(&packet[0]); // This compiles OK
but it doesn't get the address I need :but the char value instead :s

I need some help with this... Any Ideas?

Thanks in advance


Closed Thread


Similar C# / C Sharp bytes