ActiveX EXE: How Do I access an internal class from a standard module? 
Author Message
 ActiveX EXE: How Do I access an internal class from a standard module?

Using VB 5 Enterprise SP3 on WinXP Pro.

I'm trying to make an ActiveX EXE which is a usable replacement for the shell RunAs command. I originally put together a DLL which worked flawlessly; to make it usable for console use also, I decided to transform it into an ActiveX EXE.

I have the command line parsed OK, using a Sub Main() in an ordinary module, but now discovered that I have no clue as to how to call a function in a class module from the module I am using.

Is it possible to do this, or do I need to just make a hidden form and call the ActiveX component from that?



Sat, 18 Sep 2004 10:09:06 GMT  
 ActiveX EXE: How Do I access an internal class from a standard module?

Quote:
> Using VB 5 Enterprise SP3 on WinXP Pro.
> I'm trying to make an ActiveX EXE which is a usable replacement for
> the shell RunAs command. I originally put together a DLL which worked
> flawlessly; to make it usable for console use also, I decided to
> transform it into an ActiveX EXE.
> I have the command line parsed OK, using a Sub Main() in an ordinary
> module, but now discovered that I have no clue as to how to call a
> function in a class module from the module I am using.
> Is it possible to do this, or do I need to just make a hidden form
> and call the ActiveX component from that?

What does the Sub Main look like?  Are you depending on receiving an
event from your class object when the external command terminates?
If so, you'll need to create a second class, since only class-level
or form-level object reference variables can be defined WithEvents.

--
Joe Foster <mailto:jlfoster%40znet.com>     On the cans? <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 18 Sep 2004 10:28:12 GMT  
 ActiveX EXE: How Do I access an internal class from a standard module?
I'm not doing any events - just a sub to a method which is simply an API wrapper.  What's even more problematic I suspect is the fact that I think I may have made the structure excessively complicated.  Here's the general flow:

Sub Main()
    ' parse commandline given as args
    'call the class with the parsed args as arguments
End Sub

'================
' Defines, including an API call which is the core of it

Public function RunAsX(args)
    ' Do logic
    ' make API call
End Function

The reason for what may appear convoluted thinking is that I was trying to make this do double duty as a command line EXE and an ActiveX component - and I already had the component working.

**MORE** important than making it work this way right now is my thinking process.  I don't have to combine the component and the command line EXE, I can duplicate the loginc in what is a 3Kb EXE and a comparably sized ActiveX DLL.

So - if I can divert the question -

(1) What the heck is an "ActiveX EXE" really? I assumed it was simply something which could be either run directly as an executable *or* called via its COM interface; is there anything more fundamental to this?

(2) Over the long run, how does one best share internal logic between the exposed classes and an executable in the same app - is it usually best to stick everything into normal modules which are then accessed from Main() and the class modules with basic wrappers around input from their interfaces?

or
(3) Are these questions really muddled?


Quote:

> > Using VB 5 Enterprise SP3 on WinXP Pro.

> > I'm trying to make an ActiveX EXE which is a usable replacement for
> > the shell RunAs command. I originally put together a DLL which worked
> > flawlessly; to make it usable for console use also, I decided to
> > transform it into an ActiveX EXE.

> > I have the command line parsed OK, using a Sub Main() in an ordinary
> > module, but now discovered that I have no clue as to how to call a
> > function in a class module from the module I am using.

> > Is it possible to do this, or do I need to just make a hidden form
> > and call the ActiveX component from that?

> What does the Sub Main look like?  Are you depending on receiving an
> event from your class object when the external command terminates?
> If so, you'll need to create a second class, since only class-level
> or form-level object reference variables can be defined WithEvents.

> --
> Joe Foster <mailto:jlfoster%40znet.com>     On the cans? <http://www.xenu.net/>
> WARNING: I cannot be held responsible for the above        They're   coming  to
> because  my cats have  apparently  learned to type.        take me away, ha ha!



Sat, 18 Sep 2004 12:33:10 GMT  
 ActiveX EXE: How Do I access an internal class from a standard module?
well, {*filter*}-all!           (VB5 on XP Pro)

Joe, I can see that it is really easy to write a basic wrapper... and then gets dirty very, very quickly. I decided to do a very simple exe to make sure I understood what happened why.  Following are questions after doing a trivial ActiveX Exe.

Sorry if these are very basic questions, but as I always plead, I've only een using VB a few days.

(1) Took a simple project - writing a raw "uptime" tool which would access the GetTickCount function in kernel32 and return raw values when either double-clicked or called from script.

(2) Here's what I wound up with for code:

(2a) A module which has

Public Declare Function GetTickCount Lib "kernel32" () As Long
Sub Main()
  MsgBox GetTickCount
End Sub

(2b) A class which contains:

Public Function Uptime() As Long
  Uptime = GetTickCount
End Function

======================
QUESTIONS
I think I understand the answer to my original question: one method to access stuff from both modules and classes easily is to put it into a module, then have a wrapper in your classes to expose it.

Unfortunately, I think I may be totally misunderstanding ActiveX Exe's. I *thought* they could be used to allow both COM access to internal functions and command line access.

What I actually see is that yes, I do get the information back from my program via a script call:

set o = CreateObject("CurrentUpTime.Class1")
wscript.echo o.Uptime

QUESTION 1: Purpose of ActiveX EXEs
However, instantiating the reference apparently triggers Sub Main()!  This makes sense when I think about it, I guess - I assume that the ActiveX Exe was designed to allow automation of an application, not "mining" the app for its functions.  Is this correct?

QUESTION 2:Multi-purposing as EXE and COM Class
I can see how to work around it, also  if I wanted "double duty" apps - I played with Command$ and found that it was "-Embedding" when I called it from script; so changing Sub Main() to

Sub Main()
If Command$ <> "-Embedding" Then MsgBox GetTickCount
End Sub

Allows me to use it as both an EXE and a library.  Is this a bad way to do things, though? For a larger project, I am wondering if I will run into weird problems from trying to make this work.

QUESTION 3: Register/Unregister
The app seemed to self-register, which is OK - but how do I unregister it? It kicks a fit on regsvr32 both with and without the /u switch.



Mon, 20 Sep 2004 13:37:59 GMT  
 ActiveX EXE: How Do I access an internal class from a standard module?

Quote:
> QUESTION 1: Purpose of ActiveX EXEs
> However, instantiating the reference apparently triggers Sub Main()!  This
> makes sense when I think about it, I guess - I assume that the ActiveX Exe
> was designed to allow automation of an application, not "mining" the app
> for its functions.  Is this correct?

I'm not sure, exactly.  I've used them only to share small amounts of
data and maybe events between multiple processes which might reside
on multiple workstations over a network.  If I had an app I wanted to
be able to automate, I'd split it up into a plain EXE and one or more
ActiveX DLLs.  Getting at an ActiveX DLL's methods and properties is
so very much faster than using even a locally registered ActiveX EXE!

Quote:
> QUESTION 2:Multi-purposing as EXE and COM Class
> I can see how to work around it, also  if I wanted "double duty" apps
> - I played with Command$ and found that it was "-Embedding" when I
> called it from script; so changing Sub Main() to
> Sub Main()
> If Command$ <> "-Embedding" Then MsgBox GetTickCount
> End Sub
> Allows me to use it as both an EXE and a library.  Is this a bad way
> to do things, though? For a larger project, I am wondering if I will
> run into weird problems from trying to make this work.

I have no clue, sorry!.  There might be a StartMode property which can
tell you this without relying on something Microshaft might change at
the drop of a hat...  any hat...

Quote:
> QUESTION 3: Register/Unregister
> The app seemed to self-register, which is OK - but how do I unregister
> it? It kicks a fit on regsvr32 both with and without the /u switch.

Just launch these to register or deregister an ActiveX EXE:

youractivex.exe /RegServer

youractivex.exe /UnRegServer

I have absolutely no idea whatsoever if they're case-sensitive or not.

--
Joe Foster <mailto:jlfoster%40znet.com>  Sign the Check! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Thu, 23 Sep 2004 03:09:26 GMT  
 ActiveX EXE: How Do I access an internal class from a standard module?
Thanks, Joe.

I think I'll just steer clear of ActiveX EXE's for now; using them seems more of an annoyance than a solution at present.

I've checked and in at least this case and that of wscript.exe, the /regserver switch is not case-sensitive.


Quote:

> > QUESTION 1: Purpose of ActiveX EXEs
> > However, instantiating the reference apparently triggers Sub Main()!  This
> > makes sense when I think about it, I guess - I assume that the ActiveX Exe
> > was designed to allow automation of an application, not "mining" the app
> > for its functions.  Is this correct?

> I'm not sure, exactly.  I've used them only to share small amounts of
> data and maybe events between multiple processes which might reside
> on multiple workstations over a network.  If I had an app I wanted to
> be able to automate, I'd split it up into a plain EXE and one or more
> ActiveX DLLs.  Getting at an ActiveX DLL's methods and properties is
> so very much faster than using even a locally registered ActiveX EXE!

> > QUESTION 2:Multi-purposing as EXE and COM Class
> > I can see how to work around it, also  if I wanted "double duty" apps
> > - I played with Command$ and found that it was "-Embedding" when I
> > called it from script; so changing Sub Main() to

> > Sub Main()
> > If Command$ <> "-Embedding" Then MsgBox GetTickCount
> > End Sub

> > Allows me to use it as both an EXE and a library.  Is this a bad way
> > to do things, though? For a larger project, I am wondering if I will
> > run into weird problems from trying to make this work.

> I have no clue, sorry!.  There might be a StartMode property which can
> tell you this without relying on something Microshaft might change at
> the drop of a hat...  any hat...

> > QUESTION 3: Register/Unregister
> > The app seemed to self-register, which is OK - but how do I unregister
> > it? It kicks a fit on regsvr32 both with and without the /u switch.

> Just launch these to register or deregister an ActiveX EXE:

> youractivex.exe /RegServer

> youractivex.exe /UnRegServer

> I have absolutely no idea whatsoever if they're case-sensitive or not.

> --
> Joe Foster <mailto:jlfoster%40znet.com>  Sign the Check! <http://www.xenu.net/>
> WARNING: I cannot be held responsible for the above        They're   coming  to
> because  my cats have  apparently  learned to type.        take me away, ha ha!



Fri, 24 Sep 2004 11:47:29 GMT  
 ActiveX EXE: How Do I access an internal class from a standard module?

Quote:
> I think I'll just steer clear of ActiveX EXE's for now; using
> them seems more of an annoyance than a solution at present.

Yeah, they usually are more trouble than they're worth!  Oh yeah,
you also need to use them in order to do multi-threading in pure
VB.  There are ways to use the raw CreateThread API, but only if
you're Matthew Curland, who has access to Windows OS source code.

Quote:
> I've checked and in at least this case and that of wscript.exe,
> the /regserver switch is not case-sensitive.

However, wscript.exe was probably written in MSVC+, not VB.  =)

--
Joe Foster <mailto:jlfoster%40znet.com>  Sign the Check! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above        They're   coming  to
because  my cats have  apparently  learned to type.        take me away, ha ha!



Fri, 24 Sep 2004 23:44:33 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Accessing procedures of a class module from another class module

2. Problem with class modules in activex exe with ado recordsets

3. Problem with ActiveX exe / Thread per Object / Multiuse Class Modules

4. Internal format of VB class Modules

5. making standard VB EXE to ActiveX EXE?

6. Standard EXE and ActiveX EXE

7. ActiveX EXE or Standard EXE

8. Callback between standard.exe and activeX.exe

9. How to call one VB class module method from another class in an ActiveX dll

10. Class modules 97 - Refering to array within a custom class module

11. Many Instances of a Class in A Standard EXE/DLL

12. Many Instances of a Class in A Standard EXE/DLL

 

 
Powered by phpBB® Forum Software