Solved

How to end from ActiveX DLL?

Posted on 1999-01-20
8
143 Views
Last Modified: 2010-05-03
hi,
I have a VB .exe which calls a function A from VB ActiveX DLL.
in function A, I have a message box. If the user selects  Yes, action will be done, else nothing is performed.
When I chose No, the form still appears. I tried to use the End keyword but it seems that this keyword can't be used in DLL.

Please advise how can i answer No and make the form disappears.

thanks,
andrea
0
Comment
Question by:andreat
8 Comments
 
LVL 4

Expert Comment

by:gencross
ID: 1469753
Use unload formname and in the unload event say...Set objectDllName = Nothing

This should get rid of the reference to the Dll and close the form.


0
 

Author Comment

by:andreat
ID: 1469754
hi gencross,
just to further elaborate my qn,
actually, the message box is on a dummy form with no controls.
the codes are :
calling function
----------------
Private WithEvents mform As fdialog
with mform
   .show vbmodal
end with

fdialog
-------
Private Sub Form_Load()
Dim msg, style, title, Help, Ctxt, response, MyString
msg = "Do you really want to stop all operations?"
style = vbYesNo + vbQuestion + vbDefaultButton2
title = "Stop Operation"
response = MsgBox(msg, style, title)
If response = vbYes Then
    'perform some actions
End If
End Sub

so in this case, I can't use unload in the form_load right?
Please advise.
thanks
andrea
0
 
LVL 13

Expert Comment

by:Mirkwood
ID: 1469755
1) You can't unload in form_load that does not work. You can unload in form_activate or form_show. Just put a variable to true and test for this variable in form_show for example.

2) End in a dll does not work. The dll function should return a value or something on which the client should test. The client can now unload in this case.

Please reject the answer of gencross if it is not sufficient.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 1469756
You can do something about your Show problem.

Create a new Sub in your form as follows:

Public Sub ExternalShow(objOwnerForm As Form, intMode As Integer)

Within this sub you can execute all the code that you have put into the Form_Load procedure

Dim msg, style, title, Help, Ctxt, response, MyString
msg = "Do you really want to stop all operations?"
style = vbYesNo + vbQuestion + vbDefaultButton2
title = "Stop Operation"
response = MsgBox(msg, style, title)
If response = vbYes Then
    'perform some actions
    Me.Show intMode, objOwnerForm
End If

And to call the form:
Private WithEvents mform As fdialog
with mform
   .ExternalShow vbmodal, Me
end with

(You can adapt the sub to
- not have an objOwnerForm parameter if you don't need it
- not have an intMode parameter if you're always going to show the form either modeless or modal.)
0
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.

 
LVL 10

Expert Comment

by:caraf_g
ID: 1469757
You are free to unload the form within this sub
Unload Me

or from outside; it's up to you.
0
 

Author Comment

by:andreat
ID: 1469758
the answer is insufficient.

Mirkwood & caraf_g, I will try out your suggestions and then
revert to you for answering.

thanks,
Andrea
0
 

Author Comment

by:andreat
ID: 1469759
caraf_g : I've tried your suggestion but I get error 13 on
ExternalShow Me


Mirkwood : for my problem above, i can't return a value from form_load right? does it mean that I have to create another function X in fdialog and return a value from X? if that's the case, how do i call the function X from the calling project?

thanks,
andrea
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 20 total points
ID: 1469760
You could "Translate" the intMode parameter, let's say you decide that 1 = modeless, and 2 = modal.

You can then change the code as follows

If response = vbYes Then
    'perform some actions
    If intMode = 1 then
        Me.Show vbModeless, objOwnerForm
    Else
        Me.Show vbModal, objOwnerForm
    End If
End If

Please note that you must call the procedure with 2 parameters, for example

   .ExternalShow 1, Me
or
   .ExternalShow 2, Me

Good luck
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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

746 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

10 Experts available now in Live!

Get 1:1 Help Now