logo
vbRad Home
Source Code
Book Reviews
Forum
Links
About Us
Contribute

Compare Databases with SQL Effects Clarity
 
 Creating "Hidden" Public Interfaces

Posted on
2/18/2001
Author:
Matthew Ferry
Email:
Not Shown
Applies To OS:
All
Product:
5, 6



Many people don't realize it but it is very easy in VB to hide public members of your class objects. This means that your project can have a class that has a member (Sub, Function or Property) which can be called by a client application but only if the client app knows the name and parameters to call and pass. Such an interface works in the same way that a normal "exposed" interface does with the exception thats its description in the type library is hidden. This means that this member will not show up in the object browser or in VB's intellisense feature either.

Why Hide Interfaces?
Most of the time this kind of covert stuff is really not necessary - and you should never think that this technique is a foolproof way to provide security features for your component because it simply is not. Decompilers and other "black book" techniques can find your hidden interfaces easily enough.
That being said, there definitely is a place for hiding your interfaces. If you are developing components for use by persons other than yourself (the public, another department or team - whatever...) then you might come across a situation where you want to have public methods that are not normally used by whomever you are writing the component for. For example suppose you create a server that runs on a remote machine that other departments will be calling. You could build "hidden" interfaces into the server to allow someone (probably yourself!) to administer and tune the server. The advantage of making such administrative interfaces hidden is that they then uncomplicate the standard interface that other people are using. This is sort of a what they don't know won't hurt them approach, and will help you minimize the amount of time you spend providing these folks tech support.

How do I do it?
You can hide any Public Sub, Public Function, or Public Property in your component by performing the following steps.

1. Write the member's prototype line - and put your cursor inside the code block created by the new member.
2. Click the VB Tools menu and then select the menu item "Procedure Attributes."
3. Click the "Advanced" button to display an extended view of the Procedure Attributes dialog.
4. Check the checkbox called "Hidden."

Thats it! You have just made the current procedure a hidden one. What could be easier? Make sure you repeat these steps for whatever other procedures you would like to hide. The steps are the same for both VB5 and VB6.

Note: After the project is compiled the hidden members will not show up in the object browser or in intellisense. They will always show up, however, when you pull the component's source code back into the development environment.

Add Your Comment  

Name: Email Address: all fields optional
Notify me via email when someone responds to this message (valid email required).

Enter the word:
 



Comments
#1. By Marc Miron. Posted on 4/18/2006 6:26:29 PM
I agree this is possible but i would like to suggest that the use of an interface be used instead regarding your example of administrating the server.
Eg: an Server.IAdministrator interface can be created with the following methods
private sub ServerFunction1(...)
end sub
....

and the actual server code would implement this interface. Which would allow it to be instantiated later on as a IAdministrator instance and worked on properly by the administrator.

I believe this is better suited regarding your example.

Cheers,
Marc.