VB Decompiler Forum Index VB Decompiler
Hosted by TheAutomaters.com
 
  MemberlistMemberlist
 

Non-VB Client + VB Dll with GUI - A Simple Case

 
   VB Decompiler Forum Index -> Visual Basic
Author Message
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sat Sep 04, 2004 6:09 am     Post subject: Non-VB Client + VB Dll with GUI - A Simple Case

This screenshot shows a demo in operation that has a VB dll initialising correctly in response to being loaded by a non-VB caller, in this case a PowerBasic client (sorry, I have no C!)

The VB dll, operating without a ThunderRt6Main window, has to show the Form modally, but by using secondary threads the client is still free to do pretty much whatever it wants, run its own GUI, etc, as demonstrated.

A ScreenShot is provided here, but I'll zip and attach the actual EXE and DLL used here, you should be able to run them as is, as long as they are in the same folder (it works fine on Win 2000 and my laptop XP/SP6), and has no external dependencies.

I'll describe the method a bit more in the next post...

Hope it's of some interest ..

Cheers
Back to top
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sat Sep 04, 2004 6:29 am     Post subject: Notes on the method

In the screenshot above, a process viewer window is included that shows the modules and windows of the process. Our VB is entry number 10, dmProject1.dll (17000000)


About the DLL

Apart from switching the DLL's entry point, and ensuring that nominated VB functions are exported, no other DLL customisations are involved. All the VB6 dll is VB6.

The dll does not require an explicit initialisation call, when loaded it will automatically detect the caller is not VB and adjust the startup procedure accordingly.

The goal of the initialisation is the same for any type of client, only the method has to be varied.

The aim in all cases is to achieve the goal by engineering a call to the DLL's own DllGetClassObject function, passing it an IClassFactory interface reference.

No object is actually instanced by this process, however the DLL will have been initialised sufficiently to enable it to create VB forms and controls.

The DLL shows a form with 2 buttons. Pressing one updates a time display on the form, pressing the other makes a call back to a nominated function in the PowerBasic client.


The ScreenShot

The window on the right has the focus, that's the PB client's window. PB calls an exported function, ShowForm, in the DLL, passing it the address of a function for VB to call when a Click Event happens on that button.

The user has just clicked on that "Client Callback" button, and the DLL has called the PB callback function which has displayed the message box seen.

Note that PB's message box is modeless by default, which is why I was able to give focus back to the client's main window.

A second press on the same button would produce a second message window.


One Form At A Time
As stated, this simple model can show only 1 Form at a time, but that might well be sufficient, and it can be rendered effectively modeless with respect to the client by th use of secondary threads, so it does have some useful functionality.

How does it stay up at all without anybody providing a message pump? Clearly it can't, and we can safely deduce without looking that the VB "Modal Show" method has its own independent message disptach loop, which keeps it supplied, and also provides the "modal" effects of blocking access to other top-level windows in the app. I will not exit until the form is hidden or closed.

So we can show a VB Form from a non-VB client without a ThunderRt6Main window, if we show it modally.

The dll is thus restricted, in this simple model, to showing one Form at a time.


Client Application

This simple model is implemented by simply delegating all the client's own processing, its window creation and message dispatch loop, to a background thread, where it will have its own message queue and not interfere with the main thread's message loop.

Here's its "Main" logic:
Code:

'
' 1. Start Worker Thread
'
Thread Create Worker(1) Suspend To pThread
Thread Resume pThread To T
'
' 2. Main loop (for main thread)
'
Do
ShowVBform vbCallBack ' that's modal, so this thread waits
vbRestart = 0 ' and on return, we then loop waiting
Do ' for either a request to redisplay the
Sleep 0 ' form, or the clousre of the main window.
Thread Status pThread To T
Loop Until (T = 0) Or vbRestart Or wStop
Loop While vbRestart And (wStop = 0)
'
' 3. Exit
'
WaitWorkerThread
MsgBox "End of this Demo, Thank you!", %MB_IconInformation


The worker thread runs a standard message pump, which drives the main window. The time display is kept up to date in that message loop.

If the user closes the VB form, it just gets hidden, and the main thread returns to its loop, where it waits for the worker thread to request re-display, or the user to close the main window.

If the "main window" of the client is closed, the VB form if visible will stay there, as it's a modal display. But now when we close it releases the main thread's loop so it can exit.

Code:

Function Worker(ByVal Param As Long) As Long
Dim tNow As Long, tLast As Long
Dim msg As tagMsg

InitmainWindow hModule

Do
If PeekMessage(Msg, %NULL, 0, 0, 1) Then
If msg.message = %WM_QUIT Then Exit Do
TranslateMessage Msg
DispatchMessage Msg
End If
UpdateClock ' update the time display
Sleep 0
Loop Until wStop
wstop = 1
End Function
Back to top
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sat Sep 04, 2004 6:40 am     Post subject:

The EXE and DLL used in this demo ....
Back to top
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sat Sep 04, 2004 4:52 pm     Post subject:

My Gosh! I think I've just found the true Grail of this particular quest - the real thing in other words - multiply instanced modeless VB forms for the same client!

This thread could have a short shelf life indeed ... I think it's redundant already

Following thorough verification (and dinner), I hope to present a much improved screen shot
Back to top
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sat Sep 04, 2004 7:03 pm     Post subject:

It's real! A new report will be required, but the new screen shot should show what I mean. We are back to simple single-threading, which is nice, too.

The same PB client will now request a new Form Instance every time the space bar is pressed. The form has lightweight controls and you can see they are working properly, as both Label and Image Click events are being correctly triggered
Back to top
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sat Sep 04, 2004 7:08 pm     Post subject:

When the Form's button is pressed, it changes to a new backgnd coloyr.

When the label control is clicked, it reports how many times this has occurred since the Form was instanced.

When the Image control is clicked, a similar report is made, also using the Label caption.
Back to top
_aLfa_
Site Admin


Joined: 21 Sep 2002
Posts: 233
Location: Aveiro, Portugal

Posted: Sun Sep 05, 2004 8:43 am     Post subject:

Although I'll never use this, it seems a very nice piece of code
_________________
One thing only I know, and that is that I know nothing. (Socrates)
Back to top
Dr Memory
Expert


Joined: 16 Aug 2004
Posts: 147
Location: Surrey, UK

Posted: Sun Sep 05, 2004 9:02 am     Post subject:

It's of little direct use to the reverse-engineering community, I'd have to agree

... but it's an example of the good things that can come out of sharing information.

I said elsewhere the structure information was critical in this DLL initialisation technique - actually now that I've refined it to this level, the structure info is no longer involved .....

But I'd never have got here without it! Not this easily, at any rate!
Back to top
_aLfa_
Site Admin


Joined: 21 Sep 2002
Posts: 233
Location: Aveiro, Portugal

Posted: Sun Sep 05, 2004 1:35 pm     Post subject:

I'm more than happy to know that
_________________
One thing only I know, and that is that I know nothing. (Socrates)
Back to top
   VB Decompiler Forum Index -> Visual Basic All times are GMT
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group