|
Caveats of the CopyMemory API function
|
Total Hit (4194) |
Here's the correct declaration of the CopyMemory API function, which is so useful whenever you want to move a block of bytes between two memory locations:
«Code LangId=2»
Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (dest As Any, _
source As Any, ByVal bytes As Long)
«/Code
....Read More |
Rating
|
|
|
Determine whether an API function is available
|
Total Hit (3551) |
In many cases you may want to call an API function, but you aren't sure whether the Windows version the application is running on supports that particular function.
The easiest way to test whether a function exists and can be called is to replicate through VB code what Windows itself would do whe
....Read More |
Rating
|
|
|
Extract null-delimited strings
|
Total Hit (3758) |
Most API function that return a string require that you pass a buffer where they can place the result as a null-terminated ANSI string (a.k.a. ASCIIZ string). The calling code must then extract the string by taking all the characters up to the first Chr$(0) character, if there is one. For example, t
....Read More |
Rating
|
|
|
Never use the GetLastError API function
|
Total Hit (3857) |
If you heavily use API calls and strictly follow the SDK documentation, you might be tempted to use the GetLastError API to retrieve the error returned by your last API function or procedure. However, this function doesn't always return valid error codes, because Visual Basic internally does a lot o
....Read More |
Rating
|
|
|
Use Currency instead of LARGE_INTEGER values
|
Total Hit (3406) |
A few API calls require that you pass one or more LARGE_INTEGER arguments. These are 64-bit integer values, defined as follows:
«Code LangId=1»
Type LARGE_INTEGER
lowpart As Long ' lower 32-bit value
highpart As Long ' higher 32-bit value
End Type
«/Code»
Unfortunately, wor
....Read More |
Rating
|
|
|
Reduce activation delays by sorting DCOM protocol list properly
|
Total Hit (1938) |
When the client and the server machine have different communication protocol lists you can experience serious delays when the client tries to instantiate an object on the server, and you can even get an error if the two protocol lists don't have any protocol in common.
For best response times, us
....Read More |
Rating
|
|
|
Avoiding Access Denied erros when raising events from MTS objects
|
Total Hit (3164) |
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 (3082) |
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 (2911) |
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 (2824) |
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 (2676) |
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 (2701) |
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 (3561) |
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 (3618) |
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
|
|
|
Improve availability by running a COM+ app as an NT service
|
Total Hit (1799) |
COM+ 1.5 has the ability to run any server application as a NT service, so that the application is up and running when the machine reboots, before any client makes the first requests. This improves the response time of the COM+ application. Besides, running a COM+ app as a service means that it can
....Read More |
Rating
|
|
|
Make COM objects in a COM+ application visible to clients
|
Total Hit (1775) |
What I describe for COM+, applies to MTS with some slight differences as well.
Registering COM objects remotely has been quite a pain before MTS showed up (remember the VBR file?). In COM+ it's very easy to do:
1) Right click on the COM+ application and choose export Choose application proxy,
....Read More |
Rating
|
|
|
Misconceptions on variables and binding
|
Total Hit (1851) |
Consider this line of code:
Dim x as Project1.Class1
Many developers think that we were declaring x as a "Project1.Class1" object. This is wrong. All object variables in VB are interface variables. In this line of code x is declared as the _Class1 interface defined in the Project1 Type librar
....Read More |
Rating
|
|
|
Never use New to create MTS/COM+ objects
|
Total Hit (1855) |
A common question among VB developers is: Why is it dangerous the use of the New keyword in VB to create COM objects registered under MTS/COM+?
The New keyword is the only way to go when you want to create objects that are defined as PublicNotCreatable or Private (CreateObject doesn't work) insid
....Read More |
Rating
|
|
|
Reduce COM+ context overhead: use non configured classes
|
Total Hit (1649) |
In another item in this Tip Bank (see link below), we mention that you can co-locate secondary instances within the context of the caller. If you don't need any services at all for your secondary components, then you don't have to configure them as COM+ components either. You lose the deployment and
....Read More |
Rating
|
|
|
Reduce context overhead for COM+ components
|
Total Hit (1524) |
Instances of configured components, that is, components configured in COM+, get runtime services owing to context objects. When you instantiate a COM+ component, your instance will live in a context object. When you call a method of your instance, the call will go through the context and that is whe
....Read More |
Rating
|
|
|
Replicate a complete COM+ catalog to another machine
|
Total Hit (1853) |
The Component Services MMC gives you an easy way to export and import COM+ applications. However, if you want to export the entire COM+ catalog to one or more systems on your LAN you can do it quickly with the COMREPL command-line utility, which you can find in the c:\windows\system32\com directory.
....Read More |
Rating
|
|
|
Setting authentication across different domains
|
Total Hit (1476) |
COM doesn't have a built in security mechanism, but relies on Windows authentication services (Security Service Providers). When you access a resource or invoke a method in a remote DCOM server (or MTS package / COM+ Application), security checks cannot be performed in the standard way if the client
....Read More |
Rating
|
|
|
The best setting for the RunAs option in a server package
|
Total Hit (1789) |
When you deploy COM objects in DLLs no security issues arise since DLLs run in the process of the caller. On the contrary, when you deploy your COM objects into an .EXE, you have to deal with such issues.
- (D)COM needs to know under what security principal (read identity) the process, where you
....Read More |
Rating
|
|
|
Tips for debugging MTS components in the VB IDE
|
Total Hit (1605) |
It was and it is still easy to debug MTS components written on Visual C++ version 5 and higher. Debugging components written on Visual Basic 5 is possible under VC IDE. Starting with version 6, Visual Basic allows to debug under its own IDE. Here are the things you should keep in mind while preparin
....Read More |
Rating
|
|
|
Setting authentication across different domains
|
Total Hit (1680) |
COM doesn't have a built in security mechanism, but relies on Windows authentication services (Security Service Providers). When you access a resource or invoke a method in a remote DCOM server (or MTS package / COM+ Application), security checks cannot be performed in the standard way if the client
....Read More |
Rating
|
|
|
Avoid duplicate entries for the same serviced component
|
Total Hit (2694) |
A common mistake when creating a .NET component that runs under Component Services - that is, a class that inherits from ServicedComponents - is that you forget to assign a fixed version and/or GUID to the component being built. In this case, whenever the assembly is modified and recompiled, a new v
....Read More |
Rating
|
|
|
Reduce COM+ context overhead: activate in the caller's context
|
Total Hit (2774) |
Even though you may want to use some COM+ services, it doesn't mean that you have to have a unique context for each and every instance. The root instance, that is, the instance that the client uses, must have a context, but the secondary instances can often co-locate within the first context.
In
....Read More |
Rating
|
|
|
Reduce COM+ context overhead: use modules and shared members
|
Total Hit (2786) |
If you use Shared members in .NET or modules in VB6, you reduce COM+ context overhead without any risk whatsoever that you will get extra context overhead for that code. You also release yourself from the clean-up burden that you have in both worlds. Instead of the VB6 consumer code:
«Code LangId
....Read More |
Rating
|
|
|
|
Support COM+ constructor strings in serviced components
|
Total Hit (2877) |
Having a VB6 component support a COM+ construction string requires that you implement the IObjectConstruct interface and its only method, Construct. The .NET ServicedComponent class implements this interface internally and expose the Construct method as a protected, overridable method. Thus your VB.
....Read More |
Rating
|
|