473,385 Members | 1,546 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Automation Issues

I have a VB6 Application that shells out some activity to another VB6
application in a separate thread. This second application relies
heavily upon the Microsoft Access 10.0 Object Library. I have also
used the Microsoft Access 11.0 Object Library. This second application
grabs recordsets from the Access mdb by using the below set of
commands.

Set qdfX = objAccess.CurrentDb.CreateQueryDef("", strSQLX)
Set rstX = qdfX.OpenRecordset()

I did not write this and I personally find this method of grabbing data
from Access to be a rather poor design choice, but it is entrenched
within the application, and it is unlikely that I can change it at this
point.

I believe the use of the automation in this manner may be causing the
application to freeze on some machines. It causes it and its parent
application to freeze as well. The rest of the machine continues to
run normally, and I have to kill the processes in Task Manager.

The second app is started from the first application with the code
below

ExecCmdLineEx """" & gstrDataManagerPath & "\" & DATA_MANAGER_EXE & """
-e[i2] -a[1]", SW_SHOWMINNOACTIVE, ABOVE_NORMAL_PRIORITY_CLASS

----ExecCmdLineEx Module----

Option Explicit

Private Type STARTUPINFO
cb As Long
lpReserved As String
lpDesktop As String
lpTitle As String
dwX As Long
dwY As Long
dwXSize As Long
dwYSize As Long
dwXCountChars As Long
dwYCountChars As Long
dwFillAttribute As Long
dwFlags As Long
wShowWindow As Integer
cbReserved2 As Integer
lpReserved2 As Long
hStdInput As Long
hStdOutput As Long
hStdError As Long
End Type

Private Type PROCESS_INFORMATION
hProcess As Long
hThread As Long
dwProcessID As Long
dwThreadID As Long
End Type

Private Declare Function WaitForSingleObject _
Lib "kernel32" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long
_
) As Long

Private Declare Function CreateProcessA _
Lib "kernel32" ( _
ByVal lpApplicationName As
String, _
ByVal lpCommandLine As
String, _
ByVal lpProcessAttributes As
Long, _
ByVal lpThreadAttributes As
Long, _
ByVal bInheritHandles As
Long, _
ByVal dwCreationFlags As
Long, _
ByVal lpEnvironment As Long,
_
ByVal lpCurrentDirectory As
String, _
lpStartupInfo As STARTUPINFO,
_
lpProcessInformation As
PROCESS_INFORMATION _
) As Long

Private Declare Function CloseHandle _
Lib "kernel32" ( _
ByVal hObject As Long _
) As Long
Private Declare Function GetExitCodeProcess _
Lib "kernel32" ( _
ByVal hProcess As Long, _
lpExitCode As Long _
) As Long
Private Const INFINITE = -1&

'Show Window Constants
Private Const SW_HIDE = 0
Private Const SW_SHOWNORMAL = 1
Private Const SW_SHOWMINIMIZED = 2
Private Const SW_MAXIMIZE = 3
Private Const SW_SHOWMAXIMIZED = 3
Private Const SW_SHOWNOACTIVATE = 4
Private Const SW_SHOW = 5
Private Const SW_MINIMIZE = 6
Private Const SW_SHOWMINNOACTIVE = 7
Private Const SW_SHOWNA = 8
Private Const SW_RESTORE = 9
Private Const SW_SHOWDEFAULT = 10
'End Show Window Constants

'Priority Class Constants
Private Const REALTIME_PRIORITY_CLASS = &H100&
Private Const HIGH_PRIORITY_CLASS = &H80&
Private Const ABOVE_NORMAL_PRIORITY_CLASS = &H8000&
Private Const NORMAL_PRIORITY_CLASS = &H20&
Private Const BELOW_NORMAL_PRIORITY_CLASS = &H4000&
Private Const IDLE_PRIORITY_CLASS = &H40&
'End Priority Class Constants

Public Function ExecCmdLineEx( _
szCommandLine, _
Optional nCmdShow As Variant, _
Optional dwPriorityCreationFlags As
Variant _
) As Long

Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
Dim lngReturnCode As Long

Const STARTF_USESHOWWINDOW = &H1

' Initialize the STARTUPINFO structure:
With start
.cb = Len(start)

'If this is missing then wShowWindow is ignored
.dwFlags = STARTF_USESHOWWINDOW
If (IsNull(nCmdShow)) Then
.wShowWindow = SW_SHOW
Else
.wShowWindow = nCmdShow
End If

End With

' Start the shelled application:

If IsNull(dwPriorityCreationFlags) Then
lngReturnCode = CreateProcessA(vbNullString, _
szCommandLine, _
0&, _
0&, _
1&, _
NORMAL_PRIORITY_CLASS, _
0&, _
vbNullString, _
start, _
proc _
)
Else
lngReturnCode = CreateProcessA(vbNullString, _
szCommandLine, _
0&, _
0&, _
1&, _
dwPriorityCreationFlags, _
0&, _
vbNullString, _
start, _
proc _
)
End If

' Wait for the shelled application to finish:
lngReturnCode = WaitForSingleObject(proc.hProcess, INFINITE)
Call GetExitCodeProcess(proc.hProcess, lngReturnCode)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)

ExecCmdLineEx = lngReturnCode

End Function

Any Ideas?

May 17 '06 #1
8 1659
yeah my idea is:

a) wake up to the 90s and dont use DAO for anything
b) wake up to the 90s and dont use MDB for anything
c) wake up to the 90s and dont use Vb6 for anything.

Access Data Projects are AWESOME!!

May 17 '06 #2
On 17 May 2006 07:14:51 -0700, ja**************@gmail.com wrote:

<snip>
' Wait for the shelled application to finish:
lngReturnCode = WaitForSingleObject(proc.hProcess, INFINITE)
Don't do an infinite wait
- don't wait, use DoEvents to keep your first App alive

'Wait
Do
WaitMessage ' JF
Me.Print ".";
Count = Count + 1
If Count > 100 Then
Count = 0
Me.Cls
End If
DoEvents
Loop While WaitForSingleObject(pinfo.hProcess, 0)
Call GetExitCodeProcess(proc.hProcess, lngReturnCode)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)

ExecCmdLineEx = lngReturnCode

End Function

Any Ideas?


May 18 '06 #3

"J French" <er*****@nowhere.uk> wrote in message
news:44****************@news.btopenworld.com...
On 17 May 2006 07:14:51 -0700, ja**************@gmail.com wrote:

<snip>
' Wait for the shelled application to finish:
lngReturnCode = WaitForSingleObject(proc.hProcess, INFINITE)


Don't do an infinite wait
- don't wait, use DoEvents to keep your first App alive

'Wait
Do
WaitMessage ' JF
Me.Print ".";
Count = Count + 1
If Count > 100 Then
Count = 0
Me.Cls
End If
DoEvents
Loop While WaitForSingleObject(pinfo.hProcess, 0)


This will make this code highly computable while it actually does nothing.
It makes the app responsive to user events which may be a good thing.
OTH the rest of the code in the app needs to take care not to interfere with
this unfinished business or use information from this activity until it's
finished.

Those dots on the screen will becoming thick and fast too.

A small time out of say 500ms might be worth introducing.

If the created process is hung then this look never exits so an additional
counter might be needed to terminate the loop after certain period has
elapsed.
Call GetExitCodeProcess(proc.hProcess, lngReturnCode)
Call CloseHandle(proc.hThread)
Call CloseHandle(proc.hProcess)

ExecCmdLineEx = lngReturnCode

End Function

Any Ideas?

May 20 '06 #4
On Sat, 20 May 2006 12:45:35 +0100, "Anthony Jones"
<An*@yadayadayada.com> wrote:

<snip>
This will make this code highly computable while it actually does nothing.
No, it will make the App do nothing until there is a Message in the
Apps Windows Message Queue

WaitMessage releases everything to Windows until a Message comes in,
then it returns immediately

I'm assuming that :
WaitForSingleObject(pinfo.hProcess, 0)
generates a WindowsMessage, or more specifically that a closing App
generates one.
It makes the app responsive to user events which may be a good thing.
Sure is
OTH the rest of the code in the app needs to take care not to interfere with
this unfinished business or use information from this activity until it's
finished.
Better that, than have a totally frozen App that cannot even re-paint
itself
Those dots on the screen will becoming thick and fast too.
Not if they are Remmed out
- they are only there in the example to give a visual indication of
what is going on
A small time out of say 500ms might be worth introducing.
Why bother ?
If a message needs processing, then process it
If the created process is hung then this look never exits so an additional
counter might be needed to terminate the loop after certain period has
elapsed.


You are right about that, but that was not the question

If you want to do that then activate a normal VB Timer with a interval
of say 1 sec to act as a Message pump

That way the App will get at least 1 msg per sec, and the code in the
loop can decide when to cop out.

You need to have a serious look at what WaitMessage does, it is a
fascinating beast
- and extremely efficient at keeping down unnecessary processing

It can be used for all sorts of tasks, my favourite is for totally
hijacking the Windows loop
May 21 '06 #5

"J French" <er*****@nowhere.uk> wrote in message
news:44****************@news.btopenworld.com...
On Sat, 20 May 2006 12:45:35 +0100, "Anthony Jones"
<An*@yadayadayada.com> wrote:

<snip>
This will make this code highly computable while it actually does nothing.

No, it will make the App do nothing until there is a Message in the
Apps Windows Message Queue

WaitMessage releases everything to Windows until a Message comes in,
then it returns immediately

I'm assuming that :
WaitForSingleObject(pinfo.hProcess, 0)
generates a WindowsMessage, or more specifically that a closing App
generates one.

Oops I didn't spot that WaitMessage function. It might be useful to the OP
to provide it's declare (simple though it might be I didn't spot it and it's
not obvious its an API call):-

Private Declare Function WaitMessage Lib "user32" () As Long

However I can't see how the termination of the launched process would
generate a windows message to cause waitmessage to return.
It makes the app responsive to user events which may be a good thing.


Sure is
OTH the rest of the code in the app needs to take care not to interfere withthis unfinished business or use information from this activity until it's
finished.


Better that, than have a totally frozen App that cannot even re-paint
itself


Agreed but there is more work that needs to be done and I still don't think
a DoEvents loop is the approach to take.
Those dots on the screen will becoming thick and fast too.


Not if they are Remmed out
- they are only there in the example to give a visual indication of
what is going on


They would in fact be a little random since they depend on messages
arriving.
A small time out of say 500ms might be worth introducing.
Why bother ?
If a message needs processing, then process it


That statement was made without the WaitMessage function being spotted.
If the created process is hung then this look never exits so an additionalcounter might be needed to terminate the loop after certain period has
elapsed.
You are right about that, but that was not the question


Yes the OP wasn't interested in any of this. It's a little ambiguous but
appears the OP seems to be wondering whether launching the process in this
manner may be the reason it is freezing (the called process). A secondary
affect being that the calling process freezes.

The answer is I doubt this manner of launching the process is causing it to
freeze but it's difficult to tell.
If you want to do that then activate a normal VB Timer with a interval
of say 1 sec to act as a Message pump

That way the App will get at least 1 msg per sec, and the code in the
loop can decide when to cop out.

You need to have a serious look at what WaitMessage does, it is a
fascinating beast
- and extremely efficient at keeping down unnecessary processing

It can be used for all sorts of tasks, my favourite is for totally
hijacking the Windows loop


I think in this case a better design would be to launch the app but not loop
at all.

Use a timer to check whether the process handle has been signalled.

Modify the parent app to ensure invalid actions are not taken whilst this
secondary process is operating.

TBH I've never come across a problem that might be solved using a DoEvents
loop that couldn't be better solved without one. Especially if the
developer is happy dipping into the windows API.
May 21 '06 #6
On Sun, 21 May 2006 08:54:09 +0100, "Anthony Jones"
<An*@yadayadayada.com> wrote:
<snip>
Oops I didn't spot that WaitMessage function. It might be useful to the OP
to provide it's declare (simple though it might be I didn't spot it and it's
not obvious its an API call):- Private Declare Function WaitMessage Lib "user32" () As Long
Since the original post was a jiggered form of Shell And Wait from the
KPD All API Guide, I figured that the OP would realize that
WaitMessage is an API
However I can't see how the termination of the launched process would
generate a windows message to cause waitmessage to return.
It seems it does
- when an App unloads it creates a bundle of activity within Windows
- also Windows knows very well which thread launched the App
- I just found that it is reliable
>It makes the app responsive to user events which may be a good thing.


Sure is
>OTH the rest of the code in the app needs to take care not to interferewith >this unfinished business or use information from this activity until it's
>finished.


Better that, than have a totally frozen App that cannot even re-paint
itself Agreed but there is more work that needs to be done and I still don't think
a DoEvents loop is the approach to take.
Why not ?
a) it is not hammering the processor
b) it is not 'blocking' the App

Anyway an App's Window Message queue is just a loop using a variation
of WaitMessage

// Start the message loop.

while (GetMessage(&msg, (HWND) NULL, 0, 0))

{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
>Those dots on the screen will becoming thick and fast too.
Not if they are Remmed out
- they are only there in the example to give a visual indication of
what is going on They would in fact be a little random since they depend on messages
arriving.
Less random than you would expect
- they go bananas when you move the mouse, but otherwise there are
very few of them
>A small time out of say 500ms might be worth introducing.


Why bother ?
If a message needs processing, then process it That statement was made without the WaitMessage function being spotted.
>If the created process is hung then this look never exits so an

additional >counter might be needed to terminate the loop after certain period has
>elapsed.


You are right about that, but that was not the question

Yes the OP wasn't interested in any of this. It's a little ambiguous but
appears the OP seems to be wondering whether launching the process in this
manner may be the reason it is freezing (the called process). A secondary
affect being that the calling process freezes.
<quote>
I believe the use of the automation in this manner may be causing the
application to freeze on some machines. It causes it and its parent
application to freeze as well.
</quote>

The code is deliberately freezing the Calling App until the Called App
returns
- it has nothing to do with the Called App, once that is running the
calling App has no influence
The answer is I doubt this manner of launching the process is causing it to
freeze but it's difficult to tell.
It is definitely freezing the Caller
- which is pretty darn silly for a 3+ minute process
If you want to do that then activate a normal VB Timer with a interval
of say 1 sec to act as a Message pump That way the App will get at least 1 msg per sec, and the code in the
loop can decide when to cop out. You need to have a serious look at what WaitMessage does, it is a
fascinating beast
- and extremely efficient at keeping down unnecessary processing It can be used for all sorts of tasks, my favourite is for totally
hijacking the Windows loop

I think in this case a better design would be to launch the app but not loop
at all.
There are two types of Looping
a) inefficient looping
-using pure DoEvents that raises CPU usage to 100%
b) efficient looping that responds immediately to Windows
Use a timer to check whether the process handle has been signalled.
That is a possibility
- in this case I would use an AX Exe and run the process off its
internal thread
- or use a normal Exe and set up a communications system

Sometimes Waiting is sensible
- especially if there is not much you can do until the thing comes
back with a result
Modify the parent app to ensure invalid actions are not taken whilst this
secondary process is operating.
Dead easy, a Modal Form with an Abort button
TBH I've never come across a problem that might be solved using a DoEvents
loop that couldn't be better solved without one. Especially if the
developer is happy dipping into the windows API.


I am trying to explain to you that

While Something
WaitMessage
DoEvents
Wend

Is NOT a DoEvents Loop
- it is the equivalent of popping up a Modal Form ( and you can be
sure that is how Modal Forms work )

As I said before, you would be wise to look into the implications of
WaitMessage
- a lot of VB programmers don't understand it
May 21 '06 #7

"J French" <er*****@nowhere.uk> wrote in message
news:44**************@news.btopenworld.com...
On Sun, 21 May 2006 08:54:09 +0100, "Anthony Jones"
<An*@yadayadayada.com> wrote:
<snip>
Oops I didn't spot that WaitMessage function. It might be useful to the OP
to provide it's declare (simple though it might be I didn't spot it and it'snot obvious its an API call):-
Private Declare Function WaitMessage Lib "user32" () As Long


Since the original post was a jiggered form of Shell And Wait from the
KPD All API Guide, I figured that the OP would realize that
WaitMessage is an API
However I can't see how the termination of the launched process would
generate a windows message to cause waitmessage to return.


It seems it does
- when an App unloads it creates a bundle of activity within Windows
- also Windows knows very well which thread launched the App
- I just found that it is reliable


Hmm.. seems a bit wolly. You may be right. As a process tears itself down
it may remember what thread launched it. It may look for a window message
pump queue thingy on that thread (does every thread in windows have on
these? I don't think so). It may decide to put a message in that queue to
the effect that 'a process you created is now finished'.

It would be nice know for sure that that is what is happening. At the
moment I think it's more likely that is works simply because some messages
will be passing through anyway.

>It makes the app responsive to user events which may be a good thing.

Sure is

>OTH the rest of the code in the app needs to take care not to interfere
with
>this unfinished business or use information from this activity until
it's >finished.

Better that, than have a totally frozen App that cannot even re-paint
itself
Agreed but there is more work that needs to be done and I still don't

thinka DoEvents loop is the approach to take.


Why not ?
a) it is not hammering the processor
b) it is not 'blocking' the App


How many of these loops would you want in your app? What if the process you
launched never dies, does this loop stay inplace.

Anyway an App's Window Message queue is just a loop using a variation
of WaitMessage

// Start the message loop.

while (GetMessage(&msg, (HWND) NULL, 0, 0))

{
TranslateMessage(&msg);
DispatchMessage(&msg);
}

Yeah but one of these is already there do we want to create others also?

If the created process is hung then this look never exits so anadditional
>counter might be needed to terminate the loop after certain period has
>elapsed.

You are right about that, but that was not the question
Yes the OP wasn't interested in any of this. It's a little ambiguous but
appears the OP seems to be wondering whether launching the process in thismanner may be the reason it is freezing (the called process). A secondaryaffect being that the calling process freezes.


<quote>
I believe the use of the automation in this manner may be causing the
application to freeze on some machines. It causes it and its parent
application to freeze as well.
</quote>

The code is deliberately freezing the Calling App until the Called App
returns
- it has nothing to do with the Called App, once that is running the
calling App has no influence
The answer is I doubt this manner of launching the process is causing it tofreeze but it's difficult to tell.


It is definitely freezing the Caller
- which is pretty darn silly for a 3+ minute process


Perhaps I've read the question wrong.
If you want to do that then activate a normal VB Timer with a interval
of say 1 sec to act as a Message pump That way the App will get at least 1 msg per sec, and the code in the
loop can decide when to cop out. You need to have a serious look at what WaitMessage does, it is a
fascinating beast
- and extremely efficient at keeping down unnecessary processing It can be used for all sorts of tasks, my favourite is for totally
hijacking the Windows loop
I think in this case a better design would be to launch the app but not

loopat all.


There are two types of Looping
a) inefficient looping
-using pure DoEvents that raises CPU usage to 100%
b) efficient looping that responds immediately to Windows

c) Don't bother
Use a timer to check whether the process handle has been signalled.


That is a possibility
- in this case I would use an AX Exe and run the process off its
internal thread
- or use a normal Exe and set up a communications system

Sometimes Waiting is sensible
- especially if there is not much you can do until the thing comes
back with a result


Agreed
Modify the parent app to ensure invalid actions are not taken whilst this
secondary process is operating.


Dead easy, a Modal Form with an Abort button


Ah now it makes sense. Your WaitMessage/DoEvents loop coupled with this
should work nicely.
TBH I've never come across a problem that might be solved using a DoEventsloop that couldn't be better solved without one. Especially if the
developer is happy dipping into the windows API.


I am trying to explain to you that

While Something
WaitMessage
DoEvents
Wend

Is NOT a DoEvents Loop
- it is the equivalent of popping up a Modal Form ( and you can be
sure that is how Modal Forms work )

As I said before, you would be wise to look into the implications of
WaitMessage


Doesn't look like I need to. What else is there to learn that you haven't
already explained :)
- a lot of VB programmers don't understand it


I think it's more like never heard of it. I hadn't and I've been doing VB
for more years than I care to admit. (although not a great deal of UI
work).

May 21 '06 #8
On Sun, 21 May 2006 14:29:50 +0100, "Anthony Jones"
<An*@yadayadayada.com> wrote:

I see that you are a Dori Previn Fan
- I went to school with her daughter

Yada Yada is a great track - it even gets me, and I am a-musical

On the subject, Windows is a deliberate illusion

Mostly, I like to explain things to those that should know

- you will probably want to know, it took me time to understand

Right now I am inebreiated - tomorrow I shall spell ( as in spell )
- and like most of us, show the devious paths

Just look into WaitMessage or do a Google search
- it is rather interesting
May 21 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: jabailo | last post by:
I came across this article while researching a VB6 430 error: INFO: Considerations for Server-Side Automation of Office http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757 ...
15
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no...
25
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's...
17
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
0
by: Sharath | last post by:
Quality Globe is Glad to Offer you the Fast Track course on Automation, QTP Basics and Advanced, and Quality Center Starting Date: June 4th, 2007 Timings: 10 AM to 3:30 PM Duration: 50 Hours ...
0
by: Sharath | last post by:
"Inspired" by the huge success of our first two automation fast track batches We are forced to start third fast track automation batch ...
0
by: Sharath | last post by:
We are glad to inform you that "Inspired" by the huge success of our first three automation fast track batches We are forced to start fourth fast track automation batch ...
0
by: Sharath | last post by:
We are glad to inform you that "Inspired" by the huge success of our first four automation fast track batches We are forced to start fifth fast track automation batch ...
10
by: cj2 | last post by:
I open a word template in VB and add values to the bookmarks then save the document as as pdf. When I then go to close the document it pops up a save as dialog box. It's already saved the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.