|
I used this piece of code to gain binary representation of a
float number...
byte* p;
float f = 11.0F;
p = (byte*)(&f);
Console.WriteLine("First Byte: " + *p++);
Console.WriteLine("Second Byte: " + *p++);
Console.WriteLine("Third Byte: " + *p++);
Console.WriteLine("Fourth Byte: " + *p);
But as you know we can't use pointers for managed types. Does anyone know
a method to find the binary representation of objects?
|
|
|
|
|
Here are two ways to do it :
float f = 1.0F;
byte[] buffer = BitConverter.GetBytes(f);
int nSize = buffer.Length;
byte b = 0;
for (int i=0; i<nSize; i++)
b = buffer[i];
float f = 1.0F;
IntPtr p = Marshal.AllocHGlobal(Marshal.SizeOf(f));
Marshal.StructureToPtr(f, p, false);
|
|
|
|
|
Yesterday, I was trying to create a shell extension for adding items to the context menu inside windows explorer. The .NET SDK comes with a sample application for this, shellcmd, but when I use this extension and right-click on an explorer item (in this case Folder items), every program that's running will be frozen. Anyone has an idea why this is?
|
|
|
|
|
Works fine for me (W2K SP2 IE6SP1 .NET1.1+1.0SP2).
|
|
|
|
|
I'm running WXP SP1 with Visual Studio 2003 (.NET 1.1) ... VERY weird
I've just reinstalled windows this week and this is the only strange thing I encountered up until now...
|
|
|
|
|
[edit]I'm trying to use the Property grid control at runtime.[/edit]
I added the Proeprty Grid to a form, and now trying to figure out how to get the properties of an object instance into it.
Seems like
a) I have to tag the editable properties with "Browsable" (did that)
b) Get the "Browsable Proeprties" colleciton from the instance - how?
c) set it to the BrowsabeProperties prop of the property grid
Any idea?
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Create a user control. Add properties into it. By default they become browsable. ([Browsable] is more to tell the framework to mark it as non browsable).
Need a sample? Look at the multi-selection treeview[^], where I have a public property : SelectedNodes, which is a collection. Once added to the toolbox, and dropped onto a form, you'll see that, by opening the "Properties Window", you have a SelectedNodes property under the Misc category. That's it!
|
|
|
|
|
Maybe a little misunderstanding:
I'm using the Property Grid in my application (i.e. at run time).I have a custom (dereived-from-nothing) class with application settings I want to allow my end users to adjust.
"Der Geist des Kriegers ist erwacht / Ich hab die Macht" StS
sighist | Agile Programming | doxygen
|
|
|
|
|
Hi
i'm trying to create a structure in C# that look something like this
struct TEST
{
byte t[100];
};
As i come to learn this is nothing that is supported in C#. I have tried a bunch of diffrent approaches in (using unsafe, Managed C++ etc. ) without any success.
What i want to be able to accomplish is something simmilar to this c++ snippet.
struct TEST
{
char t[100];
};
int* i=new int[100];
TEST* p=(TEST*)i;
Any suggestions appriciated
Thanks
Mikael
|
|
|
|
|
Mikaelr wrote:
As i come to learn this is nothing that is supported in C#. I have tried a bunch of diffrent approaches in (using unsafe, Managed C++ etc. ) without any success.
Amazing statement.
(C world)
byte t[100];
(C# world)
byte[] t = new byte[100];
|
|
|
|
|
Yes i know this but i'm NOT looking for creating a reference to an byte array.Which i thought it was obvious in my mail.
I want to create a fixed size array that the compiler maps to offset in the structure. So that I can cast diffrent structs on a buffer and access the data accordingly.
I have not managed to do this in C# as doing "int k[100]" is illegal.
|
|
|
|
|
Mikaelr wrote:
I want to create a fixed size array that the compiler maps to offset in the structure
Ok. I recommend to build an array of object, instead of a specialized array :
object[] m_objecttable; // declaration
m_objecttable = new int[100]; // creation of an int array
m_objecttable = new String[100]; // creation of a string array
And then use reflection to get the type at run-time,
Type objectype = System.GetType( m_objecttable[0] );
Mikaelr wrote:
So that I can cast diffrent structs on a buffer and access the data accordingly
C terminology.
|
|
|
|
|
I'm using System.Uri and System.UriBuilder with .NET Framework 1.0 SP3. It seems to be the case that the "escape string" functionality doesn't work as I'd expect a normal Uri class to work -- it doesn't escape special characters such as ' ' or '"' at all, and I don't see a way to do that in the system classes. Anyone?
Also, I just noticed that System.Uri.ToString() and System.Uri.AbsoluteUri produce different output, which is something I didn't expect.
|
|
|
|
|
Arun Bhalla wrote:
it doesn't escape special characters such as ' ' or '"' at all, and I don't see a way to do that in the system classes
They are escaped! How it works is as follows : for these characters to be escaped they must be such that IsExcludedCharacter() below returns true. Ascii code for space is 32, and ascii code for the quote is 34. Which is ok.
internal static string System.Uri.EscapeString(string rawString,
bool reEncode, ref bool escaped) {
...
do {
...
if (Uri.IsExcludedCharacter(rawString.get_Chars(local6))) {
local1 = Uri.HexEscape_NoCheck(rawString.get_Chars(local6));
break;
}
...
local6++;
} while (local6 < rawString.Length);
...
}
protected static bool System.UriIsExcludedCharacter(char character) {
if (character > 32 && character < 127)
if (character != 60 && character != 62 && character != 35 &&
character != 37 && character != 34 && character != 123 &&
character != 125 && character != 124 && character != 92 &&
character != 94 && character != 91 && character != 93)
return character == 96;
return 1;
}
A few hints :
- make sure to double quotes, instead of doing \"
- all non-ending spaces are escaped. Ending spaces are not escaped, just trim them before you pass the string to be encoded.
Arun Bhalla wrote:
Also, I just noticed that System.Uri.ToString() and System.Uri.AbsoluteUri produce different output, which is something I didn't expect
Different implementations indeed.
|
|
|
|
|
How I can add a tooltip text with explanation in my code - so when I try to call some function/propertie the tooltip automaticly generated by C# will be with my text ? For example - when you type somthing like this:
String.CompareTo (
Tooltip at the bottom will show the return type and a little info about this function. How I can make something like this in my program ?
|
|
|
|
|
|
Hey,
I want to create streamreader object by using xml like this
StreamReader sr = new StreamReader(xmlNode.InnerXml);
But it is showing the following error -
Illegal characters in path.
Can anybody tell how to do this,
Thanks,
Chito
|
|
|
|
|
chito wrote:
StreamReader sr = new StreamReader(xmlNode.InnerXml);
Try instead:
StringReader sr = new StringReader(xmlNode.InnerXml);
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
I have a form which is set as the MdiParent and I open a modal form which is a login form. I want to open a MdiChild form if login is successful.
I would usually set the MdiChild as below but as the login form is not the MdiParent how do I set the parent of the new Mdi form since I can't use the this keyword.
fManagerChild ChildForm = new fManagerChild();
ChildForm.MdiParent = this;
ChildForm.Show();
The forms are called: fManager (MdiParent), fLogin (Modal Form), fManagerChild (MdiChild)
Thanks
Neil
|
|
|
|
|
Is this what you are after?
ManagerChild ChildForm = new fManagerChild();
ChildForm.MdiParent = this.Owner;
ChildForm.Show();
|
|
|
|
|
Has anyone seen any articles on how to do this:
For example, the ASP.NET Validator Controls allow you to select a ControlToValidate in the property table. It's stored as a string, but if you click the drop down button, you get a list of all your controls that support the ValidationPropertyAttribute.
How does it do this? Does it use the attribute somehow?
What I'd like to do is show a list of all MenuItems, so if the concept requires the attribute then I could be onto a non-starter. But it would be a nifty feature for what I'm trying to do.
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
I think those are refered to as TypeDescriptors in design mode. Frankly, I wish I could figure out how to debug designer code could within VS.NET.
HTH
I rated this article 2 by mistake. It deserves more. I wanted to get to the second page... - vjedlicka 3:33 25 Nov '02
|
|
|
|
|
leppie wrote:
I think those are refered to as TypeDescriptors in design mode
leppie,
Never found chance to thank you for this reply.
Did it help me? Well, it gave me something new to learn about... and then I discovered that you could just define the property as type MenuItem and it gives you a DropDownList of MenuItems in the form automatically, so learning it was completely useless but cool anyway
Paul
We all will feed the worms and trees So don't be shy - Queens of the Stone Age, Mosquito Song
|
|
|
|
|
When a Socket got data , I receive it and save it to a *.wav file , play it immediately., my code is under next line .
-------------------------------------------------------
byte[] receive = _server.GetReceiveData();
ff++; // just a counter
statusBar1.Text = "Receive!!!" + receive.GetUpperBound(0) +" "+ff ;
FileName = "receive.wav";
CreateRIFF(); // A function to Create a RIFF, do not look this
Writer.Write(receive);
count = receive.Length ;
Writer.Seek(4, SeekOrigin.Begin);
// Seek to the length descriptor of the RIFF file.
Writer.Write((int)(receive.Length + 36));
// Write the file length, minus first 8 bytes of RIFF description.
Writer.Seek(40, SeekOrigin.Begin);
// Seek to the data length descriptor of the RIFF file.
Writer.Write(receive.Length);
// Write the length of the sample data in bytes.
Writer.Close(); // Close the file now.
Writer = null; // Set the writer to null.
WaveFile = null; // Set the FileStream to null.
//----------------------------------------------------------
//!!!!Problem , when program run to here , yes , it can create a buffer,
//but it just play three times and then can't play anymore !!
//mind that this case is a OnReceiveEvent called when Socket got data.
//The Frequention perhaps ten times a second.
Buffer p = new Buffer("receive.wav",applicationDevice_buffer);
p.Play(0, BufferPlayFlags.Default);
//----------------------------------------------------------------
textBox1.Text = "Receive and played!!!" + receive.GetUpperBound(0) "+(ff) ;
Something happened let I can't receive the data since ff > 3 , can anyone solve this problem ?
|
|
|
|
|
hi peoples.... i need to find away to get the count of event handlers prescribed to a Timer.Tick method. Is there away ? or as a alternitive but working just as well.....is the best way just to re-initialize the variable agian?
thanks....
Jesse M
The Code Project Is Your Friend...
|
|
|
|