Wrox Programmer Forums
|
VB Components Issues specific to components in VB.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 22nd, 2004, 05:39 PM
amc amc is offline
Authorized User
 
Join Date: Feb 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default creating an activex dll

I want to create an activex dll that uses global / public variables, not defined in the scope of the dll itself, but in the outside world. Is this possible? and, if so, how?

the obvious answer, pass all the globals to be used as parameters, would cause a massive parameter-passing situation, that is, precisely, what I want to avoid.



thanks
antonio
__________________
thanks
antonio
 
Old March 3rd, 2004, 06:48 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Have to have a reference to the ActiveX Exe or Dll that originally dimensions these variables. Instantiate the relevent object containing the variables you're after and access the variables. I can't remember if you can access global/public variables belonging to another object in VB6 (can in .Net), but if you find you can't you'll just have to have the relevant variables as properties in the original object

 
Old March 3rd, 2004, 06:57 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 142
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Further to my last post, if you're worried about the amount of overhead of the parameters, you probably need to think about whether to pass the parameters ByVal or ByRef.

Basically, the difference is that if you pass in a parameter ByRef (the default in VB6), it gives the method a reference back to the original variable/object - this is useful when the variable/object is particularly large, so you don't want more than one in memory. The downside of ByRef is if you are using DCOM then if you reference the variable/object a lot, you'll create a fair amount of network traffic - depends on network speed as to how efficient this is.

The other option, ByVal, is the default in VB.Net. This avoids the excessive network traffic pitfall by creating a copy of the variable/object, but if you are passing in a lot of very large variables/objects you'll get a lot of system resources consumed by your method. It can also create a nightmare for trying to tidy up objects later on - you'll have to set the parameters to be nothing before the method ends because, unlike passing ByRef, you have a whole new object in a different memory area that needs to be destroyed. Fail to do this and you'll be creating memory leaks in your application.



 
Old March 3rd, 2004, 07:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Jaucourt, I don't think that's right when talking about objects. In VB6 you get a reference to the object whether you pass it ByVal or ByRef. The only difference is that you can't modify the original reference if its passed ByVal (for example if I receive an object ByRef I can set it to Nothing, but if I receive the object ByVal I can only set the copy reference to Nothing which doesn't affect the original object reference).

rgds
Phil
 
Old April 27th, 2004, 03:26 PM
amc amc is offline
Authorized User
 
Join Date: Feb 2004
Posts: 27
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks,

Specifically I would like that a dll could receive the value of a pointer to a open Access database. Not by parameter passing, but through another way, (I thought in using the Registry as a way to write/read, but it would be valid for string, numerical variables, but not for an object that is valid out of the scope of the dll itself)

Is it possible ? I imagine that "system" dll "see" system structures although they are not namely passed to them.....

thanks


thanks
antonio
 
Old May 17th, 2004, 12:26 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You mean you want to pass a pointer between applications?!?!?!
Marco
 
Old June 24th, 2004, 08:58 AM
Authorized User
 
Join Date: May 2004
Posts: 83
Thanks: 0
Thanked 1 Time in 1 Post
Default

One way or the other, u must pass the parameters to the dll. One way to do it is to package all the variables in a data structure (that might be an array, a type, or a collection) and pass it to the dll function. You don't get any performance penalties using this method. It will, however, make your code more readable where you are calling the function if u really have a large number of parameters to pass.

ejan

ejan
 
Old June 25th, 2004, 05:10 PM
tnd tnd is offline
Authorized User
 
Join Date: Jun 2004
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Such an old post. Wonder if you are still looking for the answer.

You can achieve your goal by creating a 3rd COM object. This object must be in a seperate project. What you need is to have your main project and ActiveX.dll both reference this 3rd object. You can then set the values of the 3rd object from your main and retrieve it from you ActiveX.dll. You can even create additional program and share this data if you create the COM as an ActiveX.exe.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Advantages /Disadvantages of ActiveX DLL & ActiveX priyank Beginning VB 6 6 February 19th, 2007 11:34 AM
ActiveX DLL Joann Beginning VB 6 6 January 25th, 2007 08:50 PM
Using ActiveX DLL in ASP Andraw Classic ASP Basics 13 January 22nd, 2007 06:07 AM
ActiveX Exe and Dll Vasudevan VB How-To 1 September 26th, 2003 07:48 AM
Creating Activex DLL components vbmo Classic ASP Components 11 June 30th, 2003 04:37 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.