Custom message loop

  • Thread starter Thread starter Nak
  • Start date Start date
N

Nak

Hi there,

I am attempting to make a custom message loop in VB.NET so that I can
use it for interprocess communication. At current I am successfully
creating a window class that never actually gets drawn to screen so that I
can recieve messages, this seems to work but for only a few messages then
all of a sudden my application seems to start unloading.

I have a class that exposes shared methods, mainly windows API's and
types, after a couple of messages have been sent to the "windowless" I can
no longer use any of the shared methods as I am being told that the object
is not referenced, I never thought it was??!?

I am wondering if there is anything else that I should be processing in
order to keep this object alive, currently my Windows message handler looks
like so...

-----

Private Function MyWndProc(ByVal hWnd As Integer, ByVal msgvalue As Integer,
ByVal wParam As Integer, ByVal lParam As Integer) As Integer
Dim pIntRetVal As Integer

Select Case msgvalue
Case WM_DESTROY
Call PostQuitMessage(0)
Case Else
RaiseEvent messageRecieved(msgvalue, wParam, lParam)
pIntRetVal = DefWindowProc(hWnd, msgvalue, wParam, lParam)
End Select

Return (pIntRetVal)

End Function

-----

I seem to be able to send about 2 or 3 of my own messages to the window
before it suddenly stops working, maybe it has something to do with
DefWindowProc being called at the wrong time?

If anyone has any suggestions I would be most appreciative. Thanks
loads in advance!!!

Nick.
 
Hi Nak,

I suggest you create a new thread to do the interprocess communication by
message loop. Because one thread will be associated with one message queue,
if there is something making MyWndProc hang, then all the thread including
the main window's winproc will hang.

Also can you describe your senario more detailed, there may be another
solution.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Ahh, not to worry, I have utilized the NativeForm class to produce a
solution that actually works.

Nick.
 
Hi Peter,

I managed to get a working solution via inheriting from NativeForm. All
is sorted now!

Nick.
 
Back
Top