Gmoney
asked on
Need help creating an ActiveX Dll from a class
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).pi cCanvas
.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
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).pi
.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
Try setting Instance property to 5-multiuse.
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.
If so, how class know about them. I cannot see any "connection" between class module and form.
Besides, using public variables to simulate properties doesn't help you. It only gives you troubles.
In background, VB creates them anyway.
In background, VB creates them anyway.
ASKER
setting the Instance property to 5-multiuse helped some but I'm still receiving compile errors.
ASKER
setting the Instance property to 5-multiuse helped some but I'm still receiving compile errors.
the same error or a new one?
ASKER
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
emoreau, i'm getting different errors
ASKER
i got the DLL compiled, now all i need is an example of how to call the DLL in a standard exe project.
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
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
You will need another public property into your class: fMyForm.
ASKER
Richie could you please create an example project?
ASKER
I still need a lot of help on this
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
How do I set reference to the DLL emoreau
project -> references and then find your component into the displayed list.
are mcdonald_g and Gmoney the same?
see
https://www.experts-exchange.com/visualbasic/Q.20299610.html
https://www.experts-exchange.com/visualbasic/Q.20299745.html
see
https://www.experts-exchange.com/visualbasic/Q.20299610.html
https://www.experts-exchange.com/visualbasic/Q.20299745.html
Could explain a little more where do you get the error. All is posting the same comments but...
ASKER
emoreau mcdonald_g is my brother, we are working on the same problem
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.
I mean, automating excel or word, or using FileSystem objects?
If so, you have to use the same approach with your own dll.
ASKER
emoreau, what code do I put in the declarations part of the form?
ASKER
emoreau, your all most there, just give me the complete code to implement the Dll in a standard exe.
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?
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?
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
'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
ASKER
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!
ASKER
Someone please email me tonite, I need this for a project that I suppose to email my boss today.
which errors?
ASKER
Thanks a bunch
will you convince your brother to accept the other question to me too?