Solved

Get a Form from an ActiveX DLL

Posted on 2003-11-19
13
353 Views
Last Modified: 2010-05-03
Hi,

I'd like to know if I can retrieve a form from an ActiveX component.

I am testing a component that allows me to "include" a form inside another form. The function that does so needs the reference to the form that should be included.

Eg.  the function would be

       asComponent.SubForm frmIncludedForm

where frmIncludedForm is the form I want to include.

The problem is that the form i want to include is in an ActiveX DLL. I have tried to use Property Get to retrieve the form but it says that I can't return a private object as a parameter of a public function.

Any idea?

pablo


0
Comment
Question by:pablete
  • 6
  • 3
  • 2
  • +2
13 Comments
 
LVL 3

Expert Comment

by:NBrownoh
ID: 9777218
use your public function to call a private one, seems redundandt but it might work???
0
 
LVL 29

Expert Comment

by:Nightman
ID: 9777493
Forms are private.

You cannot return the form instance from one ActiveX.dll to another. Instead, it would probably be easier to create a ShowForm sub in the other dll which then displays it's own form.

Cheers
Night
0
 
LVL 1

Expert Comment

by:c2felicia
ID: 9778913
I tried before with your case. The ActiveX DLL will be added in your project if you clicked the "Add Standard EXE Project" button that inside the tool bar there. The ActiveX DLL will be added in project, not form, but it still work while execute your project forms.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 26

Accepted Solution

by:
EDDYKT earned 250 total points
ID: 9778928
Why not?


Try this
on your dll, add text box on your form


Option Explicit

Private Myform As New Form1

Public Function getform() As Object
Set getform = Myform

End Function


On your standard exe, add 2 buttons

Option Explicit
Private cls1 As Object
Private myform As Object
Private Sub Command1_Click()
Set cls1 = CreateObject("Project1.Class1")
Set myform = cls1.getform
myform.Show
End Sub

Private Sub Command2_Click()
myform.Text1 = Now
End Sub

0
 
LVL 1

Expert Comment

by:c2felicia
ID: 9778943
if you have existing ActiveX DLL, make sure you have added in your project that you want it to execute with your forms. Because we cannot open or add another project into the project. we all known that we only can add forms, modules, ActiveX DLL, User Control........ without a project.
0
 

Author Comment

by:pablete
ID: 9779872
EDDYKT, Have you really tried the solution you suggested? It is completely opposed to the answer that Nightman suggested...

pablo
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9779924
Have you tried?

It works here
0
 

Author Comment

by:pablete
ID: 9780128
Hey EDDYKT, it does work. but, how can be possible? I read from msdn:

"The dialog box is not invoked directly from the client, because forms are private classes. Clients cannot create instances of private classes, and you should never pass instances of private classes to client applications.!

That is what Nightman said...

I am bit lost in this. I am about to give you the points, EDDYKT, but I will split them with somebody who helps me with this contradiction.

Pablo
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9780178
What doesn't work?

Which line cause the problem?
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9780195
The way I do is pass the object from dll to standard exe


When you do that

Private Sub Command2_Click()
myform.Text1 = Now
End Sub


you can see the textbox contain has been changed.
0
 

Author Comment

by:pablete
ID: 9780642
EDDYKT, you are right. I said that it works, but i don't understand the reason... I'll keep this question open till tomorrow waiting for an explanation and then i'll give you the points
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9780874
I don't understand what do you don't understand

This is just OLE object pass to container.
0
 
LVL 26

Expert Comment

by:EDDYKT
ID: 9781083
>>"The dialog box is not invoked directly from the client, because forms are private classes. Clients cannot create instances of private classes, and you should never pass instances of private classes to client applications.!


It is true, I did not create the form from container, I just pass the object to container. The form still create from dll. I just pt it out you still can access from container since dll is run as in-process
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
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…

773 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