?
Solved

Get a Form from an ActiveX DLL

Posted on 2003-11-19
13
Medium Priority
?
357 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
[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
  • 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
Industry Leaders: 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!

 
LVL 26

Accepted Solution

by:
EDDYKT earned 1000 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

Technology Partners: 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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…
Suggested Courses

752 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