OK...after a few days of getting annoyed at having to encode and decode the data I sent using the vbGateway2.dll, in my case I used property bags, I decided to write soem code that did this for you.
I have added 3 classes to the vbGateway2.dll project. this are:
- Command
- Parameter
- Parameters
These are used to create a command (function) and it's params.
Say you referenced a DLL in your project and this DLL had the following function in a class called clsUsers:
VB Code:
Public Function FetchUsers(ByVal TaskCount As Long, ByVal Admin As Boolean) As String 'XML return
Then in your UI you would do:
VB Code:
Dim strXML As String
Dim objUsers As clsUsers
Set objUsers = New clsUsers
strXML = objUsers.FetchUsers(10, False)
Set objUsers = Nothing
This is straight forward, although using the vbGateway2.dll meant you had to somehow convert this into a single bit of data and do:
VB Code:
Dim strXML As String
Dim varData As Variant
'create data that the thread can decode and understand
strXML = mobjGateway.SendData(varData)
Then is te DataArrived event in the thread you had to decode the data, which can be hard if you are passing lots of encoded parameters.
This annoyed me, and I'm sure it did some of you 
The new command object deals with this for you.
So for the FetchUsers example I used above you would now do:
VB Code:
Private Sub FetchUsers(ByVal plngTaskCount As Long, ByVal plngAdmin As Boolean)
Dim objCommand As Command
Set objCommand = New Command
With objCommand
.Key = "FetchUsers"
.Parameters.Add "TaskCount", plngTaskCount
.Parameters.Add "Admin", pblnAdmin
End With
mobjGateway.PostCommand objCommand
Set objCommand = Nothing
End Sub
Now this is received by the gateway object in the thread and a new event is raised.
VB Code:
Private Sub mobjGateway_CommandArrived(Command As vbGateway2.Command, ByVal Synchronous As Boolean)
What you do now is:
VB Code:
Private Sub mobjGateway_CommandArrived(Command As vbGateway2.Command, ByVal Synchronous As Boolean)
Dim strXML As String
Dim objRet As Command
With Command
Select Case .Key
Case "FetchUsers"
strXML = FetchUsers(.Parameters.Item("TaskCount").Value, .Parameters.Item("Admin").Value
Set objRet = New Command
objRet.Key = "UsersFetched"
objRet.Parameters.Add "XML", strXML
mobjGateway.PostCommand objRet
Set objRet = Nothing
End Select
End With
End Sub
Private Function FetchUsers(ByVal plngTaskCount As Long, ByVal plngAdmin As Boolean) As String
'code to laod users from DB
End Function
Then you do pretty much the same thing in the calling thread to handle the return value:
VB Code:
Private Sub mobjGateway_CommandArrived(Command As vbGateway2.Command, ByVal Synchronous As Boolean)
Dim strXML As String
With Command
Select Case .Key
Case "UsersFetched"
strXML = .Parameters.Item("XML").Value
'code to deal with users in XML
End Select
End With
End Sub
Does this make sense.
I have updated the file searching demo so that it uses this new code. Makes things MUCH MCUH easier
There is also a new button on the Main UI screen called Cancel ALL searches. This sends a cancel command to ALL threads and terminates their search. This shows how simple it is to send and handle many different command, with or without parameters.
The above exmaple was how to load users Asynchronously...to do it synchronously you would do the following in the UI:
VB Code:
Private Sub FetchUsers(ByVal plngTaskCount As Long, ByVal plngAdmin As Boolean)
Dim strXML As String
Dim objCommand As Command
Set objCommand = New Command
With objCommand
.Key = "FetchUsers"
.Parameters.Add "TaskCount", plngTaskCount
.Parameters.Add "Admin", pblnAdmin
End With
strXML = mobjGateway.SendCommand(objCommand)
Set objCommand = Nothing
End Sub
Then in the thread you would have:
VB Code:
Private Sub mobjGateway_CommandArrived(Command As vbGateway2.Command, ByVal Synchronous As Boolean)
Dim strXML As String
Dim objRet As Command
With Command
Select Case .Key
Case "FetchUsers"
strXML = FetchUsers(.Parameters.Item("TaskCount").Value, .Parameters.Item("Admin").Value
mobjGateway.Reply = strXML
End Select
End With
End Sub
Even easier 
There is also a VERY simple demo of this in the root folder of the vbGateway2 project.
Just load Test.vpg group project and run it.
This simply has 2 buttons, send synchronously and send Asynchronously. This shows you a very simple example.
Just follow the same steps as in the 1st post.
Download the zip file and open it.
Open the vbGateway2 project and compile to your PC
Open the multithreading folder, and then open the ThreadUI folder. Open the SearchThread project and compile it. This is used for searching files. Many of these threads can be created and multiple searches can take place at the same time. Obviously the more search you have running at the same time the slower your PC will become. This is not the multithreadings codes fault 
If you DO NOT enter a file extension and you have many search threads open then your UI will become unresponsive. this is expected, since the amount of files, and their details, that are being sent to the client is bloody LOADS! and ANY app will become unresponse when dealing with this much data...again, this is not the codes fault.
I hope this helps.
Woof