?
Solved

Creating an ActiveX DLL

Posted on 2006-05-07
6
Medium Priority
?
331 Views
Last Modified: 2010-05-01
I'm writing an ASP script that is pulling data from a vendor.  They provided a DLL that I need to use in order to communicate with their server.  From what I understand, I need to encapsulate the functions in this DLL into an ActiveX DLL - and I'm not sure where to start.

I've got a list of Declare statements provided by the vendor:

Declare Function myFunction1 Lib "vendor.dll" (Byval myData as String)
Declare Function myFunction2 Lib "vendor.dll" (Byval myData as String)
...

I assume I need to use Visual Studio to compile the DLL (see?  I'm really new to this...).  Can someone provide a step-by-step?  I know that I've got VS.Net - can I compile a VB6 DLL using that?  I assume I need to create a new project, then put the declare statements inside a class.  What do I need to do to compile?  How do I indicate that it's an ActiveX DLL?  Sorry for my ignorance...
0
Comment
Question by:BigMonkeyHead
  • 3
  • 2
6 Comments
 
LVL 6

Accepted Solution

by:
junglerover77 earned 2000 total points
ID: 16627415
Yes, you are right, you must encapsulate the functions in the DLL into an ActiveX DLL.

First, you must get a VB6, not VB.NET.
Then, Do the following:
1. Create a new project, Select "ActiveX DLL";
2. In Class1, paste the list of Declare statements provided by the vendor;

3. Create a public function for each function from the DLL, like the following:

public Function COMmyFunction1 (Byval myData as String)
    COMmyFunction1=myFunction1(myData)
end Function

4. Save the project, and compile it.

5. In your ASP script, just do the following:

set MyObj=CreateObject("Project1.Class1")
MyValue =  MyObj.COMmyFunction1(myData)
0
 
LVL 20

Expert Comment

by:clarkscott
ID: 16629462
VB.NET can load a VB6 DLL but it converts it to VB.NET syntax.  This makes the DLL somewhat difficult to debug.

Using VB6 - create your DLL and save as a project.

Using VB6 - create a new application project and insert the 'calling code' (previous by Junglerover).

Click FILE - LOAD - and select your DLL code.  You can now put BREAKPOINTS in the application (test) program and walk right through the DLL code.    Make any code adjustments necessary and save.   Open JUST the dll code and re-compile.

You may also want to add a REFERENCE to the dll in the application program (calling program).  Project- references - browse and locate the compiled DLL.

Note:  VB6 is much more 'forgiving' when dealing with changes in DLLs.  VB.NET keeps it's own 'version' of dlls.  If you make a change to the DLL, you may have to 'drop' the DLL from VB.NET and re-select it.  

Scott C.
0
 
LVL 1

Author Comment

by:BigMonkeyHead
ID: 16629758
I can't get the code to compile - I put the vendor-supplied DLL (fbb.dll) in the same directory as my code.  Using the first three subroutines as an example, the code is as shown below.  However, it wouldn't compile because of the Declare statements (Declare statements not allowed as Public members of object modules).  So I declared them as Private.  This passes the debugger, but fails to compile when it gets to the first function call from the DLL - vb_setADataPath (6th line below).  The error is:  Expected Function or variable.  That tells me that it's not seeing the DLL.  ??

Private Declare Sub vb_setAdataPath Lib "fbb.dll" (ByVal inPath As String)
Private Declare Sub vb_setCommDllPath Lib "fbb.dll" (ByVal inPath As String)
Private Declare Sub vb_setCommSupportPath Lib "fbb.dll" (ByVal inPath As String)

Public Sub COMvb_setAdataPath(ByVal inPath As String)
    COMvb_setAdataPath = vb_setAdataPath(inPath)
End Sub
Public Sub COMvb_setCommDllPath(ByVal inPath As String)
    COMvb_setCommDllPath = vb_setCommDllPath(inPath)
End Sub
Public Sub COMvb_setCommSupportPath(ByVal inPath As String)
    COMvb_setCommSupportPath = vb_setCommSupportPath(inPath)
End Sub
0
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!

 
LVL 6

Expert Comment

by:junglerover77
ID: 16629908
Private Declare Sub vb_setAdataPath Lib "fbb.dll" (ByVal inPath As String)
Private Declare Sub vb_setCommDllPath Lib "fbb.dll" (ByVal inPath As String)
Private Declare Sub vb_setCommSupportPath Lib "fbb.dll" (ByVal inPath As String)

Public Sub COMvb_setAdataPath(ByVal inPath As String)
    call vb_setAdataPath(inPath)
End Sub
Public Sub COMvb_setCommDllPath(ByVal inPath As String)
    call vb_setCommDllPath(inPath)
End Sub
Public Sub COMvb_setCommSupportPath(ByVal inPath As String)
    call vb_setCommSupportPath(inPath)
End Sub
0
 
LVL 1

Author Comment

by:BigMonkeyHead
ID: 16630749
Ok, I got that working.  Now, to move this to the production server, I put my new dll and fbb.dll in the same directory.  And I put a simple ASP script in there too.  When I try to instantiate the object in my ASP script, it fails....

<%
set myObj = CreateObject("Project1.Class1")

%>

Error:  ActiveX component can't create object: 'Project1.Class1'

Do I need to register these?  I was under the impression I didn't need to....or should I be putting these in the System\ folder?
0
 
LVL 6

Expert Comment

by:junglerover77
ID: 16630784
Oh my god, of cause you must register an ActiveX DLL before you can use it.

If your Project1.dll is in "C:\Test", Run the following statement from "Start Menu->Run" to register it:
regsvr32 "c:\test\project1.dll"

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses
Course of the Month14 days, 6 hours left to enroll

807 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