|
Thanks for the clarification, TnTinMan. Much obliged. So much to learn...So little time!
|
|
|
|
|
|
Thank you, Bernhard!
I am testing it now.
|
|
|
|
|
That is the function, but the problem is the last argument, dwNewLong. In vb6, you could just use AddressOf dwNewLong and the world was happy. But in vb.Net you can't do that because its AddressOf() does not return an address, but a delegate object.
|
|
|
|
|
The AddressOf is fine; it's the P/Invoke declaration which is wrong. You're trying to pass a delegate to a parameter which is declared as taking an IntPtr . In unmanaged code, this would be fine, but in managed code, the parameter types need to match.
To call this method, you would need to declare an overload of the SetWindowLong method with the dwNewLong parameter declared as a WndProc delegate.
However, .NET offers much easier ways to accomplish the same thing. For example, in Windows Forms, you just need to override the WndProc method[^].
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard!
I am trying out all three suggestions to see what happens!
|
|
|
|
|
That's what I couldn't understand, was how to get the address out of the delegate. But one of the things I still get caught up with is that the documented data types for API functions are apparently not sacrosanct. I guess there is some leeway via overloading (which seems hard to find info on in the official sources). In that regard, is overloading the same as subclassing?
|
|
|
|
|
treddie wrote: is overloading the same as subclassing?
Overloading[^] means creating two or more methods with the same name but different signatures. Subclassing[^], in this context, usually means replacing the window procedure of an existing control to extend or alter its behaviour.
pinvoke.net[^] is usually a good place to start when you're looking to call an unmanaged Windows API.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
DoH!...I should have known better, but I forgot...Many years ago, I first learned about subclassing to solve a graphics issue, and should have recalled that subclasssing is, in a way, a sort of "hijacking", in that you make Windows THINK you are using a standard WindowProc(), when in fact you have redirected execution to a function of your own making. That way, Windows is satisfied, and you get to do neat stuff as a result.
|
|
|
|
|
Hi all,
I hope someone of the more experienced members watches this forum - it doesn't seem to be very frequented, but I urgently need a solution very soon. Let me also mention that I am a fairly unexperienced leisuretime programmer, and that scanning the internet and playing around with Expresso for days didn't help - so I set my hopes upon you now... Sniff | .
In my application I have to parse different file formats for regular expressions. The match patterns are divided by diffferent patterns of control characters, depending on the file format. A sample would be:
1
01:00:01:10
01:00:05:22
After the conquest and plundering
of the Inca empire by Spain
2
01:00:05:25
01:00:09:09
the Indians invented the
legend of El Dorado
3
01:00:09:12
01:00:13:24
a land of gold, located in the
swamps of the Amazon headwaters. I get fairly proper matches with this regex:
(?<Nummer>\d+)\r\n(?<TCStart>\d{2}:\d{2}:\d{2}:\d{2})\r\n(<TCEnd>\d{2}:\d{2}:\d{2}:\d{2})\r\n(?<Text>[a-zA-Z;1-9;\s;\p{P};\p{L}\p{M}]*)\r\n\r\n The problem is: If there's a '0' (zero) in the text - like e.g. in years ("this happened a.d. 1570") - the whole pattern won't match!? On the other hand, if I change "1-9" into the common "0-9" pattern, then I have only one matching result, which contains all the other supposed matches in its "Text" group.
I hope I expressed the problem in an understandable way... and I'll highly appreciate if someone could guide me to a better solution!
Thanks in advance
Mick
|
|
|
|
|
I think the Text portion could be:
(?<Text>((?!\d+\r\n).*\r\n)*)
(?!\d+\r\n) will exclude any line with number only
.* will include any line (except the lines with number only, as excluded by (?!\d+\r\n) )
Btw, I noticed you don't have ? before <TCEnd>
|
|
|
|
|
Wow - this seems to make it and even looks much simpler than what I've been fiddeling out in so many hours ! Thank you for ending my sleepless nights
BTW the ? must have got lost in the copy/paste process. It's part of the original.
Have a very nice weekend,
thank you very much!
|
|
|
|
|
Hi all.
Sorry for the frustration here, but I always dread going to MS for any kind of help anymore, regarding what this-or-that does. For years now, they are extremely spotty in their ability to describe something simply and unambiguously. Below is a perfect example; a paragraph which talks in circles:
"The WithEvents statement and the Handles clause provide a declarative way of specifying event handlers. An event raised by an object declared with the WithEvents keyword can be handled by any procedure with a Handles statement for that event, as shown in the following example:"
Sounds like lawyer talk, so whenever I run into lawyer talk, I try to reword it into an explicit example. So here goes.
"A button's mouse click event raised by a button, declared with the WithEvents keyword can be handled by any procedure with a Handles statement for the button mouse click event..."
That's like saying "A box with a lid, has a lid on it."
It seems to be saying that if I use the WithEvents keyword, I can attach, for example, the statement, "Handles Button3.Click" on to ANY procedure and the procedure will respond to the Button3.Click event. Well...Duh! I can do that withOUT the WithEvents keyword! So what is the difference?
Or did they MEAN to say,
"A user can declare a custom event with the WithEvents keyword. Then, any procedure can use that event just like any other event, by attaching it at the end of a procedure's declaration, with the "Handles" clause."
If so, why use the keyword "WithEvents at all? Why not just,
Public Event MyCustomEvent
End Event
OR, are they trying to say this,
'Using the WithEvents keyword, a class is declared that can contain multiple events, any of which can be used at the end of a procedure's declaration with the "Handles" clause. For example,
Dim WithEvents MyEventsCollection As New EventsCollection1
Class EventsCollection1
Public Event My1stEvent()
Public Event My2ndEvent()
End Class
'Then, any procedure can have a Handles clause at the end of it, which assigns any of the events in the collection,
Private Sub ThisProcedure() Handles EventsCollection1.My1stEvent
End Sub
If THAT is what they mean, why put all of those events in a collection (a Class), instead of just calling them all out individually? That is a lot less work:
Private Sub ThisPrcoedure() Handles My1stEvent, My2ndEvent
End Sub
Please help me straighten this out, since I am obviously missing something really important about WithEvents that MS can't explain without ambiguity.
|
|
|
|
|
treddie wrote: If so, why use the keyword "WithEvents at all? Why not just,
"VB6"
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Do you mean that it is a left-over from vb6?
|
|
|
|
|
It was already there[^], yes
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Try reading this old article on MSDN.[^]
Truthfully, I haven't used WithEvents for anything in about 10 years. I found that I prefer to wire up the events I need myself instead of relying on Handles.
|
|
|
|
|
Thanks for the links. It's taking a while, since I have to fit reading them into my schedule. I am in the middle of Article 2.
|
|
|
|
|
How to find the size of a structure in vb.net?
Here is my structure
Public Structure MyStruct
Public a As Byte
Public b As Integer
Public c As Double
Public d As Double
End Structure
|
|
|
|
|
Find out the size of the different data types and add them together, this will give you the max size.
The exercise is left to the student!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Thanks Mycroft Holmes. Earlier in visual basic 6.0 we can use simply Len(structName). If the structure is too lengthy, it will be difficult to use this method..? Is there any other way ?
|
|
|
|
|
Doesn't the managed layout use the default packing/alignment as well, or is that only for P/Invoke?
The C# sizeof (the unsafe operator, not the Marshal.SizeOf method - see Dave's comment and Eric Lippert's blog) reports the size of this structure as 24, but the individual fields would only account for 21 bytes.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
That depends on what you're doing with the structure.
Read this[^].
|
|
|
|
|
Hi everyone.
Built small package in vb 2005 with reportviewer. However when i converted it in vb 2010, all the forms with a reportviewer control do not work and give errors. I tried to drag and drop the control onto the form anew. It shows the action is taken place but no effect meaning the control is not placed onto the form at all.
This is my first time using vb 2010.
Thanks
|
|
|
|
|
I know your question states VS2010, but by chance are you using the express edition?
|
|
|
|