|
Always declare objects with full library name
|
Total Hit (2923) |
If your application uses objects from external components, either third-party or your own libraries, a good rule of thumb is to include the complete servername.classname string in the Dim statement, as in:
«Code LangId=1»
Dim word As Word.Application
«/Code»
This syntax ensures that if you th
....Read More |
Rating
|
|
|
Always run a component using Full-Compile
|
Total Hit (2807) |
When testing a component in the IDE, always perform a full compilation. This ensures that VB checks the syntax of all the code in the component, which in turn guarantees that no syntax error will break the program while it is serving another application.
You can activate the full compilation opti
....Read More |
Rating
|
|
|
Check a GUID
|
Total Hit (2969) |
The following routine quickly check that a string contains a valid GUID. Of course, it doesn't check that the GUID refers to a valid entity, but at least it lets you quickly reject invalid values:
«Code LangId=1»
Function CheckGUID(Value As String) As Boolean
Const PatternGUID = "{#######
....Read More |
Rating
|
|
|
Compound member attributes
|
Total Hit (2762) |
The Procedure Attributes dialog includes a Procedure ID combo box, that lets you associate a particular ID to a given member of the class. You usually use this combo to make a property or a method the default item of a class or an ActiveX control, but there are other uses as well. For instance, you
....Read More |
Rating
|
|
|
Correct usage for binary compatibility settings
|
Total Hit (3053) |
When working on an updated version of a COM component, you should always enforce Binary Compatibility in the Component tab of the Project Properties dialog box. When enforcing binary compatibility there are a number of common mistakes that you should stay clear of:
Always use the last EXE or DLL
....Read More |
Rating
|
|
|
Create a GUID
|
Total Hit (3942) |
When you build your ActiveX controls and components, Visual Basic automatically creates all the GUIDs as necessary. The same also happens in other cases, without you even realizing it: for instance when you make a MDB database replicable, the Jet Engine adds new fields and uses GUIDs to mark their c
....Read More |
Rating
|
|
|
Create stand-alone type libraries
|
Total Hit (3190) |
Many VB programmers assume that Visual Basic 5.0 is not capable of creating stand-alone Type Libraries, because the documentation states that when an ActiveX component or control is created, the companion Type Library is embedded in the main executable file.
This is correct, but if you own the E
....Read More |
Rating
|
|
|
Creating help string for Enum constants
|
Total Hit (3081) |
I've been trying to find a way to assign helpstrings for Enums in Visual Basic. The Class builder utility does that only for methods, events, and properties, but not for Enums.
The IDL source code that corresponds to an Enum in a type library looks something like follws, and you can run the MIDL
....Read More |
Rating
|
|
|
Don't include Extender properties in ActiveX Wizard
|
Total Hit (3178) |
The left-most listbox in the first page in the ActiveX Control Interface Wizard includes all the properties exposed by the constituent controls currently on the UserControl's surface. Unfortunately, this list includes Extender properties, methods, and events, which should be never added to the publi
....Read More |
Rating
|
|
|
Don't pass Private objects to client applications
|
Total Hit (2912) |
Under some circumstances, an ActiveX DLL can pass private objects to its client application, for example a reference to a control that belongs to a form in the DLL. While this approach can be useful, and can work under some circumstances, you should absolutely avoid avoid to do so, because it might
....Read More |
Rating
|
|
|
Enum constants that include spaces
|
Total Hit (2878) |
If you're writing an ActiveX control, you can create properties that return an enumerated value, as in:
«Code LangId=1»
Public Enum SizeConstants
SizSmall = 1
SizMedium
SizLarge
End Enum
Public Size As SizeConstants
«/Code»
When another developer is using your control, an enu
....Read More |
Rating
|
|
|
Get the Command$ value from inside an ActiveX DLL
|
Total Hit (3179) |
At times you may need to access the command line passed to the application from within an ActiveX DLL. Unfortunately, when inside a DLL the Command$ function returns a null string, so you have to resort to some API trickery:
«Code LangId=1»
Private Declare Function GetCommandLine Lib "kernel32"
....Read More |
Rating
|
|
|
Hide the Automation Manager
|
Total Hit (3432) |
If you haven't switched to DCOM yet, and still use Remote OLE Automation, you must launch the Automation Manager program on the server machine, in order to let the server respond to requests coming from client workstations.
The Automation Manager displays a visible window at launch time, which t
....Read More |
Rating
|
|
|
Never mix SingleUse and MultiUse classes
|
Total Hit (2838) |
ActiveX components written in VB can contain both SingleUse and MultiUse classes at the same time. It usually isn't a good idea to use both types of classes in the same project, however.
When a client creates an instance of a SingleUse class, COM always runs a new instance of the EXE file that ex
....Read More |
Rating
|
|
|
Pass the hidden Global object to an ActiveX DLL
|
Total Hit (3201) |
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 a
....Read More |
Rating
|
|
|
Programmatically register an ActiveX control or DLL
|
Total Hit (4975) |
All ActiveX DLL or OCX export two functions: DllRegisterServer and DllUnregisterServer. They are used to register and unregister the ActiveX in the Windows registry, and are usually invoked from regsvr32.exe at registration time.
However, you can register and unregister these files programmatical
....Read More |
Rating
|
|
|
Rebase compiled DLLs
|
Total Hit (3355) |
Many VB developers know that they should specify a DLL Base Address value - in the Compile tab of the Project Properties dialog box - that is different from the base address of any other DLL or OCX used in the project.
When you are working with a compiled DLL or OCX for which you don't have the
....Read More |
Rating
|
|
|
Register and unregister components with context menus
|
Total Hit (3318) |
The stardard method to register and unregister ActiveX component is running the REGSVR32 utility, which forces you to bring up the Start|Run dialog and manually type the command line. A much better approach is to have the Register and Unregister commands right in the context menu that appears when y
....Read More |
Rating
|
|
|
Register and unregister type libraries
|
Total Hit (3685) |
All COM-oriented VB developers know how to register and unregister an ActiveX DLL, using the REGSVR32 utility. However, there is no such an utility to register and unregister a type library.
You can quickly build your own TLB Registration utility with a handful of statements, thanks to the undoc
....Read More |
Rating
|
|
|
Saving a MSChart image to file
|
Total Hit (5906) |
To save to file the graph generated by a MSChart control, you must use the control’s EditCopy method to copy the image into the clipboard, and then paste it into a PictureBox control. Then, just use the SavePicture function to save the PictureBox’s content to file. Here’s an example:
«Code LangId
....Read More |
Rating
|
|
|
Understanding interface marshaling
|
Total Hit (3681) |
There is quite a lot of misunderstanding among COM newbies about what really happens when a COM interface is passed as a method parameter. As in most of the cases, VB programmers are protected from a lot of details on the COM run-time, but you do have to know such details if you want to assemble som
....Read More |
Rating
|
|
|
Combine Default attribute with other attributes
|
Total Hit (3337) |
When building an ActiveX control, you can set a default property or method using the Procedure Attributes dialog box, after clicking on the Advanced button. However, if your default property also happens to require another special attribute - as is the case with Caption and Text properties-you're in
....Read More |
Rating
|
|
|
Avoiding Access Denied erros when raising events from MTS objects
|
Total Hit (3175) |
If you don't take specific actions, you get an Access Denied Error when you try to raise an event from an MTS component into a client. This happens because the client executable doesn't have the proper DCOM security settings to let the server call it back. In order to have it working you have two so
....Read More |
Rating
|
|
|
Be careful in using CreateObject with two arguments
|
Total Hit (3093) |
If you install a COM+ application proxy on a client and open its Properties dialog, you'll see that the field "Remote Server Name" is set to the server where you created and exported the application. Before you export the component, you can also change the server name by setting the "Application Pro
....Read More |
Rating
|
|
|
Disable COM+ 1.5 applications and components
|
Total Hit (2924) |
COM+ 1.5 (provided with Windows XP) has an interesting feature that is missing in COM+ 1.0: the ability to disable entire COM+ applications or just their individual components. You can disable and re-enable a COM+ application or component by right-clicking on it in the Component Services MMC explore
....Read More |
Rating
|
|
|
Don't let binary compatibility beat you
|
Total Hit (2832) |
When you decide to release a new version of an MTS/COM+ component you should take care of its compatibility with the previous version. There are three types of changes you could make:
(1) You change only internal code of a component, keeping the interface that the component provides untouched.
(
....Read More |
Rating
|
|
|
Don't store object variables in the SPM
|
Total Hit (2685) |
Some MTS/COM+ newbies wonder whether it is legal to store object variables in the SPM.
No, you can't!! the SPM is unaware of Apartment marshaling issues. If you ask the SPM for an interface pointer while running in an apartment that is different from the one where the interface pointer resides t
....Read More |
Rating
|
|
|
Don't use global variables in MTS/COM+ projects
|
Total Hit (2707) |
Public variables at module level are thread specific. Each new thread starts get a new fresh & uninitialized copy of such variables. All the activities that are born from the same object context always run in the same apartment (You can confirm this by checking the thread ID) as if the object contex
....Read More |
Rating
|
|
|
Generating IDL code to overcome binary compatibility issues
|
Total Hit (3571) |
Among the different COM details that VB hides to the programmers, one of the most problematic one is that it doesn't let you take control on interface GUIDs. Binary compatibility settings in VB try to make you follow COM rules (as a fact breaking such rules with the interface forward mechanism it si
....Read More |
Rating
|
|
|
GetObjectContext.CreateInstance is obsolete in COM+
|
Total Hit (3626) |
CreateInstance was necessary in COM to provide a COM object activation mechanism that could be hooked by the MTS runtime before the activation request reached the COM runtime. So that MTS could apply some pre and post activation magic to put a wrapper around the real object and return this wrapper t
....Read More |
Rating
|
|