views:

395

answers:

5

I'm working as a developer, curently mantaining a VB6 app that desperately needs to work fine under Vista. However, it must work fine under Vista Starter Edition, since is the version new computers here (Argentina) come with.

Now, onto the technical stuff: my app uses ImageMagick's convert to process images (resizing, black and white segmentation, rotation, etc), so the three-apps limit is a real pain in the... well, somewhere. Worst: the failure in running convert is not (currently?) detected, so when this happens the program hangs up.

Can anyone tell me how to:

a_ Detect the number of open apps, so I can ask the user to close something before retrying? An API call, maybe? or

b_ Detect that convert (currently running with the "Shell" function) wasn't launched properly?

Please, comments like "you should migrate your app to x" should be sent to my boss (not me), are not welcome and will make me travel to your place and bite your toe. It will take me some time to get the visa, though, but I assure you that one day a stranger will knock on your door, ask your StackOverflow username and then he WILL bite your toe.

Thanks for your consideration

+1  A: 

Sigh

Disregard, I need to read beyond the subject line in the future!

Call GetSystemMetrics() passing SM_STARTER (a Const = 88).

Option Explicit

Private Const SM_STARTER = 88&

Private Declare Function GetSystemMetrics Lib "user32" ( _
    ByVal nIndex As Long) As Long

Private Sub Form_Load()
    MsgBox CStr(GetSystemMetrics(SM_STARTER)) 'Zero (0) means False.
End Sub

This is defined for XP, and ought to be the same for Vista. Easy enough to try, right?

Bob
A: 

Not what you wanted to hear, but I'll bet that "starter" is sufficiently easy to break.

I'll bet something like this works: load system service, take SE_DEBUG, walk all processes, patching GetSystemMetrics(0x88) to return 0 in RAM.

Joshua
+4  A: 

Why aren't you using the ImageMagickObject COM+ interface? I've never used it, but the documentation claims it can do everything the command-line utilities can, without running an extra app.

Daniel Martin
Honestly, I'm not using it because it scares me (COM+ interfaces give me nightmares), but since I can't think of a better solution, I'll give it a try.
Martin
A: 

Try starting with createprocess instead of via the shell? Or have a service manage it, while the app communicates with the service.

Marco van de Voort
A: 

Have you tried checking the return value of the Shell function? Documentation says it should return zero if the shell fails.


Martin says in the comments: I tried, but every time I check the return value, is some weird number greater than zero.

MarkJ again: The return values are supposed to be process IDs. It might be possible to make an API call to check whether they are valid process IDs. You could try something like this: this always shows a "succeeded" MsgBox for me, because I don't have Vista Starter Edition :)

Private Declare Function OpenProcess Lib "kernel32" ( _
    ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
    ByVal dwProcessId As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" ( _
    ByVal hObject As Long) As Long

Sub StartProcess()
   Dim ProcessId&
   Dim hProcess&
   Const PROCESS_QUERY_INFORMATION = &H400&

   ProcessId = Shell("notepad.exe", vbNormalFocus)
   hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, ProcessId)
   If hProcess = 0& Then
     MsgBox "Failed"
   Else
     MsgBox "Succeeded"
     CloseHandle hProcess
   End If

End Sub
MarkJ
After reading your comment I tried, but every time I check the return value, is some weird number greater than zero. Personally, I blame the IDE, for not foreseeing that ten years after being developed the O.S. would change in completely unexpected ways. But that's just me.
Martin