Solved

Need help creating an ActiveX Dll from a class

Posted on 2002-05-11
28
166 Views
Last Modified: 2013-11-23
I need help creating an ActiveX Dll from the class posted below. Each time I try to compile the Dll, I get the following message error "No creatable public component detected." Also, after you create the DLL, could you create a sample project using the DLL in a standard exe?

Class:

Option Explicit

' The PictureBox we draw on.
Public picCanvas As PictureBox

' The rectangle's drawing attributes.
Public X0 As Single
Public Y0 As Single
Public Radius As Single
Public DrawWidth As Integer
Public ForeColor As OLE_COLOR
Public FillColor As OLE_COLOR
Public FillStyle As FillStyleConstants
Public DrawStyle As DrawStyleConstants

' Default property values.
Private Const m_def_X0 = 0
Private Const m_def_Y0 = 0
Private Const m_def_Radius = 80
Private Const m_def_DrawWidth = 1
Private Const m_def_ForeColor = vbBlack
Private Const m_def_FillColor = vbBlack
Private Const m_def_FillStyle = vbBlack
Private Const m_def_DrawStyle = vbSolid

' Draw on picCanvas.
Public Sub Draw()

   Form1.Picture1.ForeColor = ForeColor
   ' Set other drawing attributes.
   With fmyform(iCurrentProcId).picCanvas
       .FillStyle = FillStyle
       .FillColor = FillColor
       .DrawWidth = DrawWidth
       .DrawStyle = DrawStyle
   End With

   ' Draw the object.
   Form1.Picture1.Circle (X0, Y0), Radius, Form1.Picture1.ForeColor
End Sub

' Set default property values.
Private Sub SetDefaultProperties()
   X0 = m_def_Y0
   Y0 = m_def_X0
   Radius = m_def_Radius
   DrawWidth = m_def_DrawWidth
   ForeColor = m_def_ForeColor
   FillColor = m_def_FillColor
   FillStyle = m_def_FillStyle
   DrawStyle = m_def_DrawStyle
End Sub

' Set some defaults.
Private Sub Class_Initialize()
   SetDefaultProperties
End Sub
0
Comment
Question by:Gmoney
  • 13
  • 8
  • 7
28 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Try setting Instance property to 5-multiuse.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Where are those form and picture box, in a form?
If so, how class know about them. I cannot see any "connection"  between class module and form.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Besides, using public variables to simulate properties doesn't help you. It only gives you troubles.
In background, VB creates them anyway.
0
 

Author Comment

by:Gmoney
Comment Utility
setting the Instance property to 5-multiuse helped some but I'm still receiving compile errors.
0
 

Author Comment

by:Gmoney
Comment Utility
setting the Instance property to 5-multiuse helped some but I'm still receiving compile errors.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
the same error or a new one?
0
 

Author Comment

by:Gmoney
Comment Utility
could someone copy the class, compile it into a dll, and email it to me in an example of using it?

emoreau, i'm getting different errors
0
 

Author Comment

by:Gmoney
Comment Utility
i got the DLL compiled, now all i need is an example of how to call the DLL in a standard exe project.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
You need to set a reference to that library in your standard exe and create a variable of its type (just like any other COM class):
i.e.

dim objMydll as MyActiveXDll

and from it, maybe you need to create a new one:
set objMydll = new MyActiveXDll.myclass

and you would be ready to use properties/methods from it.

That's a generic approach, you have to know the rest.Hope it helps
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
You will need another public property into your class: fMyForm.
0
 

Author Comment

by:Gmoney
Comment Utility
Richie could you please create an example project?
0
 

Author Comment

by:Gmoney
Comment Utility
I still need a lot of help on this
0
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 150 total points
Comment Utility
I have change this method of your class:

Public Sub Draw(ByRef fMyForm As Object)

  fMyForm.Picture1.ForeColor = ForeColor
  ' Set other drawing attributes.
  With fMyForm.picCanvas
      .FillStyle = FillStyle
      .FillColor = FillColor
      .DrawWidth = DrawWidth
      .DrawStyle = DrawStyle
  End With

  ' Draw the object.
  fMyForm.Picture1.Circle (X0, Y0), Radius, fMyForm.Picture1.ForeColor
End Sub

And I places this into a new standard EXE after having added a command button (command1), 2 picture box (picture1 and piccanvas) and after having set a reference to your DLL.

Option Explicit

Private Sub Command1_Click()
Dim x As Project1.Class1

    Set x = New Project1.Class1
    With x
        .X0 = 1000
        .Y0 = 1000
        .ForeColor = vbBlack
        .FillColor = vbRed
        .Radius = 500
        .Draw Me
    End With
End Sub
0
 

Author Comment

by:Gmoney
Comment Utility
How do I set reference to the DLL emoreau
0
What Security Threats Are You Missing?

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.

 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
project -> references and then find your component into the displayed list.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Could explain a little more where do you get the error. All is posting the same comments but...
0
 

Author Comment

by:Gmoney
Comment Utility
emoreau mcdonald_g is my brother, we are working on the same problem
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
Did you work with active x dll before?
I mean, automating excel or word, or using FileSystem objects?
If so, you have to use the same approach with your own dll.
0
 

Author Comment

by:Gmoney
Comment Utility
emoreau, what code do I put in the declarations part of the form?
0
 

Author Comment

by:Gmoney
Comment Utility
emoreau, your all most there, just give me the complete code to implement the Dll in a standard exe.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
I already posted it in a previous post:

Option Explicit

Private Sub Command1_Click()
Dim x As Project1.Class1

   Set x = New Project1.Class1
   With x
       .X0 = 1000
       .Y0 = 1000
       .ForeColor = vbBlack
       .FillColor = vbRed
       .Radius = 500
       .Draw Me
   End With
End Sub


Are you missing something?
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
Comment Utility
As i posted previously:
'general declarations section of form
dim objMydll as MyActiveXDll

'In sub form_load event
set objMydll = new MyActiveXDll.myclass
'start using methods/properties from here
end sub
0
 

Author Comment

by:Gmoney
Comment Utility
Could someone email me sample project of the Dll and Exe at glynn.mcdonald@charter.net and I will post you the points. I followed the above directions and still got errors!
0
 

Author Comment

by:Gmoney
Comment Utility
Someone please email me tonite, I need this for a project that I suppose to email my boss today.
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
which errors?
0
 

Author Comment

by:Gmoney
Comment Utility
Thanks a bunch
0
 
LVL 69

Expert Comment

by:Éric Moreau
Comment Utility
will you convince your brother to accept the other question to me too?
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…

771 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

9 Experts available now in Live!

Get 1:1 Help Now