 |
|
 |
Please let me know how to know what threading model a project uses ? Also, let me know in detail the available threading models in VB.
Seethalakshmi A
|
|
|
|
 |
|
 |
In visual basic 6.0 it uses STA as the default. When using C++ you have the option to choose between STA and MTA. A rule of thumb is not to mixed the two models otherwise you will end up with unpredictable results and it will be harder to repro any possible errors because of this.
I do agree with the author that the MTA model is the one to use whenever it is possible.
--
Jess Nielsen
Security Analyst
C++ Programmer
|
|
|
|
 |
|
 |
Hello,
I created an COM (.exe) in STA. I would like to use it to shared data between different software.
I also created a client which call the COM.
until now no problem, when I start the client I access the COM, I can write and read in it.
but when I start another client. I click to read the value: it is not the value I wrote in the first client.
do you have some ideas to help me??
thank you in advance.
Pascal.
|
|
|
|
 |
|
 |
Hi,
Please refer to:
Q I want to implement a singleton object in COM. How should I do it?
http://www.microsoft.com/msj/0797/activex0797.aspx
|
|
|
|
 |
|
 |
I have an COleDispatchDriver pointer in the main thread, and I am calling the InvokeHelper in another thread, then it is returning this error: RPC_E_WRONG_THREAD, the ::OleInitialize(NULL); has been done in the sub thread. Can anyone has some solution for this problem.
http://www.geocities.com/priyank_bolia/
|
|
|
|
 |
|
 |
Hi,
"How To Marshal Interfaces Across Apartments"
http://support.microsoft.com/default.aspx?scid=206076
|
|
|
|
 |
|
 |
I can't understand that article, the problem is that I have a COleDispatchDriver pointer in the main thread : COleDispatchDriver *m_pVicApp which is used in some other thread to call InvokeHelper for the server function, whose code I don't have.
http://www.geocities.com/priyank_bolia/
|
|
|
|
 |
|
 |
Before using COleDispatchDriver pointer in another thread, the real COM interface pointer has to be marshaled to another thread. Before making the call you unmarshal the COM interface pointer and make the call on that pointer. That article describes a number of ways on how you you can do the actual marshaling.
|
|
|
|
 |
|
 |
Hi, Can you try to use ::CoInitializeEx() with COINIT_APARTMENTTHREADED parameter instead of ::OleInitialize(NULL); This is very interesting problem. Thread models are very important. For instance If you initialize your software by wrong parameter you might get some problems. Probably you get some errors while your long process when you use ADO components, or common dialog boxs might failed in some operating systems.
|
|
|
|
 |
|
 |
if your two object created in same STA, no reenter HAPPEN..........
|
|
|
|
 |
|
 |
Hi,
We are present developing a network system. In the console side, We choose VB to be our development tool. We used VC and made a ActiveX DLL called ThreadController to create threads for VB. Each thread created by this ActiveX DLL will invoke a VB ActiveX DLL called ViewDLL where there is a VB Form in it. There are several kinds of ViewDLL in the console.
All of threads are derived from CWinThread in MFC. We thought we can use this machanism to make VB's programs act as multithread. The ThreadController is binded in a VB ActiveX EXE Program called ControlPanel. All of the communications between ControlPanel and other VB ActiveX DLLs are by Windows Message.
When ControlPanel catchs a data from Server, it will use PostMessage to those Windowss in ActiveX DLLs and then these ViewDLLs will refresh themselves. Now there is a problem we still can't figure it out.
Frist, each ViewDLL is created by a thread, so it should have its own window message queue and CPU resources. However, thing going not as we expected. We found if we call a infinite function call in a ViewDLL, it will make all of threads locked and have to wait for the ViewDLL which is running infinite function stopped and then the other ViewDLL can accept Windows Message. We really don't know what's going on in this situation. Do we choose a wrong tool to develop our system? Is the problem is about Free Threading Model? I knew VB can't do that. We are so confused. Can you help me?
Please forgive if I made many grammar mistakes, I'm not good at English writing. Thanks first.
Scott
Mercury Data System(MDS)
http://www.mds.com.tw
|
|
|
|
 |
|
 |
Hi Scott,
It's hard to understand the project details and therefore I can't really help
"We found if we call a infinite function call in a ViewDLL, it will make all of threads locked and have to wait for the ViewDLL which is running infinite function stopped and then the other ViewDLL can accept Windows Message."
Are you sure each COM object is created on separate thread and dispatches messages? It seems as if
only one thread dispatches messages and therefore doesn't seem concurrent to other COM objects that you have.
|
|
|
|
 |
|
 |
I've been working on a multi-threaded ActiveX control for handling serial port communications from various ports. I wrote the control in VC++ using the MFC wizard. I wrote a VB application to test it. I found that it only worked consistently in VC++ Debug mode, and even then would fail in any VB event procedure if I put a break in it. Subsequent testing in Delphi and some in a VC++ app suggest there is nothing wrong with the control. I tried every trick I could dream up to make it work in Visual Basic. The documentation about apartment threading always talks about the app, not objects placed in them, but in some places I have seen statements to the effect that everything in a single threaded apartment runs on the same thread. Since the control is presumably trying to run as an in-process component, I suspect that it fails because of the attempt to retrieve data in the other thread. In sum, I conclude that a multi-threaded object can not successfully run in VB6. VB.NET is touted as compatible with all threading modes, and I suspect will handle such a beast, so you may say recover your development time expended by switching to the beta now. I would appreciate response or comments to confirm or shred this interpretation.
|
|
|
|
 |
|
 |
Hi,
I can use a VB activex dll in a vc app without any problems. but when I try to create the component and access methods FROM A SEPARATE THREAD of the client, everything crashes. Why is this happenning?
My idea is that the dll is Apartment threaded (STA). To use component from a separate thread than the main thread of the client, component needs to be MTA. Hence, the problem..
Is this so? Then would the problem go away if I use an Activex exe component since they run in their own thread.
TIA.
Hush..Hush.. thought I heard you calling my name now...
|
|
|
|
 |
|
 |
Hi,
In your VC app I assume you created the VB Activex component in STA apartment. If so,
then when you need to access the component's interface pointer from another thread,
you have to marshall the interface pointer to another thread. It can be done either through
1. CoMarshalInterThreadInterfaceInStream/CoGetInterfaceAndReleaseStream
Or
2. IGlobalInterfaceTable
CoCreateInstance(CLSID_StdGlobalInterfaceTable, ...)
IGlobalInterfaceTable::RegisterInterfaceInGlobal
IGlobalInterfaceTable::GetInterfaceFromGlobal
IGlobalInterfaceTable::RevokeInterfaceFromGlobal
The problem will not go away if you use ActiveX as .exe instead of in-proc .dll.
Let me know if you have any problem
Thanx
Leon
|
|
|
|
 |
|
 |
So, If I understand correctly, If I have two threads in client application (using COM) which has entered STA, and if I want to use COM Instance initialized from one thread in other thread, I will have to marshal the interface pointer before using it. But what happens if I have more than one threads all are in STA and all are creating their own instance of COM object ? Will any marshelling required then ? I think no, but still want to confirm.
Regards,
Jigar Mehta
|
|
|
|
 |