473,425 Members | 1,806 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

Event help needed

Jon
I have a service program that creates a crystal report and prints the report
to a named printer driver. The printer driver raises an event when it is
finished. I am supposed to trap for the following event to determine when I
can continue with my code flow.
Event:
%printername%.mfx.complete

Can anyone help me out with some sample code to loop and wait for this
event? I found one example in C#, but I'm not having much luck getting to
work in vb.net.

I'm using v. 2003.

Thanks!
Nov 23 '05 #1
6 1358
inside of a sub (probably new())

addhandler %printername%.mfx.complete, addressof PrintJobComplete
Private Sub PrintJobComplete
'call the rest of your code here
end sub
--
--Eric Cathell, MCSA
"Jon" <ru******@msn.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
I have a service program that creates a crystal report and prints the
report to a named printer driver. The printer driver raises an event when
it is finished. I am supposed to trap for the following event to determine
when I can continue with my code flow.
Event:
%printername%.mfx.complete

Can anyone help me out with some sample code to loop and wait for this
event? I found one example in C#, but I'm not having much luck getting to
work in vb.net.

I'm using v. 2003.

Thanks!

Nov 23 '05 #2
Jon
Thank you. Apparently, this article below demonstrates how it should be
done, but it's in C#, and I can't get it converted correctly.
http://www.codeproject.com/csharp/interopevents.asp

I did try your method, but the %printername% is just a string name of the
printer. I'm not very familiar with using named events, sorry.
"ECathell" <ec******@nospam.com> wrote in message
news:%2***************@TK2MSFTNGP15.phx.gbl...
inside of a sub (probably new())

addhandler %printername%.mfx.complete, addressof PrintJobComplete
Private Sub PrintJobComplete
'call the rest of your code here
end sub
--
--Eric Cathell, MCSA
"Jon" <ru******@msn.com> wrote in message
news:uH**************@TK2MSFTNGP09.phx.gbl...
I have a service program that creates a crystal report and prints the
report to a named printer driver. The printer driver raises an event when
it is finished. I am supposed to trap for the following event to
determine when I can continue with my code flow.
Event:
%printername%.mfx.complete

Can anyone help me out with some sample code to loop and wait for this
event? I found one example in C#, but I'm not having much luck getting
to work in vb.net.

I'm using v. 2003.

Thanks!


Nov 23 '05 #3

Jon wrote:
Thank you. Apparently, this article below demonstrates how it should be
done, but it's in C#, and I can't get it converted correctly.
http://www.codeproject.com/csharp/interopevents.asp


Ah, what we're talking about here aren't .NET events, they are Win32
events. So really, since C# and VB.NET both interop with Win32 in a
very similar way, it's just a translation problem. Let's see your VB
translation :)

--
Larry Lard
Replies to group please

Nov 23 '05 #4
Jon
Yes, I'm sorry, these are win32 events. My conversion follows

The three errors I get are
1)Dim unEventPermissions As UInt32 = 2031619
It says error converting 2031619 to a UInt32
2) OpenEvent was not found in dll Kernel32.dll
3) IntPtr.Zero = hEvent
operator = is not defined for IntPtr

Here it is:

Namespace CSharpEventSink
' <summary>
' Summary description for Class1.
' </summary>
Class Class1

'OPEN EVENT
Private Declare Function OpenEvent Lib "Kernel32.dll" (ByVal
dwDesiredAccess As UInt32, ByVal bInheritHandle As Boolean, ByVal lpName As
String) As IntPtr

' <summary>
' The main entry point for the application.
' </summary>
<STAThread()> _
Private Shared Sub Main(ByVal args() As String)
Dim unEventPermissions As UInteger = 2031619
' Same as EVENT_ALL_ACCESS value in the Win32 realm
Dim hEvent As IntPtr = IntPtr.Zero
' Get a handle to the Win32 Event. The name, "MfcEventSource",
is known in advance
hEvent = OpenEvent(unEventPermissions, False, "MfcEventSource")
If (IntPtr.Zero = hEvent) Then
Console.WriteLine("OpenEvent failed")
Return
' Exit
End If
' Create an AutoResetEvent object to wrap the handle we got from
OpenEvent
Dim arEvent As AutoResetEvent = New AutoResetEvent(False)
arEvent.Handle = hEvent
' Set the Handle to the event from
Dim waitHandles() As WaitHandle
'Put it in our array for WaitAny()
waitHandles(0) = arEvent
Dim bDone As Boolean = False

While Not bDone
Console.WriteLine("Top of while")
Dim waitResult As Integer = WaitHandle.WaitAny(waitHandles,
2000, False)
' For timeout, just loop and wait again
If (waitResult = WaitHandle.WaitTimeout) Then
Console.WriteLine(" WaitAny timed out.")
ElseIf (0 = waitResult) Then
Console.WriteLine("0 == waitResult. Yippee !!!")
' Do Something
ElseIf (1 = waitResult) Then
Console.WriteLine("1 == waitResult !!!")
' Do Something Else
Else
Console.WriteLine("Error else")
End If

End While
End Sub
End Class
End Namespace
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Jon wrote:
Thank you. Apparently, this article below demonstrates how it should be
done, but it's in C#, and I can't get it converted correctly.
http://www.codeproject.com/csharp/interopevents.asp


Ah, what we're talking about here aren't .NET events, they are Win32
events. So really, since C# and VB.NET both interop with Win32 in a
very similar way, it's just a translation problem. Let's see your VB
translation :)

--
Larry Lard
Replies to group please

Nov 23 '05 #5

Jon wrote:
Yes, I'm sorry, these are win32 events. My conversion follows
I inferred the necessary Imports statements from the C# source :)

The three errors I get are
1)Dim unEventPermissions As UInt32 = 2031619
It says error converting 2031619 to a UInt32
Until VB2005 (I think), VB's support for unsigned types such as UInt32
is not ideal. You have to do this to initialize one:

Dim unEventPermissions As UInt32 = Convert.ToUInt32(2031619)

(Here the conversion is actually from a Long, which is what the
compiler assumes 2031619 is)

2) OpenEvent was not found in dll Kernel32.dll
When P/Invoking API functions that have both ANSI and Unicode versions,
you need to add 'Ansi', 'Unicode', or (usually the appropriate choice)
'Auto' to the Declare statement. If you did any API work in VB classic,
you may remember having to always declare the -A version of APIs - this
is the improved replacement for that. So:

Private Declare Auto Function OpenEvent Lib "Kernel32.dll"
(ByVal _
dwDesiredAccess As UInt32, ByVal bInheritHandle As Boolean, _
ByVal lpName As String) As IntPtr

3) IntPtr.Zero = hEvent
operator = is not defined for IntPtr
Until VB2005 (I think), VB doesn't support operator overloading (ie
redefining things like = to have a specific meaning for non-intrinsic
types), so we have to explicitly call Equals:

If IntPtr.Zero.Equals(hEvent) Then

The rest is fine.


Here it is:

Namespace CSharpEventSink
' <summary>
' Summary description for Class1.
' </summary>
Class Class1

'OPEN EVENT
Private Declare Function OpenEvent Lib "Kernel32.dll" (ByVal
dwDesiredAccess As UInt32, ByVal bInheritHandle As Boolean, ByVal lpName As
String) As IntPtr

' <summary>
' The main entry point for the application.
' </summary>
<STAThread()> _
Private Shared Sub Main(ByVal args() As String)
Dim unEventPermissions As UInteger = 2031619
' Same as EVENT_ALL_ACCESS value in the Win32 realm
Dim hEvent As IntPtr = IntPtr.Zero
' Get a handle to the Win32 Event. The name, "MfcEventSource",
is known in advance
hEvent = OpenEvent(unEventPermissions, False, "MfcEventSource")
If (IntPtr.Zero = hEvent) Then
Console.WriteLine("OpenEvent failed")
Return
' Exit
End If
' Create an AutoResetEvent object to wrap the handle we got from
OpenEvent
Dim arEvent As AutoResetEvent = New AutoResetEvent(False)
arEvent.Handle = hEvent
' Set the Handle to the event from
Dim waitHandles() As WaitHandle
'Put it in our array for WaitAny()
waitHandles(0) = arEvent
Dim bDone As Boolean = False

While Not bDone
Console.WriteLine("Top of while")
Dim waitResult As Integer = WaitHandle.WaitAny(waitHandles,
2000, False)
' For timeout, just loop and wait again
If (waitResult = WaitHandle.WaitTimeout) Then
Console.WriteLine(" WaitAny timed out.")
ElseIf (0 = waitResult) Then
Console.WriteLine("0 == waitResult. Yippee !!!")
' Do Something
ElseIf (1 = waitResult) Then
Console.WriteLine("1 == waitResult !!!")
' Do Something Else
Else
Console.WriteLine("Error else")
End If

End While
End Sub
End Class
End Namespace
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@g47g2000cwa.googlegr oups.com...

Jon wrote:
Thank you. Apparently, this article below demonstrates how it should be
done, but it's in C#, and I can't get it converted correctly.
http://www.codeproject.com/csharp/interopevents.asp


Ah, what we're talking about here aren't .NET events, they are Win32
events. So really, since C# and VB.NET both interop with Win32 in a
very similar way, it's just a translation problem. Let's see your VB
translation :)

--
Larry Lard
Replies to group please


Nov 23 '05 #6
Jon
Thanks much!!
"Larry Lard" <la*******@hotmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...

Jon wrote:
Yes, I'm sorry, these are win32 events. My conversion follows


I inferred the necessary Imports statements from the C# source :)

Nov 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jim Mitchell | last post by:
I have some code behind that generates 10 imagebutton controls.... I can not seem to figure out how to trap the onclick event for each image and determine which image was clicked. Can someone...
3
by: Lachlan Hunt | last post by:
Hi, I've been looking up lots of documentation and trying to work out a cross-platform method of capturing a keyboard event and working out which key was pressed. From what I can find, there...
9
by: Mike | last post by:
How do I prevent SQL Server 2000 from posting successful backup completion messages to the Windows 2000 Application Event Log? I have scheduled jobs which backup my transaction logs on 50+...
6
by: Tom | last post by:
Hi, In the following code I have reproduced a problem in IE that is extremely annoying for my application. <html> <head> <script type="text/javascript">
15
by: Pohihihi | last post by:
This might sound little stupid to many but I was thinking that when we can use object why we really need event args to pass in any functions e.g. bool MyFunction(object sender, System.EventArgs...
27
by: Codemonkey | last post by:
Heya All, Sorry, but I think it's about time for a monkey-ramble. I've just had enough of trying to serialize even simple objects with VB. A simple task you may think - stick the...
8
by: Csaba Gabor | last post by:
Is there any way in Mozilla/Firefox to add an event listener to all textarea elements? Something along the lines of HTMLTextAreaElement.prototype.onkeydown = function() {alert('mom');} only it...
3
by: jm | last post by:
>From a C. Petzold book I have Programming Windows C#. It's a little old now, but anyway, it has on page 71 (shortened): form.Paint += new PaintEventHandler(MyPaintHandler); static void...
2
by: Salad | last post by:
This was an interesting problem. I open a form, CalledForm. When a record is presented in CalledForm I needed to check the status of something. If the status is met, I needed to present...
8
by: Brad Walton | last post by:
Hello. First post, but been doing a bit of reading here. I am working on a project in Java, but decided to switch over to C# after seeing some of the additional features I can get from C#. One of...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.