IRC Networks
Irc Logs Stats
Start date: 2007-09-27 02:48:27
Last update: 2008-10-24 20:19:38
Channels: 41
Logged Lines: 6230436
Size: 1822.42 MB
Powered by
Channel Info
Network: freenodeChannel: #csharp |
Search in www.irclog.org
Log from #csharp at freenode 2006-09-04
[21:00]<y-gz>a is proxy to b
[21:00]<rrsync>Randroid: you can omit gg_fix() function
[21:00]<pz2-rwrd>I whouth == was just an alias to .Equals for most objects
[21:00]<y-gz>so i want when I do a == c that to be actually b == c
[21:00]<pz2-rwrd>but my book is at work
[21:01]<zzgmzjym>jasiek: ok
[21:01]<zzgmzjym>jasiek: OK, now this is the original C code. I'm more interested in your C# code.
[21:02]<zzgmzjym>Well, I guess this could be C#, if called in an unsafe block.
[21:02]<zzgmzjym>I'd have to look at it more closely.
[21:02]<sdnffdxdlld>frb-away: most of the time yeah it is , when you overload == you just redirect it to .Equals()
[21:02]<rrsync>http://nomorepasting.com/paste.php?pasteID=68140
[21:03]<dgdyrg>hi
[21:03]<dgdyrg>are there available .net components or APIs to interop with microsof office documents, or their xml format ?
[21:04]<pzynsv-jp-psy>later all
[21:04]<pzynsv-jp-psy>asta andy
[21:04]<pzynsv-jp-psy>meeting time
[21:04]<sdnffdxdlld>Demian: have you checked out the office interop assemblies to see if they have what you want?
[21:04]<zzgmzjym>jasiek: As you've discovered, you can't mix-and-match pointers in C# as you can with C.
[21:04]<sdnffdxdlld>cya Priest-of-Psi :)
[21:05]<zzgmzjym>That's why sock.Receive(&CONN) fails.
[21:05]<rrsync>why?
[21:05]<dgdyrg>smellyhippy: in which package are they ? a separate distribution ?
[21:05]<sdnffdxdlld>uhhhh i think they come with office ... but i might be wrong
[21:05]<zzgmzjym>sock.Receive is defined to take byte[], not gg_header*.
[21:05]<sdnffdxdlld>SpikeLite google office interop assemblies c#
[21:05]<slycnlyvn>Result: Faster MS Excel Reading using Office Interop Assemblies - The Code ... : http://www.codeproject.com/csharp/FasterExcelAccessTOC.asp
[21:06]<zzgmzjym>jasiek: Pointers and reference types are strongly typed in C#.
[21:06]<rrsync>so what solution you advice?
[21:07]<dgdyrg>thanks smellyhippy
[21:07]<sdnffdxdlld>np Demian :)
[21:07]<zzgmzjym>jasiek: I can't remember whether you can directly cast between byte* and some other type in an unsafe block, but I do know that the Marshal object has static methods that will let you do what you want to do.
[21:08]<rrsync>cast? what does it mean?
[21:10]<zzgmzjym>jasiek: Example, pseudocode, may not work: gg_header CONN; byte[] bytes = new bytes[Marshal.SizeOf(CONN)]; sock.Receive(bytes); CONN = Marshal.BlahBlah(bytes);
[21:10]<zzgmzjym>The Marshal.BlahBlah method must be replaced with the name of the actual method that converts an array of bytes into a struct.
[21:10]<zzgmzjym>That code should be CONN = (gg_header)Marshal.BlahBlah(bytes);
[21:11]<zzgmzjym>This could is probably not exactly correct, but it points you in the right direction.
[21:11]<rrsync>okay
[21:11]<zzgmzjym>*could = code
[21:12]<rrsync>I will look for the Marshall object...
[21:12]<zzgmzjym>The bottom line is that sock.Receive can only receive an array of bytes. You are responsible for converting those bytes into a struct or or whatever you wish.
[21:13]<rrsync>in C it is easier...
[21:15]<sdnffdxdlld>then use C for the communication and C# for the rest of the app if you feel comfortable with C
[21:15]<zzgmzjym>jasiek: True, but also less safe, at least according to the designers of C#. Pointers are considered confusing and error-prone for your average developer. But when you need them, you need them.
[21:15]<zzgmzjym>jasiek: I find pointers quite simple to understand, but many do not, and that's not to say they are bad developers.
[21:16]<sdnffdxdlld>c# wasn't made because people didnt understand pointers
[21:16]<pz2-rwrd>pointers sucks
[21:16]<zzgmzjym>smellyhippy: Never said they were. But they are considered confusing and error-prone, and thus can lead to buffer overflows, etc.
[21:16]<pz2-rwrd>garbage collection saves developer time
[21:16]<rrsync>:) I am not a developer ;) I am a young man trying to learn somehthin :)
[21:17]<zzgmzjym>jasiek: That's cool! I started out like that back in the 80's.
[21:17]<sdnffdxdlld>oldie!
[21:17]<zzgmzjym>hehe
[21:17]<sdnffdxdlld>;)
[21:18]<zzgmzjym>At least I don't look it. :)
[21:19]<zzgmzjym>jasiek: Good luck. Seriously.
[21:19]<rrsync>yeah I started learning c# when I heard about something like Genetic programming, which is connected with my interestings :))
[21:19]<rrsync>thanks Randroid :)
[21:20]<zzgmzjym>I am more interested in development for the Macintosh, but C# is what pays my bills. :)
[21:22]<rrsync>randroid : last question:) what I need to Marshal object? a dll? because I dont have it by default in vs2005
[21:22]<zzgmzjym>jasiek: You do. You just have to import the right namespace. And I don't remember exactly what that is. System.Runtime.InteropServices, probably.
[21:23]<zzgmzjym>using System.Runtime.InteropServices;
[21:23]<sdnffdxdlld>aye that sounds right
[21:25]<zzgmzjym>If you are importing C DLLs, the Marshal object is your friend. It has static methods that do all kinds of interesting stuff.
[21:25]<zzgmzjym>Last night I even cleaned my house using it. It's really amazing.
[21:26]<rrsync>:)
[21:27]<rrsync>Marshal.StructToPtr() is it it?
[21:28]<zzgmzjym>Probably the reverse.
[21:28]<zzgmzjym>Marshal.PtrToStruct(), if there is such a thing?
[21:28]<zzgmzjym>You want to marshal a pointer into a struct.
[21:28]<rrrdjdtxyrr>Possibly being really dumb here, but could you not define a metod that populates a structure given a byte[] param?
[21:29]<rrrdjdtxyrr>s/metod/method/
[21:29]<zzgmzjym>RandomThing: Sure you could. But we're trying to find the path of least resistance, I think.
[21:29]<rrrdjdtxyrr>least resistance for who?
[21:29]<zzgmzjym>The struct has the exact same memory layout as the byte array.
[21:29]<zzgmzjym>RandomThing: We The People.
[21:29]<rrsync>yeah there is somethinh PtrToStructure
[21:30]<zzgmzjym>jasiek: That's probably the one.
[21:30]<rrrdjdtxyrr>I mean, would there be anything wrong with doing that in terms of efficiency?
[21:30]<zzgmzjym>RandomThing: I think it would be more complex than simply marshaling the bytes into a managed struct, but to each his own. :)
[21:31]<zzgmzjym>The array of bytes IS the struct. All we need to do is tell C#'s strict type system that that is the case.
[21:31]<rrrdjdtxyrr>yeah, I get that...
[21:32]<rrrdjdtxyrr>I just couldn't understand using Marshal.PtrToStructure when I looked briefly at it.
[21:32]<zzgmzjym>I don't even remember what you have to pass to it. I'd have to look it up. I'm on my MacBook Pro at the moment and don't have a Windows virtual machine running, but I guess I could look on MSDN.
[21:34]<rrsync>byte to System.IntPtr
[21:34]<rrsync>;/
[21:34]<zzgmzjym>jasiek: That's probably fairly easy.
[21:37]<zzgmzjym>You need to use a fixed code block, something like fixed( byte *p = received ) { gg_header CONN = (gg_header)Marshal.PtrToStructure(new IntPtr((int)p), typeof(gg_header)); }
[21:37]<zzgmzjym>Again, I make no claims that exact code will work.
[21:37]<zzgmzjym>"received" is your array of bytes.
[21:41]<rrsync>heh
[21:41]<rrsync>I tryed like that :
[21:41]<rrsync>byte[] bytes = new byte[Marshal.SizeOf(CONN)];
[21:41]<rrsync> sock.Receive(bytes);
[21:41]<rrsync>CONN = Marshal.PtrToStructure(new IntPtr((int)bytes), CONN);
[21:42]<rrsync>is it correct?
[21:42]<zzgmzjym>Well, you have to use the "fixed" keyword because the memory manager can move the byte[] array at any time.
[21:42]<zzgmzjym>jasiek: Welcome to a "managed" language. :)
[21:43]<rrsync>so is it good?







