Solved

Need help creating an ActiveX Dll from a class

Posted on 2002-05-11
28
170 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 8
  • 7
28 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7003866
Try setting Instance property to 5-multiuse.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 7003869
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
ID: 7003871
Besides, using public variables to simulate properties doesn't help you. It only gives you troubles.
In background, VB creates them anyway.
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 

Author Comment

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

Author Comment

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

Expert Comment

by:Éric Moreau
ID: 7004414
the same error or a new one?
0
 

Author Comment

by:Gmoney
ID: 7004534
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
ID: 7004575
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
ID: 7004782
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 70

Expert Comment

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

Author Comment

by:Gmoney
ID: 7005029
Richie could you please create an example project?
0
 

Author Comment

by:Gmoney
ID: 7005088
I still need a lot of help on this
0
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 150 total points
ID: 7005598
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
ID: 7006152
How do I set reference to the DLL emoreau
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7006161
project -> references and then find your component into the displayed list.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7006203
0
 
LVL 16

Expert Comment

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

Author Comment

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

Expert Comment

by:Richie_Simonetti
ID: 7006545
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
ID: 7006703
emoreau, what code do I put in the declarations part of the form?
0
 

Author Comment

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

Expert Comment

by:Éric Moreau
ID: 7006731
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
ID: 7006759
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
ID: 7007301
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
ID: 7007312
Someone please email me tonite, I need this for a project that I suppose to email my boss today.
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 7007447
which errors?
0
 

Author Comment

by:Gmoney
ID: 7007476
Thanks a bunch
0
 
LVL 70

Expert Comment

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

Featured Post

Independent Software Vendors: 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

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

717 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