|
budidharma wrote: so it can't be a class.
Did you mean it can't be a struct? structs can also have member functions, so you should be fine.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Oh yes, that's what I meant. I didn't know structs could have member functions.
In that case, what's the difference between a struct and a class?
I thought structs were simply structures of data, no member functions allowed.
|
|
|
|
|
This[^] might help you understand structs bettter.
Essentially, structs are passed around by value, classes by reference. For example
struct A
{
public int x;
}
class B
{
public int x;
}
static void Main()
{
A structInstance = new A();
structInstance.x = 1;
A structInstance1 = structInstance;
structInstance1.x = 20;
B classInstance = new B();
classInstance.x = 1;
B classInstance1 = classInstance;
classInstance1.x = 20;
}
After executing the above code, structInstance.x will be 1 and structInstance1.x will be 20. However, classInstance.x and classInstance1.x will be 20. What it means is that when you say A structInstance1 = structInstance; a new instance of A is created and contents are copied from structInstance. When B classInstance1 = classInstance; executes, classInstance1 and classInstance begin referring to the same instance of B, therefore, changing x using any of the two references gets reflected in both.
Regards
Senthil
_____________________________
My Blog | My Articles | WinMacro
|
|
|
|
|
Well, thank you very much for explaining that to me. That makes perfect sense - and yes, you were correct. I merely need to change my class to a struct and it will work the way intended.
Thanks Again.
|
|
|
|
|
Right. I don't know what I was thinking.
So you're left with Clone().
Matt Gerrans
|
|
|
|
|
Hi, Does anyone know an easy way to create a string of characters that are assigned 1 byte for each character, in C#.
I am interfaceing with a rather old API (written in ANSI C, think) from .NET 2005 (beta). The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char.
I have a Delphi 6 interface for the API that uses PCHAR data type, instead of string, and this works OK.
Also, will I need to declare the API calls with a data type that uses 1 byte per char, instead of just string ?
P.S. this is the MSMAPI32.DLL to connect to Micronetics MSM (MUMPS). Incase there are any MUMPSTER's out there.
Thanx!
Dave Shaw
History admires the wise, but elevates the brave. - Edmund Morris
|
|
|
|
|
Dave Shaw wrote: The problem is that the normal c# string data type uses unicode encoding, this allocates atleast 8 bytes per char.
thats 2 bytes rather...
Use System.Text.Encoding.UTF8.GetBytes() .
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
Leppie is right, Unicode is 2-bytes, not 8. Unicode makes room for 65,535 characters in a set (255 * 255). 8 Bytes would allow lots and lots and lots of characters, like (255 ^ 8).
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Unicode makes room for something like a million characters. Unicode does not take up any "bytes". It just define which "character" is at which number. In order to represent Unicode in memory or on file, you need an encoding of the Unicode character set.
The UTF-16 encoding (which is probably what you refer to as this is what C# use internally) will use 2 or 4 bytes per character.
|
|
|
|
|
well you can always use byte vectors, or pointers to byte in an unsafe part of the code... then you can use normal io.streamwriter for writing and io.streamreader for reading
<- true inside to understand outside ->
|
|
|
|
|
|
Im having a trouble to catch KeyDown event on the form.. it just doesnt work..
any other control on the form can get KeyDown event if ill set it to him
but the form event just doesnt work..
thanks..
|
|
|
|
|
The form itself rarely ever has the focus. The controls on the form have it, so the form's KeyDown event is rarely ever called. Unless, that is, the Form's KeyPreview property is set to true . This will pass all the keyboard events going to the form's control with the focus to the form's handlers first, then pass them on to the control that has the focus. There is a side effect to setting this though. The KeyDown event will fire for every keystroke going to any control on your form.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Thanks exactly what i was looking for !
they didnt mention that on MSDN..
|
|
|
|
|
Hi, I'm curious, why would a form need to catch keyboard events? What are you using it for? I can't think of any scenario where this can be used.
/Patric
My C# blog: C# Coach
|
|
|
|
|
Im building a small program which you can get the color of any pixel on the screen, color picker
after pointing on a pixel and getting its RGB and HEX into text boxes how would you remember them?
just clicking on a button will get them into a list of colors
|
|
|
|
|
Actually, they did. Form.KeyPreview[^]
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
How does one prototype an exported function call that has a HANDLE* parameter argument? I have tried "ref IntPtr" with no success.
Example:
C Prototype:
__declspec (dllexport) DWORD CALLTYPE func(HANDLE* phandle);
C# Prototype:
[DllImport("func.dll")]
static extern uint canOpen(ref IntPtr ptrHandle);
I get a "Invalid Handle" error from the OS when this is called.
TPF
|
|
|
|
|
Could the ref be causing the problem somehow? I'm using IntPtr's for handles while accessing user32.dll without issue.
|
|
|
|
|
T Finn wrote: ref IntPtr ptrHandle
Dont use ref . Else you are creating a pointer to a pointer.
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
What is confusing here is that the argument is a pointer to a IntPtr (HANDLE). Passing a IntPtr as a handle works but this function calles for passing a pointer to a handle (HANDLE*).
T Finn
|
|
|
|
|
T Finn wrote: IntPtr (HANDLE).
Since when? HANDLE is a struct, iow a valuetype.
xacc-ide 0.0.99-preview7 now with C#, C, C++, IL, XML, Nemerle, IronPython, Perl, Caml, SML, Ruby, Flex, Yacc, Java, Javascript, Lua, Prolog and Boo highlighting support!
|
|
|
|
|
After 22 years I am leaving AS/400 (shudder), dec unix, Linux, Java, openVms, MFC, C++, VB, Access, blah blah blah) to a new job that is pure C#/SQL.
After many years of being unmanaged , I am finally gonna get managed . ( I wish I could use VS C++ 2005 compiler for managed code, so I could manage the memory myself, sigh)
I have only done a few thousand lines of C# so here goes.
Pray for me.
.............................
There's nothing like the sound of incoming rifle and mortar rounds to cure the blues. No matter how down you are, you take an active and immediate interest in life.
Fiat justitia, et ruat cælum
|
|
|
|
|
Good luck then. I came from an unmanaged background as well (though admittedly not as extensive as yours), and am loving C#.
Oh, by the way, if you've done Java, then you've done 'managed' code already.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
> I wish I could use VS C++ 2005 compiler for managed code, so I could manage the memory myself, sigh
Don't worry. With experience you will slowly begin appreciate the fact that the computer can manage memory better at runtime than you think can at compile time.
Matt Gerrans
|
|
|
|
|