|
In C/C++, we may code:
union aa {
double bb;
char cc[8];
} a;
In this way we may verify the actual data stored in memory for the double. How do I do that in C#?
Thanks.
|
|
|
|
|
Does this [^] help (see Attributes on Structs paragraph at the bottom of the page)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
CPallini wrote: Does this [^] help
No, documentation is not helpful.
Well at least to those who refuse to read it. Yet somehow reading the same information in a forum post is helpful, go figure.
led mike
|
|
|
|
|
It really helps, thanks a lot.
Seems it doesn't take arrays as follow:
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Explicit)]
struct TestUnion
{
[FieldOffset(0)]
public double d;
[FieldOffset(0)]
public char[] c;
}
workaround would be:
[StructLayout(LayoutKind.Explicit)]
struct TestUnion
{
[FieldOffset(0)]
public double d;
[FieldOffset(0)]
public char c0;
[FieldOffset(2)]
public char c1;
[FieldOffset(4)]
public char c2;
[FieldOffset(6)]
public char c3;
}
|
|
|
|
|
cyh_cyh wrote: Seems it doesn't take arrays as follow:
Yes. I guess it is because arrays are allocated on the heap.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Yes, but not in the same way. You need to use the StructLayout and FieldOffset attributes on the struct and fields, respectively. For your example, the equivalent in C# would be
[StructLayout(LayoutKind.Explicit)]
struct aa
{
[FieldOffset(0)]
public double bb;
[FieldOffset(0)]
char[] cc;
}
Scott.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Do you know how can I change the windows mouse pointer. I can chage it on my application form ... but i waould like to change it on all windows. I want to simulate a selection rectangle but on all applicationn that allows the user to select a region of the screen. Thanks a lot.
|
|
|
|
|
|
hi
i using reporting service(report viewer) in my app, but i don't how to set paper size,landScape, ... in my report at designTime and runTime, can anyBody help me ?
thanks
|
|
|
|
|
Hi,
I need to build a application where I have a mainform and multiple runtime generated forms.
There are many good methods to pass data between 2 winforms but I have a problem to get it work with runtime generated forms.
Is there someone who have a simple sample where i can start from.
Thanks
|
|
|
|
|
redspiderke wrote: There are many good methods to pass data between 2 winforms but I have a problem to get it work with runtime generated forms.
I don't quite understand what you mean. What is the difference between a "winform" and a "runtime generated form"?
|
|
|
|
|
Sorry,with a winform I mean a standard form
|
|
|
|
|
What is a "standard form"? You have to explain what you mean by both things because I still don't know what you mean.
|
|
|
|
|
Hi Colin,
A Standard form is just a form you make with the interface from Visual Studio(the basic Form1.cs in a new solution for example).
The runtime form is a form that I totaly create from code when i hit a button.
private void button2_Click(object sender, EventArgs e)
{
Form frmRuntime = new Form();
frmRuntime.Show();
}
In realtime i have a form frmMain with a couple of buttons. Each button opens a form that is not visible in my solution explorer but is generated 100% from code. The problem is that I want pass de data (textboxes) from the code generated form to the main form (frmMain).
|
|
|
|
|
redspiderke wrote: The problem is that I want pass de data (textboxes) from the code generated form to the main form (frmMain).
They will be somewhere in the Controls collection? So long as you have uniquely identified them (use the Name property), you can use the Find method on the ControlCollection
For example:
myForm.Controls.Find("MyTextBox");
NOTE: The above line of code will return an array of Control objects because it is possible to have multiple controls with the same name.
|
|
|
|
|
When I try to add the generated dll file, the visual studio didn't accept the dll file..
plz reply asap..
thnx in advance..
code for dll
--------------
#include <stdio.h>
extern "C"
{
__declspec(dllexport) void DisplayHelloFromDLL()
{
printf ("Hello from DLL !\n");
}
}
___________________________________________________________
code for C# program
--------------------
class HelloWorld
{
[DllImport("TestLib.dll")]
public static extern void DisplayHelloFromDLL ();
static void Main ()
{
Console.WriteLine ("This is C# program");
DisplayHelloFromDLL ();
}
}
______________________________________________________
|
|
|
|
|
Everything looks ok, are you sure the dll is where your program can find it? Also, you do not add it as a reference like normal .NET assemblies.
|
|
|
|
|
Perhaps your exports aren't correct. Try adding them explicitely to your .def file.
Regards,
mav
--
Black holes are the places where God divided by 0...
|
|
|
|
|
Hi
I have an enumerated type that has two elements : fixed and floating, but I can't use "fixed" because it is an identifier.
Any ideas how I get around this?
|
|
|
|
|
If you want to use a reserved word for that kind of thing you need to put an @ in front of it
enum MyEnumeration
{
@fixed,
floating
}
...
Console.WriteLine(MyEnumeration.@fixed.ToString());
|
|
|
|
|
5'd, but please see note below.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
Thanks. 'tis thus resolved.
|
|
|
|
|
In addition to what Colin said, I would almost never recommend it. It's bad practice, and it throws people off the track. Not many people even know about this. IMO, this feature should have been left out.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
I agree that it's dangerous, but since C# keywords != VB keywords != C++ keywords != python keywords != cobol keywords, etc; the CLR needs to have a way to handle something not a keyword in the language it was written in but that is one in a different language that wasn't considered when the class was originally written.
You know, every time I tried to win a bar-bet about being able to count to 1000 using my fingers I always got punched out when I reached 4....
-- El Corazon
|
|
|
|
|
Excellent, thanks. I stand corrected on the "This feature should have been left out" bit.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|