Solved

DLL

Posted on 2008-10-27
6
595 Views
Last Modified: 2012-05-05
I would like to know how can i made a proyect to be a dll field and call it from a main proyect
Any one can give me an example  in VB 6.0
0
Comment
Question by:cano63
  • 3
  • 2
6 Comments
 
LVL 16

Expert Comment

by:HooKooDooKu
Comment Utility
I'm not clear on what you want.  But I'm going to guess that you want to figure out how to create a DLL from VB6 and then use that DLL in another VB project.

To create a VB DLL, all you have to do is create a new project and select ActiveXDLL as the project type.  Your DLL can have Forms, Classes, and Modules just like an VB EXE project.  However, functions inside of Modules are invisible outside the DLL.  Classes and Forms with an instancing property of Private can only be accessed from within the DLL.  Classes and Forms with an instancing property of Multiuse can be created and used from outside the DLL.  Classes and Forms with an instancing of Public-Noncreatable means the public functions of object can be called, but a project outside the DLL can not create an instance of the object.  Classes and Forms with an instancing of Pulic MultiUse means an instance of the Class exists and functions of that class can be called without creating an instance of the object.  In this repect, the VB ERR object is an example of a class declared as Global-Multiuse because your VB project already has an instance of the ERR object without you doing anything.

Now I might have some of these exact property names a little wrong as I'm going from memory and currently do not have access to my computer with VB6 installed on it.

Once you compile your DLL, it will automatically be registered on your machine.  To use it on another machine, you will have to register it with RegSvr32.

To use the DLL in another project, you just have to reference it from your EXE project (goto the menu options for selecting references).
0
 
LVL 1

Author Comment

by:cano63
Comment Utility
can you give a link or a place that i can find an example. I tried to make a dll but it don,t want to compile it give and error
not creable public content find
0
 
LVL 16

Expert Comment

by:HooKooDooKu
Comment Utility
Are you using VB6 or VB.NET?
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 1

Author Comment

by:cano63
Comment Utility
vb6.0
0
 
LVL 16

Accepted Solution

by:
HooKooDooKu earned 125 total points
Comment Utility
In the code snippet below, I have included the entire contents of three files that can be used to create a VB DLL.  Copy and paste the full text below the lines ***File: FILENAME *** into notepad and save the file as the FILENAME specified.  Then open the ProjectDLL.vbp and compile the DLL.  Then create a new sample VB EXE.  Display the References window from the menu option "Project/References" and select "Sample VB DLL" from the list of available references.  Then drop a command button on the form of the sample EXE and insert the following code:

Private Sub Command1_Click()
Dim C1 As New Class1
    Call C1.Sub1
    Call Sub2
End Sub

This will demonstrate how your VB EXE can work with the DLL defined in the snippet below.

Where you're ready to create your own DLL, here's the basic steps:
1. Start VB
2. If the 'New Project' window doesn't automatically pop-up, select Menu option "File"/"New Project".
3. Select "ActiveX DLL" (NOT ActiveX EXE)
4. The project will start with a default class of "Class1".  Begin adding code to that class (renaming the class as desired).
5. Add additional classes, forms, and modules to the project as desired.
Note that anything placed inside a module is private to the DLL.
Classes and Forms are visible outside the DLL based on the Class/Form Property "Instancing"
For Instancing:
  1-Private = Not visible outside of DLL
  2-PublicNotCreatable = Public Functions/Subs are visible outside of DLL, but only the DLL can create an instance of the Class/Form
  3-SingleUse = [Not a valid option for an ActiveX DLL]
  4-GlobalSingleUse = [Not a valid option for an ActiveX DLL]
  5-MultiUse = New instances of the class can be created from outside of DLL and public Functions/Subs can be call from outside of DLL
  6-GlobalMultiUse = Same as option 5, but an instance of the class is automatically created and Public Functions/Sub of the class can be called without referencing the object.
6. Goto menu option "Project/[ProjectName]Properties.  Set the Project Name and Project Description.  Note that when you reference this DLL later, you will select it froma list of available references based on Project Description.
7. Compile the DLL
8. To use the DLL on another machine, copy it to that machine and register the dll (RegSvr32), otherwise, it will automatically be registered on the machine in which it is compiled.
9. Create a New "Standard EXE" project.
10. Select Menu option "Project"/"References".
11. Select the recently created DLL (by Project Description set in step 6).  Note that the EXE and the DLL must have different project names.  If you attempt to create example code and just use the default names, VB will assign both of them as "Project1" creating a naming conflict.
12. Begin creating instances of classes/forms defined in the DLL.

***File: ProjectDLL.vbp***

Type=OleDll

Class=Class1; Class1.cls

Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#..\..\WINDOWS\system32\stdole2.tlb#OLE Automation

Class=Class2; Class2.cls

Startup="(None)"

HelpFile=""

Title="ProjectDLL"

ExeName32="ProjectDLL.dll"

Command32=""

Name="ProjectDLL"

HelpContextID="0"

Description="Sample VB DLL"

CompatibleMode="0"

CompatibleEXE32="ProjectDLL.dll"

MajorVer=1

MinorVer=0

RevisionVer=0

AutoIncrementVer=0

ServerSupportFiles=0

CompilationType=0

OptimizationType=0

FavorPentiumPro(tm)=0

CodeViewDebugInfo=0

NoAliasing=0

BoundsCheck=0

OverflowCheck=0

FlPointCheck=0

FDIVCheck=0

UnroundedFP=0

StartMode=1

Unattended=0

Retained=0

ThreadPerObject=0

MaxNumberOfThreads=1

ThreadingModel=1
 

[MS Transaction Server]

AutoRefresh=1
 

***File: Class1.cls***

VERSION 1.0 CLASS

BEGIN

  MultiUse = -1  'True

  Persistable = 0  'NotPersistable

  DataBindingBehavior = 0  'vbNone

  DataSourceBehavior  = 0  'vbNone

  MTSTransactionMode  = 0  'NotAnMTSObject

END

Attribute VB_Name = "Class1"

Attribute VB_GlobalNameSpace = False

Attribute VB_Creatable = True

Attribute VB_PredeclaredId = False

Attribute VB_Exposed = True

Option Explicit
 

Public Sub Sub1()

    MsgBox "Class1.Sub1"

End Sub
 

***File: Class2.cls***
 

VERSION 1.0 CLASS

BEGIN

  MultiUse = -1  'True

  Persistable = 0  'NotPersistable

  DataBindingBehavior = 0  'vbNone

  DataSourceBehavior  = 0  'vbNone

  MTSTransactionMode  = 0  'NotAnMTSObject

END

Attribute VB_Name = "Class2"

Attribute VB_GlobalNameSpace = True

Attribute VB_Creatable = True

Attribute VB_PredeclaredId = False

Attribute VB_Exposed = True

Option Explicit
 

Public Sub Sub2()

    MsgBox "Class2.Sub2"

End Sub

Open in new window

0
 

Expert Comment

by:Adam_930
Comment Utility
This code works as printed, but I wanted to see how changes work.
I made a change to see what would happen,
ORIGINAL CODE:
Public Sub Sub2()
    MsgBox "Class2.Sub2"
End Sub

NEW CODE
Public Sub Sub2()
    MsgBox "This is Class2.Sub2"
End Sub
The dll compiles OK

I get the error:
  Could not create reference: 'Sample Dll\Project1DLL.dll'
when I try to run my EXE project
I even tried to run RegSvr32 again

If I copy in the original code again, it works fine
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
Windows Script Host (WSH) has been part of Windows since Windows NT4. Windows Script Host provides architecture for building dynamic scripts that consist of a core object model, scripting hosts, and scripting engines. The key components of Window…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

11 Experts available now in Live!

Get 1:1 Help Now