Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Newbie in COM
Message
 
To
30/07/2006 23:41:22
General information
Forum:
Visual FoxPro
Category:
COM/DCOM and OLE Automation
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01141724
Message ID:
01141922
Views:
18
This message has been marked as the solution to the initial question of the thread.
Hi Farouk,

Here are some pieces from my San Diego 2001 DevCon session "Introduction to COM", which migh help you better understand it.

***********************************************************************************

COM can be compiled as an In-Process (DLL), or an Out-Of-Process (EXE). This affects the way you register it, and there can be a performance difference. A DLL server works in the same process as the COM client (or another COM which instantiated it), therefore all communication happens within the same process. An EXE server, however, works in its own process, so the communication goes across processes, and that's why it is slower. From the client side, running a DLL in the same process also makes the client application vulnerable to server crashes, which is not the case with an EXE server. It is up to you to decide which one to use, but remember that DCOM should be an EXE.

In Visual FoxPro COM objects can be created programmatically or visually in a class library. The key for creating the COM is the OLEPUBLIC keyword. The only difference between this COM class and a normal VFP class is that it has been marked as being OLE PUBLIC. This is not a property of the class, (which means it's not inheritable), but an indicator to VFP to publish this class to the world outside of VFP. When you subsequently build an EXE or DLL (DLLs must have at least one OLE Public class), then the result will be a COM server that can be invoked from any other COM client.

Now let's go to the Project Info menu option under Project menu pad. You see the Servers tab. (Figure 5). There is a combobox with "Single Use" and "Multi Use" options. If we compile the EXE with "Single Use" option selected and create two instances of our object:


oCom1 = CREATEOBJECT("fce.mycomclass1")
oCom2 = CREATEOBJECT("fce.mycomclass1")

You will see two instances running in the Task Manager Processes tab. This should not be confused with single user, as in the above sample one user creates two (or more) Single-Use instances of the COM server.
In other words, single user on single PC may create any number of Single-Use COM server instances.

Select "Multi Use" and recompile the EXE. Run two instances of the COM object again and you will see only one instance in the Task Manager.

The value in the Instancing combobox determines how your COM component will be used. If you choose single-use for your out-of-process COM, each client application will use its own instance of COM server with all the related overhead in creating a new process that you can see in Task Manager and allocating resources for it. However, provided that the PC has enough resources the performance of this component may be better because each process has at least one thread running.

Please do not mix Multi- or Single- Use for the instancing from Project Info dialog with Multi- or Single- threading from the Build dialog. These are two different things.

What happens when you select Multi-Threaded COM DLL from the Build dialog? In a multi-threaded environment the process of the request execution may be interrupted by other requests. As an example, three client requests arrive to your multi-threaded COM DLL almost at the same time. First request runs some long calculation method in your COM and other two just want to query some COM property. In a single-threaded environment the last two requests have to wait until the first one is finished, say in a minute and then the other two requests are executed for one second each. So, all three clients got the result in about one minute each. In a multi-threaded environment the long process can be interrupted with others. The result is that for the first long query the execution time will slightly increase, but two short ones are executed almost at once. So, the multithreaded COM will have a better performance from the user point of view. It does not mean that several simultaneous calls to COM will take less total time. There is still just one processor to execute all calls, plus it needs the time for the thread switching. The real performance increase can happen only on multiprocessor PC.

Note, that programming for multithreaded COM is different from writing the normal code. You supposed to use the SYS(2336) function which can lock and unlock the critical sections of the program where no any interference from other threads, calling the same code, may be allowed. Programming for multithreaded COM also should be a topic for a separate session.

The Multithreaded DLL option first appeared in VFP 6 Service Pack 3 and in order to take advantage of it you are supposed to use a different runtime library - VFP6T.DLL You should refer to the documentation as there is some difference in VFP features supported in normal VFP6R.DLL and VFP6T.DLL
Multithreaded DLL can be used only with "Multi-Use" option, while single-threaded DLL may be both Single-Use and Multi-Use. Multithreaded DLLs is what you should use for the heavy load web site programming.

Just one note about the third choice in the combobox -"Not Creatable". What it that? This choice should be used in case in you reuse your class library containing COM object in another project where you want to use only the object and it's methods without installing it as COM. By choosing "Not Creatable" you prevent compiling it as COM.
Nick Neklioudov
Universal Thread Consultant
3 times Microsoft MVP - Visual FoxPro

"I have not failed. I've just found 10,000 ways that don't work." - Thomas Edison
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform