Solved

How to end from ActiveX DLL?

Posted on 1999-01-20
8
151 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…
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…

914 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

17 Experts available now in Live!

Get 1:1 Help Now