|
-
Feb 19th, 2002, 06:37 AM
#1
Thread Starter
New Member
Create an objectvariable from API handle
I am making a host application that is starting up an other application as an object (like this):
Private WithEvents ProcApp As PBObjLib.Application
Set ProcApp = CreateObject("PIProcessBook.Application")
Now I have a reference to my application object: ProcApp.
Before I use the createobject function, I want to be able to detect whether an instance of the application is already running, and if so, I want this instance to be referenced by the ProcApp objectvariable.
I have made a function that can find and return a handle to the application. I do this by using FindWindow (I have the windowclass - Windowname is laft as nullstring)
So, now I know that my application is running, I even have a handle. The BIG question is how do I reference the handle to a VB object variable (ProcApp). What I need is a fantasy function calle GetObjectFromHandle(Handle as long) as object...
-
Feb 19th, 2002, 06:57 AM
#2
Frenzied Member
Could you use GetObject() insteatd of CreateObject()? According to the VB help, this will return an existing instance of an object if it is in the running object table...
-
Feb 19th, 2002, 07:08 AM
#3
Thread Starter
New Member
Originally posted by MerrionComputin
Could you use GetObject() insteatd of CreateObject()? According to the VB help, this will return an existing instance of an object if it is in the running object table...
Idon't think this is possible. I've tried.
GetObject only works with objects, that are created from files; qoute from MSDN:
***
Use the GetObject function to access an ActiveX object from a file and assign the object to anobject variable.
***
It doesn't take an API handle as argument...
Thanks though (any other ideas?)
-
Feb 19th, 2002, 10:25 AM
#4
Frenzied Member
This fairly maky looking code does that with Word:
Code:
fgWH = FindWindow("OPUSAPP", vbNullString)
If fgWH <> 0 Then ' word process is running
Set fgWordObj = GetObject(, "Word.Application")
Else
Set fgWordObj = CreateObject("Word.Application")
End If
fgWordObj.Visible = True
HTH,
Duncan
-
Feb 20th, 2002, 03:16 AM
#5
Thread Starter
New Member
Yes, you are right. GetObject does the job.
Now I found a new problem though. The Classname that I use for searching with findwindow changes (when I restart the computer I guess). Yesterday the classname was
Afx:400000:8:10011:0:466bf
today it is:
Afx:400000:8:10011:0:1031d
how can that be ?
-
Feb 20th, 2002, 04:27 AM
#6
Frenzied Member
The last bit (after the last colon) seems to be the bit that is changing. Probably this is created using a Global Atom for a standard string that the program has stored internally.
Try running the app., getting that last bit and seeing if it is a valid global atom entry and, if so, what string it is.
HTH,
Duncan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|