Welcome to Dream.In.Code
Become a C# Expert!

Join 150,390 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,072 people online right now. Registration is fast and FREE... Join Now!




unmananaged C++ and c# problems

 
Reply to this topicStart new topic

unmananaged C++ and c# problems, Converting C++ struct to C#

zakary
4 Mar, 2008 - 07:59 AM
Post #1

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
I am not completely sure this is corrrect.

cpp

struct tagRAP_DIS_Info
{
char szInterface[16];
char szAddress[16];
DWORD dwMode; // CastMode
short wPort;
BYTE bExercise;
BYTE bVersion;
};


csharp

[System.Runtime.InteropServices.StructLayout(System.Runtime.InteropServices.LayoutKind.Sequential)]
struct tag_Info
{
string[] szInterface;
string[] szAddress;
uint dwMode; // CastMode
Int16 wPort;
Byte bExercise;
Byte bVersion;
};


unfortunately in my code I only get a pointer to the error that is defined by the cpp dll or a 0(zero) meaning it is ok.

thanks for any help you can give me
User is offlineProfile CardPM
+Quote Post

baavgai
RE: Unmananaged C++ And C# Problems
4 Mar, 2008 - 11:48 AM
Post #2

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 2,290



Thanked: 136 times
Dream Kudos: 475
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
Those string[] are right out. wink2.gif

Something like this might do it:
csharp

struct tag_Info {
unsafe fixed char szInterface[16];
unsafe fixed char szAddress[16];
uint dwMode; // CastMode
short wPort;
byte bExercise;
byte bVersion;
};


User is online!Profile CardPM
+Quote Post

zakary
RE: Unmananaged C++ And C# Problems
4 Mar, 2008 - 11:52 AM
Post #3

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
Thanks baavgai I will try it and see if it works
User is offlineProfile CardPM
+Quote Post

zakary
RE: Unmananaged C++ And C# Problems
5 Mar, 2008 - 10:57 AM
Post #4

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 420



Thanked: 8 times
Dream Kudos: 175
My Contributions
Thanks again baavgai it did not work but you got me on the right direction.


This worked.
csharp


struct tag_Info
{
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst=16)]
public string szInterface; //IP address; inet_ntoa()
[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValTStr, SizeConst = 16)]
public string szAddress; //Broadcast/Multicast address

public UInt32 dwMode; //0 = Broadcast, 1 = Multicast
public Int16 wPort; //Network port
public Byte bExercise; //DIS Exercise ID; 1-255
public Byte bVersion; //DIS Version; 5 or 6
};


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 05:34PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month