VB activex dll..

Posted on 2005-04-27
Last Modified: 2012-05-05
Hi all..  I need to make a dll which has the following code in it..

    Dim wsh As String
    Shell Environ("COMSPEC") & " /c " & wsh

the wsh variable would hold something like "c:\derek.bat c:\text1.txt c:\text3.txt" which needs to be passed from another application as a parameter.  

The code basically runs a batch file on my pc using a the dos copy command.  My question is, what do I need to put in my code to receive a parameter from an external source??

Please assist..

Kind regards,

Question by:Delboy
    LVL 10

    Accepted Solution

    Open a new VB ActiveX project.
    Give the project a name (eg MyDLL)
    You should have a class and give it a name (in this example I'll call it MyClass).
    Make sure the class instancing is set to MultiUse.

    Add the following code to the class to expose your method

     Option Explicit
     Public Sub MyMethod (ByVal wsh As String)
          Shell Environ("COMSPEC") & " /c " & wsh
     End Sub

    Compile the project. If you will be distributing the DLL you may wish to look into setting the component to be Binary Compatible, and you will have to register it using resgsvr32 on the client machines - this will be done automatically if you use Package and Deployment Wizard with a client application)

    To your DLL function:
    Option 1. Early bound - More efficient  (not available in VBS)
    In a new VB project (your client application), add a reference to (Menu:Project/References) to your DLL
    Here is a code fragment creating an instance of your class and running your method:

         Dim MyObj As MyDLL.MyClass
         'Instantiate object
         Set MyObj = New MyDLL.MyClass
         'Run object Method
         'Remove the class reference
         Set MyObj = Nothing

    Option 2 Latebound (Less efficient, available in vbs)

         Dim MyObj
         'Instantiate object
         Set MyObj = CreateObject("MyDLL.MyClass")
         'Run object Method
         'Remove the class reference
         Set MyObj = Nothing
    LVL 10

    Expert Comment

    But for "Fred" use "c:\derek.bat c:\text1.txt c:\text3.txt"

    Author Comment

    PLEASE EXCUSE MY ELATION.  YOU A RE A SUPERSTAR...!!!!  The application I am passing from already does the option 1 code..  and I just tested it, and ..  phew..

    Many thanks..


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

    760 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