Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


VB activex dll..

Posted on 2005-04-27
Medium Priority
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
  • 2
LVL 10

Accepted Solution

fds_fatboy earned 500 total points
ID: 13874252
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

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

Author Comment

ID: 13874378
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..


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month13 days, 9 hours left to enroll

581 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