|
-
May 13th, 2001, 03:46 AM
#1
Multi Threading Problem
I understand that there is a problem to call for a Visual basic function from a thread that no it created. How can I overcome it though, Heard that Messaging is optional but I do not know how to implement it.
Any help would be appriciated,
FatMan
-
May 14th, 2001, 04:47 AM
#2
Re: Multi Threading Problem
it you are talking about normal function in standard module, it should be ok to be called by other thread, just to beware on global variable as VB is apartment-threaded.
if you are talking about Form function, then sending message is one way. but before you send the message, you need to subclass the form to capture the message that u r going to use.
refer http://vblib.virtualave.net there is 2 class, vbSubclassing & vbMultiThreading that make u life easy, HTH
maybe ur situation is a bit difficult, but if I didn't answer ur question, let make me understand and maybe I can be more helpful.
-
May 14th, 2001, 06:18 AM
#3
Re: Multi Threading Problem
I am trying the Messaging way now for some time, I sent message from a Dll function I called numbered 555 and could not catch it in VB, I will try again, but if you have a sample code for messaging with DLL I would be very greatfull.
FatMan
-
May 14th, 2001, 07:51 PM
#4
Re: Multi Threading Problem
you should got an example. Please note, user define message must be declare as follow
WM_LEV_MSG = WM_USER + 555&
instead of
WM_LEV_MSG = 555&
cause may be used by the system, by adding WM_USER, you are safe.
-
May 15th, 2001, 06:29 AM
#5
Re: Multi Threading Problem
For completeness you should not create your own constant for your message like this because you have no guarantee that some other program might not use that same value for one of it's messages and broadcast it thus confusing your application.
To prevent this you should register your windows message using the RegisterWindowsMessage API call:
'Declaration
private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (byval lpString as string) as Long
What I tend to do is have this wrapped up in a function shared by both applications thus:
public Function LevWindowMessage() as Long
If mMessage = 0 then
mMessage = RegisterWindowMessage("WM_LEV_MSG")
End If
LevWindowMessage = mMessage
End Function
Which you can then send and recieve safely.
For a complete example of how this is used, see the example on http://www.planetsource.com entitled "A better systray".
-------------------------------------------------
Ex. Datis: Duncan Jones
Merrion Computing Ltd
http://www.merrioncomputing.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|