Link to home
Start Free TrialLog in
Avatar of BigMonkeyHead
BigMonkeyHeadFlag for United States of America

asked on

Creating an ActiveX DLL

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...
ASKER CERTIFIED SOLUTION
Avatar of junglerover77
junglerover77

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of clarkscott
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.
Avatar of BigMonkeyHead

ASKER

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
Avatar of junglerover77
junglerover77

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
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?
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"