|
Ahh, thx James. Didnt know about unsigned types being non CLS compliant.
re BOOL, i just made a small function to take care of it , but with this input i'll try converting some of them as see the results.
The only remaining worry is what happens when DWORD return a value bigger than Int32.MaxValue? Not that it has happened yet, but it could.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
The only remaining worry is what happens when DWORD return a value bigger than Int32.MaxValue? Not that it has happened yet, but it could.
Unfortunately thats just something you have to know ahead of time and it depends on how the value is used.
If the DWORD contains something larger than Int32.MaxValue the return result will be negative as the LSB or MSB will be set (I never can remember how it should be ordered )
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thx again James
James T. Johnson wrote:
If the DWORD contains something larger than Int32.MaxValue the return result will be negative as the LSB or MSB will be set (I never can remember how it should be ordered )
According to MSDN an overflow exception will occur unless the block is marked unchecked. In which case the MSB/LSB (hell i dont know either, will wait till next year when I'm doing bitwise operations more regularly) will be set.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
According to MSDN an overflow exception will occur unless the block is marked unchecked.
I don't see this case happening, because when the data is being marshalled the framework doesn't know the original context of the value (signed or unsigned it is still a 4-byte block of memory). In this case we are telling it to be interpreted as a signed integer so it should interpret any value with the MSB or LSB set as being negative (assuming 2's complement use of the bits). The only cases where the MSB/LSB is set are when you have values larger than Int32.MaxValue.
There may be some attributes that could be applied to make the framework aware of such occurances, but I'm not aware of them off the top of my head.
Now when you add 2 ints together in managed code the framework does know the context of those values so it can decide whether or not the result went over the max value.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thx James, you dont seem to overlook anything. How do u do it? Of course the the unmanaged function has no clue to what it is returning its returned value to.
And I continue to slap myself repeatedly.....
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
Thx James, you dont seem to overlook anything. How do u do it?
I have no real social life and I've worked with .NET since Beta 1; chances are that I've already had to think a lot of issues through at one time or another
Other times something just comes to me that seems to fit and makes sense when I think it through; such was the case here when returning values from unmanaged functions. In this case it was my 10 week long assembly course I took my first year of uni where we spent about 2 weeks on how the processor stores numbers (bitwise).
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
How can I do Auto Tabbing on my Controls? Example on my Form I have two Text Box, reaching a specific length in first Text Box the focus automatically goes into the next Text Box.
Anybody HELP!
|
|
|
|
|
Easily
register keypress event, check the length of the textbox1's text and do textbox2.Select().
Sorry im a bit too lazy to write out the code
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
For an app that may or may not be run in the console (ie it can be run with a dlg interface or at the cmd prompt) how could one determine whether the app is running in the console or not in the entry point?
|
|
|
|
|
Nevermind... I didn't realize it was an either or situation. Really miss the allocconsole. Maybe we'll just have to import. That's disappointing.
|
|
|
|
|
Hi all again,
What type of resource can i embed into an assembly to use at runtime? Is it possible to embed (embedding works) a Win32 dll and use that dll directly from the embedded resources?
Also , how do you view what resources are in an assembly?
Any help will be appreciated.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
Like Nnamdi said you can embed anything into the assembly
If you have VS.NET it is very easy to do; add the file to your project, then in its properties set Build Type to "Embedded Resource".
To get it back out is simple, if you know the name of the object (and yes it is possible to get all of the names)
Type type = typeof(MyClassFromAssemblyWithResources); ;P
Assembly asm = type.Assembly;
Stream stream = asm.GetManifestResourceStream(name);
Now to get the names of the resources use this bit of code (real simple )
Type type = typeof(MyClassFromAssemblyWithResources); ;P
Assembly asm = type.Assembly;
string [] names = asm.GetManifestResourceNames(); Done
Now, how is the name generated in VS.NET? First it takes the default namespace ("MyCompany.MyProduct"), then appends the names of any folders it is placed in within the project ("Resources"), finally it appends the filename of the resource ("MyResource.ext"). Given the above example the name would be MyCompany.MyProduct.Resources.MyResource.ext.
If you compile using the command line then you specify the name as the second argument to the /resource compiler switch.
I don't know how SharpDevelop derives its naming scheme.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
|
And you compiled using SharpDevelop?
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
yer. or maybe i did give it the namespace.class at the beginning - hmmmm i cant remember 100%, and i cant access at code cos im at work.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Thanx all
James T. Johnson wrote:
Type type = typeof(MyClassFromAssemblyWithResources);
Can I use any class from the assesmbly?
James T. Johnson wrote:
Stream stream = asm.GetManifestResourceStream(name); // Do something with the Stream
I just want to use the static functions in a Win32 dll, how? Do I load to memory? Im totally clueless.
In DllImportAttribute(string filename) , what do i say/do with filename here, do i have to write to file 1st?
Please help :
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
Can I use any class from the assesmbly?
Yep
leppie wrote:
I just want to use the static functions in a Win32 dll, how? Do I load to memory? Im totally clueless.
That is where it gets tricky.
I think the easiest method would be to write it to a file (with the same name it had when you compiled), and hope that the DLL doesn't get loaded until the imported method executes [so the DLL will be written to file before then]. I think there is a slight problem. From what I have heard, the dll is in use until the program exits; so you never get a chance to delete the file.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thx James I will have a look
James T. Johnson wrote:
From what I have heard, the dll is in use until the program exits; so you never get a chance to delete the file.
Thanx for that bit of info.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I’ve been trying to figure out where to place some drawing code in my application. Sometimes, I want to paint OVER some controls slightly. If I place the custom painting code in the form’s Paint Event (even override OnPaint ) when the controls on the form are painted my custom paint job is overpainted by the controls. Is there someplace that I can do my painting AFTER the controls have been painted?
|
|
|
|
|
Im not so sure , but from what i understand is you need to draw to the Graphics object found at IntPtr.Zero. Look for more info, a couple days back.
IntPtr.Zero? u may ask. I read that that is allways the pointer to the current foreground window. So it all makes sense
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
Hi leppie,
Actually passing IntPtr.Zero (i.e. null) to GetDC will return a handle to the screen. This is a fine solution (as suggested in a thread below by Li-kai Liu and AK) and this is what I am doing.
However, when I do this in the Form Paint event the Screen is painted fine, then the controls get painted and it erases what is drawn. So I’m left with my original Question:
Is there someplace that I can do my painting AFTER the controls have been painted?
Try this code out to see for yourself. Start a new project, place a button on the form. Then add the Form1_Paint event and place this code in that event:
Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
IntPtr hdc = GetDC(IntPtr.Zero); // get hdc for the screen
Graphics g = Graphics.FromHdc(hdc);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y - 7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
//This should COVER the button but the control is redrawn over it
g.FillRegion(hatchBrush, region);
/////////////////////////////////////
//Place this code outside the paint event:
/////////////////////////////////////
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern IntPtr GetDC(IntPtr hWnd);
|
|
|
|
|
You might want to try something like this:
void MyPaintMethod()
{
Rectangle r = new Rectangle();
r = this.RectangleToScreen(button1.Bounds);
Graphics g = new Graphics.FromHwnd(this.Handle);
System.Drawing.Rectangle r1 = new Rectangle( r.X - 7,r.Y -7,r.Width+14 ,r.Height+14);
System.Drawing.Region region = new Region(r1);
System.Drawing.Drawing2D.HatchBrush hatchBrush = new System.Drawing.Drawing2D.HatchBrush((System.Drawing.Drawing2D.HatchStyle) 9,Color.Gray ,this.BackColor );
g.Dispose();
}
I can't test this to see if it will work, but I am thinking this should be correct, thus you wouldn't need the DllImport portion.
HTH
Nick Parker
|
|
|
|
|
I didnt test it but it seems that all it would do is get the Graphics object to the form (i.e. your "this" = Form1). Then after this code is painted on the form the controls would be painted over it. Leaving me with the same problem.
I need to find a way to paint over the controls on the form. I simply dont know where to hook my code in.
|
|
|
|
|