Solved

Com Interop

Posted on 2006-11-03
17
324 Views
Last Modified: 2008-02-01
I have a .NET windows application that I created a COM class for.  I registered the assembly using regasm and I am able to successfully call the public methods from vb6 and vbs.  Here is my problem :)

I have the following code in a vbscript

Dim mySalesEngine
Set mySalesEngine = CreateObject("SalesEngine.ComInterface")
mySalesEngine.RunSalesEngine

Everything works fine.  the .NET windows app opens and the RunSalesEngine method is invoked.  However, as soon as it is done running it closes.  I know why it is doing this because the variable I created in my vbscript is destroyed when the script is done running.  

My question is how can I make this not happen?  I want the .NET windows app to remain open after the code in the vbscript is complete.
0
Comment
Question by:BofADev
  • 8
  • 2
  • 2
  • +3
17 Comments
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17872153
Dim mySalesEngine
If you have declared it in procedure ?
 try to declare it at Module level, i don't think this might be a problem,
but no harm in trying
0
 

Author Comment

by:BofADev
ID: 17874164
The script only runs to launch the sales engine.  So declaring a module level variable wouldn't help since the script terminates once the sales engine is launched.
0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17875545
ummmm There is a way but it is weired one, instead of dll try some exe and launch that exe by giving command line parameters.
Beacuae as dll is designed to run in such a way that instance is creted by calling application and destroyed when calling application exit. SO in the above scenario i find it difficult what you want to achive.
0
 

Author Comment

by:BofADev
ID: 17892291
I've done this in the past without a "helper" exe.  However, it was in vb6 not .NET.  I guess I'm looking for a different answer :)
0
 

Author Comment

by:BofADev
ID: 17892416
I vagely remember in the past when I did this in vb6 I had to set the class instancing to multi use and the project type to active x exe.  

Is there anything like this in vb.net?
0
 

Author Comment

by:BofADev
ID: 17892441
I think I also set the thread pool to 1 thread.  Does any of this make sense as to why the program is behaving like it is?
0
 
LVL 19

Expert Comment

by:VoteyDisciple
ID: 17892603
Where is that code run in your application?  That is, is it part of some event for while the program is already running?  Is it in Sub Main?  Or have I misinterpreted the relationship between the .NET program itself and the COM object entirely?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:BofADev
ID: 17892679
Let me clarify my question because I think what I'm asking might be lost in translation :)

I have a .NET windows application.  I want to invoke a method in the .NET windows application from a vbscript.  The code in the vbscript looks like this.

Dim mySalesEngine
Set mySalesEngine = CreateObject("SalesEngine.ComInterface")
mySalesEngine.RunSalesEngine

Here is what I want to happen.  If the .NET windows application is running in the instance that is currently running the RunSalesEngine method should be invoked.  If the .NET windows application is not running it needs to start and then invoke the RunSalesEngine method.

Here is what is happening....a new instance is always created and when the script is done running the script and the .net app terminate.
0
 
LVL 13

Expert Comment

by:AngryBinary
ID: 17894078
This can be achieved by throwing the program into a loop and suspending the tread periodically to prevent it from eating up resources. Forgive my shoddy VB memory if this isn't syntactically right, but here's the idea:

Imports System.Threading;

//...

While (true)
    Thread.Sleep(100)
    If (someExitCondition) Then
       Exit
    End if
    //if you need to do something else, put your conditions here, ie:
    //If (someProcessIsRunning) Then
    //    DoSomething()
    //End If
End While

If you need to program to perform additional actions given a particular condition, that should be included in the 'while' loop. You will need to introduce some kind of criteria to define an exit condition as well, otherwise you will have to break the process to close the program.
0
 

Author Comment

by:BofADev
ID: 17894160
I think the problem with doing it this way is the script that called my .net application would never end since the method it called is stuck in an infinate loop.  This would mean that everytime a user ran the script an instance of wscript would be created to run the script and eventually the pc would run out of resources.
0
 

Author Comment

by:BofADev
ID: 17894170
I'm trying to replicate how it works now with a vb6 app and a vbscript.  It works exactly how I want it to as described in the post from 3:31PM.
0
 
LVL 13

Expert Comment

by:AngryBinary
ID: 17898949
The program will not be stuck in an infinite loop if you provide the exit condition (which should replace the pseudovariable 'someExitCondition'). This could be a key press, a button click, a preset time limit, or a check to see if another process is running. The amount of resources it consumes will not increase over time, unless you are constantly creating objects that never fall out of scope.

Could you describe a little more completely what you intend the program to do while it is running? I think I'm gathering that you want it to execute a COM method, but I don't quite understand what you want to trigger the execution.
0
 
LVL 1

Expert Comment

by:ruizpauker
ID: 18109332
If this thread is still active...

What you want is something like automating WORD, when you create an instance, it only runs if it isn't, and then when you left your references (finish your script) it keeps running unless you call its Quit method ??????

there's just a litle possibility I can help u.
0
 

Author Comment

by:BofADev
ID: 18115607
I actually stumbled upon the answer with a friend of mine.  When you talk to an active x server from .net it moves the active x server inside of the same memory space of the .net application.  This is why I was seeing the behavior I was seeing.  Here is an article that describes the solution.

http://www.codeproject.com/dotnet/ActiveXEXEWrappers.asp
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18184053
PAQed with points refunded (500)

Computer101
EE Admin
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now