Results 1 to 9 of 9

Thread: active x exe subMain execution

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046

    active x exe subMain execution

    I have a problem with an active x exe. When i execute:

    set myObj = myExe.Application

    my application starts up and subMain starts running. All OK so far.

    The problem is that the application allows me to start using the methods before subMain execution is finished ... which is causing problems in my code (subMain does some prep work that is a pre requisite for the methods).

    I imagine that this must be a common problem. What is the best way to deal with it? My first thought was an appReady flag that I could use in a Do Until Loop. Surely there is a better way?

    Thanks in advance for any help!
    Last edited by Muddy; Sep 9th, 2004 at 08:16 AM.

  2. #2

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    bump

    thought this would be an easy one ...

  3. #3
    Addicted Member JRSofty's Avatar
    Join Date
    Jan 2004
    Location
    Somewhere in Germany
    Posts
    149
    Can you post your code? I'm not sure exactly what you are asking about.

  4. #4

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by JRSofty
    Can you post your code? I'm not sure exactly what you are asking about.
    Thanks for the response!

    too much code to post.

    imagine an active x exe with the following in the mainmodule:

    VB Code:
    1. for i = 1 to 100000
    2.    doevents
    3. next i
    4. open "app.path"  & "\test.txt" for output as #1
    5. close #1
    and the following method
    VB Code:
    1. Public Sub KillFile()
    2.     Kill "app.path"  & "\test.txt"
    3. end Sub
    now in my working app that references the active x exe i have
    VB Code:
    1. dim myObj as new myExe.Application
    2. call myObj.KillFile
    3. Kill "app.path"  & "\test.txt"

    The code would crash on call myObj.KillFile (I think) because mainmodule would not have gotten to the part where it creates the file yet.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    one more bump before I give up on an answer ...

  6. #6
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    An ActiveX Exe is considered an "out of process" server. The client application does not wait for execution to be completed as with an ActiveX dll. If two applications were to instantiate the ActiveX Exe at the same time, the Sub Main procedure only executes once.

    I guess to solve your problem, in sub Main set a global flag to indicate that it has completed porcessing. Every class you create should expose this flag. There is no other way. Events won't work because a module cannot raise events.

    Depending on what sub main does I would suggest you rethink your design. Can you move the Sub Main code into Class Initialize.

  7. #7
    Addicted Member JRSofty's Avatar
    Join Date
    Jan 2004
    Location
    Somewhere in Germany
    Posts
    149
    Also are you sure that the Sub Main is actually firing when the object is created?

    Normally when I'm working with an ActiveX EXE I use the CreateObject function to instance it.

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by JRSofty
    Also are you sure that the Sub Main is actually firing when the object is created?
    Positive

    Originally posted by JRSofty

    Normally when I'm working with an ActiveX EXE I use the CreateObject function to instance it.
    I prefer early binding... mainly because I like the intellisense .... I do many times change to late binding just before release to eliminate versioning problems on the end users machine.

  9. #9

    Thread Starter
    PowerPoster
    Join Date
    Feb 2001
    Location
    Crossroads
    Posts
    3,046
    Originally posted by brucevde
    An ActiveX Exe is considered an "out of process" server. The client application does not wait for execution to be completed as with an ActiveX dll. If two applications were to instantiate the ActiveX Exe at the same time, the Sub Main procedure only executes once.

    I guess to solve your problem, in sub Main set a global flag to indicate that it has completed porcessing. Every class you create should expose this flag. There is no other way. Events won't work because a module cannot raise events.

    Depending on what sub main does I would suggest you rethink your design. Can you move the Sub Main code into Class Initialize.
    Thanks Bruce. I hear what you are saying, but due to other considerations too convoluted to get into in this thread, I am stuck with the current structure. I'll probably go witht the flag as you suggested. I was really hoping that there was some obscure project setting that I was unaware of that would fix this ... wishfull thinking ... :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width