Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Pass the hidden Global object to an ActiveX DLL

Total Hit ( 3194)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


An ActiveX DLL doesn't have direct access to the environment of the calling EXE. For example, the App and Printer objects in the DLL don't correspond to the objects with the same name in the main application, therefore if you want to print something from the DLL using the same settings as the main app you must explicitly pass the Printer object from the main application. A similar reasoning applies to other global VB objects, such as the Forms collection.

Instead of explicitly passing the Printer, Forms, and App objects from the main app to the DLL, you can just pass it the hidden Global VB object. This object is actually the parent of the above-mentioned objects (and others as well, such as the Clipboard and the Screen objects). This code invokes a method in the DLL that receives the reference to the global object of the main app:

Click here to copy the following block
' in the main (client) application
Dim obj As New MyDll.Functions
' note that we need a pair of square brackets
obj.SetGlobal [Global]

Here's is the code in the Functions class module of the MyDLL component that receives the reference to the Global object. Note that the argument can't be declared using a specific object type, because this object is private to the VB library and Visual Basic won't let you pass it across project boundaries. Interestingly, the global object is a vtable-only object, and therefore doesn't support IDispatch, so the receiving parameter must be declared using IUnknown:
' in the Functions module of the MyDLL ActiveX DLL project

Click here to copy the following block
Dim glb As VB.Global

Sub SetGlobal(glbIU As IUnknown)
  ' get a reference to the client's global object
  Set glb = glbIU
End Sub

Let's see now how you can enumerate all the forms in the main app from within the DLL:

Click here to copy the following block
' inside the MyDLL ActiveX DLL project
Dim f As Form
For Each f In glb.Forms
  List1.AddItem f.Name
Next

For more information see: MSKB Article Q138069.



Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.