Author | Forum: General Questions Topic: HOW TO: Using our ActiveX controls in a .NET service |
Tony Priest![]() From: Utica, NY USA Posts: 8466 Member Since: 04/11/00 |
posted October 14, 2004 9:49 AM This "How to" applies to using our ActiveX controls in a .NET service. Note that this problem does not occur with our .NET components. Due to the way messages are processed in a .NET service, you need add an Idle loop so that messages are processed after the server starts. Here is how to do it in VB: Add the following to the top of your main code file: Public Delegate Sub IdleDelegate() Private bStarted As Boolean Add this to the beginning of your OnStart event: Dim o() As Object Dim i As New IdleDelegate(AddressOf Idle) i.BeginInvoke(New AsyncCallback(AddressOf DoNothingCallBack), o) Add this to the end of your OnStart event: bStarted = True Add this to your OnStop event: bStarted = False Add the following subroutines: Protected Sub Idle() While bStarted = True MessageProcessing.Idle() End While End Sub Private Sub DoNothingCallBack(ByVal ar As IAsyncResult) End Sub Lastly, create a new module called "MessageProcessing.vb" and add the following code: Module MessageProcessing Private Const WM_APP = &H8000 Private Const M_ADDRESS_EVENT = WM_APP Private Const M_CLOSE_EVENT = WM_APP + 2 Private Structure POINTAPI Public x As Integer ' X-Coordinate in pixels Public y As Integer ' Y-Coordinate in pixels End Structure Private Structure MSG Public hWnd As IntPtr ' Window handle of the associated window Public Message As Integer ' Message identifier Public wParam As IntPtr ' Additional message info Public lParam As IntPtr ' Additional message info Public time As Integer ' Time message was posted Public pt As POINTAPI ' Cursor position when message was posted End Structure Private Declare Auto Function GetMessage Lib "user32" _ (ByRef lpMsg As MSG, _ ByVal hWnd As IntPtr, _ ByVal wMsgFilterMin As Integer, _ ByVal wMsgFilterMax As Integer) As Boolean Private Declare Function TranslateMessage Lib "user32" _ (ByRef lpMsg As MSG) As Boolean Private Declare Auto Function DispatchMessage Lib "user32" _ (ByRef lpMsg As MSG) As IntPtr Private Declare Auto Function PeekMessage Lib "user32" _ (ByRef lpMsg As MSG, _ ByVal hWnd As Long, _ ByVal wMsgFilterMin As Long, _ ByVal ByValwMsgFilterMax As Long, _ ByVal wRemoveMsg As Long) As Long Public Function Idle() As Boolean Dim Msg As New MSG If GetMessage(Msg, Nothing, M_ADDRESS_EVENT, M_CLOSE_EVENT) Then TranslateMessage(Msg) DispatchMessage(Msg) Return True End If Return False End Function End Module |
Reply | General Questions Topics | Forums |
This site is powered by
![]() |