Click here to Skip to main content
15,892,809 members
Home / Discussions / C#
   

C#

 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Corinna John22-Mar-04 19:48
Corinna John22-Mar-04 19:48 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 3:18
protectorHeath Stewart23-Mar-04 3:18 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot23-Mar-04 4:42
goodpilot23-Mar-04 4:42 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 5:20
protectorHeath Stewart23-Mar-04 5:20 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot23-Mar-04 5:28
goodpilot23-Mar-04 5:28 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot24-Mar-04 3:56
goodpilot24-Mar-04 3:56 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot24-Mar-04 3:59
goodpilot24-Mar-04 3:59 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart24-Mar-04 4:13
protectorHeath Stewart24-Mar-04 4:13 
See the MarshalAsAttribute documentation. To make your implementation easier, use string instead of byte[] but be sure to marshal it as an ANSI string (since you're obviously using bytes for chars and not double-byte chars):
[StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)]
public struct Packet
{
  public Packet(DateTime dt, int line, string msg)
  {
    if (msg == null) throw new ArgumentNullException("msg");

    this.dt = dt;
    this.line = line;
    this.msglen = msg.Length;
    this.msg = msg;
  }
  public DateTime dt;
  public int line;
  public int msglen;
  [MarshalAs(UnmanagedType.LPStr)]public string msg;
}
Now it's also possible that you may need to send a by-value string, in which case you use UnmanagedType.ByValTStr (it will be an ANSI string because of the CharSet property in the StructLayoutAttribute) and specify a constant size, which I know is often a valid limitation of chat software. This latter case is most likely what you'll need to do.

Also, keep in mind that the DateTime in .NET and whatever date/time struct/value you're using in C++ will most likely have different epochs. The DateTime struct uses 00:00:00 Jan 1, 0001 AD. Adjust your time as necessary. Often - depending on how your legacy solution is already coded, you should also use DateTime.ToUniversalTime or DateTime.UtcNow to use a UTC date which is based on zulu time (Greenwhich Mean Time). This ensures that your dates always have a common base. The clients use their locale information to get the local time.

goodpilot wrote:
By the way, what does Microsoft MVP mean? Are you a Most Valuable Player at Microsoft?

It means "Most Valuable Professional". You can read more about the program at http://mvp.support.microsoft.com[^].

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
goodpilot24-Mar-04 16:46
goodpilot24-Mar-04 16:46 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Sascha Andres23-Mar-04 3:17
Sascha Andres23-Mar-04 3:17 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Heath Stewart23-Mar-04 3:20
protectorHeath Stewart23-Mar-04 3:20 
GeneralRe: Socket Programming - How Do I Send and Receive a Class or Structure Pin
Sascha Andres23-Mar-04 3:34
Sascha Andres23-Mar-04 3:34 
QuestionHow do I check wether a url/file exists Pin
kris.mackintosh22-Mar-04 10:17
kris.mackintosh22-Mar-04 10:17 
AnswerRe: How do I check wether a url/file exists Pin
Heath Stewart22-Mar-04 11:56
protectorHeath Stewart22-Mar-04 11:56 
Generalfrom VC6 dll Pin
yyf22-Mar-04 10:10
yyf22-Mar-04 10:10 
GeneralRe: from VC6 dll Pin
Heath Stewart22-Mar-04 11:47
protectorHeath Stewart22-Mar-04 11:47 
GeneralRe: from VC6 dll Pin
yyf23-Mar-04 3:10
yyf23-Mar-04 3:10 
GeneralRe: from VC6 dll Pin
Heath Stewart23-Mar-04 3:13
protectorHeath Stewart23-Mar-04 3:13 
GeneralRe: from VC6 dll Pin
yyf23-Mar-04 4:01
yyf23-Mar-04 4:01 
GeneralLoop through a Datagrid Pin
Anonymous22-Mar-04 9:55
Anonymous22-Mar-04 9:55 
GeneralRe: Loop through a Datagrid Pin
Heath Stewart22-Mar-04 11:46
protectorHeath Stewart22-Mar-04 11:46 
GeneralRe: Loop through a Datagrid Pin
Anonymous22-Mar-04 11:51
Anonymous22-Mar-04 11:51 
GeneralRe: Loop through a Datagrid Pin
Heath Stewart22-Mar-04 11:57
protectorHeath Stewart22-Mar-04 11:57 
GeneralRe: Loop through a Datagrid Pin
Ruchi Gupta22-Mar-04 12:11
Ruchi Gupta22-Mar-04 12:11 
GeneralRe: Loop through a Datagrid Pin
Heath Stewart23-Mar-04 2:46
protectorHeath Stewart23-Mar-04 2:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.