|
[DllImport("USER32.DLL")]
public static extern HHOOK SetWindowsHookEx(int idHook, HOOKPROC lpfn, HINSTANCE hMod, DWORD dwThreadId)
this is all the informaion that i can give. im not sure if the DWORD in C++ and C# are the same, so u may have to use a diferrent type there, icant help you there, maybe someone else can.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Hi,
How can I use Raster Fonts in TextBoxes?
(it seems raster fonts are not supported in .Net!)
Thanks,
Nima.
|
|
|
|
|
Try this, create 3 propertygrids, assign any objects to their selectedobject property, then call a timer every say 100ms doing a refresh on all the propertygrids. You will notice that all propertygrids collapses and expands when the plus or minus sign has been clicked.
Im sure this is not meant to happen...
This is very easily recreatable. Now if I only knew how to upload samples...
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
|
It appears to be a bug with Refresh; you don't even need the timer object.
I modified your sample to put buttons below each grid, each button called refresh on the grid above it. Closing or opening one grid would cause the others to follow suit when their button was pressed.
BTW, there is a bug in your test program. You call Refresh from the System.Timers.TimerElapsed event; this results in the delegate being called on another thread where you shouldn't call any methods or set any properties except for BeginInvoke, EndInvoke, Invoke, and CreateGraphics.
To make it compliant I just made a minor change:
The code added first checks to see if it can execute properly, if it can't (InvokeRequired returns true) then I call Invoke on Form object passing in a delegate of the same type as the method (System.Timers.ElapsedEventHandler) and the two parameters as an array of objects. After the call to Invoke I return since the rest of the method has already completed.
void Timer(object sender, System.Timers.ElapsedEventArgs e)
{
if( InvokeRequired )
{
Invoke(
new System.Timers.ElapsedEventHandler(this.Timer),
new object [] { sender, e }
);
return ;
}
...
}
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thx James
James T. Johnson wrote:
BTW, there is a bug in your test program.
Would programming it "unthreadsafe" make such a big difference in something as small as this? Could this cause a CreateHandle() error I sometimes see?
What other side effects could happen or is this just the "safe" way to go to make 100% sure?
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
What other side effects could happen or is this just the "safe" way to go to make 100% sure?
The known side effects are just odd behavior; which is what makes this type of bug so bad. Sometimes the code will work other times it won't.
Better to be safe than sorry
It appears that you could also have set the SynchronizingObject property of the Timer to a control (such as the Form).
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
How can I find out if some a file or a directory is access denied for read or write?
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
How about this if you check for a files read/write protection:
FileAttributes fa = File.GetAttributes(@"C:\TheFile.txt");
if((fa & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
}
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|
ReadOnly attribute is not a file security.There are some directories or file that maybe you can't even read.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
I saw a post about 2 weeks ago regarding the NTFS File Security attributes, unfortunately my GPRS connection takes ages to surf, so mite just wanna try a search for it or the article (metioned in the post) on CodeProject.
Hope u find it, else i'll post the link later
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
This article?:
NT Security Classes for .NET
Thank you.I'll check it out.Of course its MC++.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
Along with Anakrino, I recommend that one (MS shared source) to get to know how all this works behind the wheel,
Anyone ever tried to attach these symbols to a debug session by the way ?
-- modified at 10:59 Friday 14th October, 2005
|
|
|
|
|
How can I find out if a string exist in another string.Something like strstr in C++.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
|
Hmmmm,Good idea.Thanks.
Mazy
"If I go crazy then will you still
Call me Superman
If I’m alive and well, will you be
There holding my hand
I’ll keep you by my side with
My superhuman might
Kryptonite"Kryptonite-3 Doors Down
|
|
|
|
|
an alternative to that is to use te StrringBuilder class, but that would mean initialising extra variables that arent really needed.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
Why can't you set an instance of a struct to null? And therefore you cannot test a struct for null.
Which if this cannot be done really really sucks big time. I get compiler errors when I try to set an instance of a struct to null or test it for null.
I have checked my 3 C# books, and none of them even talk about it, and none of them never even use the word null in the book even once.
If this is true this is very stupid, it creates more work for some coding solutions.
In case it is important the struct in question is a "System.Drawing.Rectangle".
The errors:
#1: error CS0037: Cannot convert null to 'System.Drawing.Rectangle' because it is a value type
#2: error CS0019: Operator '==' cannot be applied to operands of type 'System.Drawing.Rectangle' and '<null>'
This is one reason I dislike structs.
Thanks,
Aalst
>> UPDATE
I figured a way around this. Setting a instance of a Rectangle to Rectangle.Empty, and then testing with IsEmpty property.
This works, but still doesn't tell me why, just that the implementor was prepared for it.
Anyway... still would like to know why (besides that it is a value type). Why Structs which are so similar to objects, and act like them in so many ways, can not act like them in this way thats all.
Thanks again,
Aalst
|
|
|
|
|
struct s and any other type that inherits from ValueType lives on the stack, and thus can't be null . ValueTypes are also copied by value instead of by reference, so assigning one System.Drawing.Rectangle to another only copies the values so any further changes to one won't affect the other.
Most struct based datatypes expose a static member named Empty which can be used for comparisons.
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thanks James for the detailed explaination.
:-D This is just me gripping about something that can't be changed now. It is not directed at anyone. :-D
Then they should not allow the use of 'new' to create one. Like in C++ you should have a choice of where you want it to be. Stack or Heap by the use of the keyword 'new' or not. If they are not going to allow you to put the struct on the heap then it should be just like an int and you do not be allowed to use the keyword 'new'.
Don't get me wrong I like C# for somethings, but I think Microsoft's attempts to merge C++ and Java missed the mark in a lot of areas.
I think Java, C#, and C++ have there place in the world and never will any one replace another in it.
Anyway, enough of my gripping about this stuff...
|
|
|
|
|
Hi Aalst, I have these problems all the time and I went searching for for more info. This is especially in regards to calling unmanaged functions that can either take a null or a struct as a parameter.
Firstly ,if it can be worked around try overloading the function, else define the struct as a class , but with an expilcit layout attribute (sequencial allways). This way the unmanaged function is "tricked" in to believing it is a struct.
Info can be viewed HandleRef Sample[^].
Hope this help
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
I wasn't having this problem with unmanaged code, it was with the .NET Framework itself, and the fact that they include structs in it.
However, the first time I tried to use COM InterOp a while back, it required a struct. This created another problem I have with the .NET Framework, how it InterOps with COM. If you add a reference to a COM DLL you only get the classes and interfaces, you do not get any functions, structs or enums. This causes great problems when you have to re-create these structs & enums in C#. First for enums you have to hope they are declared in the Header file (and usually they are) so that you can get the correct values for each member. As for structs, if they are simple data structs then usually no problem. However, when the struct implements a C++ only feature lie "union" you are screwed.
The "union" keyword really should be part of C# it is useful in some situations, and if they are not going to wrap structs and enums in the COM InterOp then they should provide you everything that you need to recreate them.
So the first time I tried to use an unmanaged function the struct it required had a union in it. Which there is NO WAY to recreate this in C#. I know how to simulate a union in C# but it has it's limits and it can not be used with unmanaged code.
Again Microsoft didn't think hard enough on how they were going to implement something, and it causes people problems (usually me).
Also BTW "ms-help://" links are environment dependent. They do not work in IE Directly. They only work in a MS Help utility or application. Like Visual Studio or MSDN Library. So if you see something you like in one of those then you can get it from the ONLINE MSDN library and provide that link.
Sorry for all my gripping, but maybe someone at Microsoft will see it someday and provide fix the problems in a future Service Pack release. (yeah Right!)
Aalst
|
|
|
|
|
Thanx for the insight I do agree, there are some parts that I just like, but I guess they cant make a language perfect for everyone, hence .NET and the ability to write in the language of choice, depending on the situation.
Aalst wrote:
Also BTW "ms-help://" links are environment dependent. They do not work in IE Directly.
Funny, mine does.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
The simplest solution is instantiate the structure as an object rather than as a structure. You can always use and explicit cast to get it back to a structure.
Only change is constant
|
|
|
|
|
Casting a sturct to an object is to much overhead. I would have to cast it every time it is needed. Thanks for the advice though.
All structs in the .NET Framework seem to have ways around this problem, by providing a static EMPTY member that you use like setting an object to null, and an IsEmpty property for testing against like testing against a null object. Only have to worry about 3rd party structs. I do not create structs in my code, since I do not like them. I use classes not structs.
In my opinion the only useful struct is one that does not have constructors or methods, just public members for use a simple data structure. To do more than this, you should just design it as a class not a struct. Struct's are from pre-OOD, and they should not have been brought into a new OO language. They have reasons for being in C++ for backwards compatibility, but they have no usefulness in C#.
Again this is just more of my ranting about a bad design choice on Microsoft part.
Aalst
|
|
|
|