|
Have not a clue what it can be from this small excerpt, maybe, you can check, if you initialize the COM in your thread (first thing usually forgoten) on the beginning of your second thread - say CoInitializeEx(...); as a first method of the threadproc and CoUninitialize() as a last one.
Next thingie - the fact that in the second function you checking isFire instead of m_isFire I consider as a typo, but...
Another thing, yes, the interface should be marshalled through CoMarshal... but check carefully what pointer you are using in the Fire_NotifyAllConnectedClients - the pointers you are using there should be unmarshalled (opposite function to CoMarshal...) before you will use them.
I do not work much with exe servers, so I can give you only these 'universal' tips, but maybe it will help you. Don't hesitate to contact me if necessary or need more explanation
|
|
|
|
|
hi, thankx a lot for ur reply !
For ur info I've used a comarshal :
STDMETHODIMP CIBMSSchedule::ExplicitInitialize()<br />
{<br />
HRESULT hr =::CoMarshalInterThreadInterfaceInStream(IID_IInternalExec, static_cast<IInternalExec*>(this), &m_pStream);<br />
<br />
if (FAILED(hr))<br />
{<br />
MessageBox(NULL,"Could not CoMarshal", "CCom control", MB_OK | MB_ICONERROR);<br />
}<br />
<br />
StartThread();<br />
<br />
return S_OK;<br />
}<br />
<br />
void CIBMSSchedule::PreCommand()<br />
{<br />
<br />
HRESULT hr = CoInitialize(NULL);<br />
if (FAILED(hr))<br />
::MessageBox(NULL,"Bad Carma","ReceiveThread",MB_OK);<br />
if (FAILED(::CoGetInterfaceAndReleaseStream(m_pStream, IID_IInternalExec, (void**)&m_pIInternalExec)))<br />
{<br />
::MessageBox(NULL,"Bad Carma, CoGetInterfaceAndReleaseStream","ReceiveThread",MB_OK);<br />
}<br />
}
ExplicitInitialize() called by clients at client's initializion process; and PreCommand() called when this application is about to send event to every connected clients.
And by the way Im not understand what u mean by "the pointers you are using there should be unmarshalled"; however below is the code for Fire_NotifyAllConnectedClients :
VOID Fire_OnReceiveSchedule(BSTR str)<br />
{<br />
T* pT = static_cast<T*>(this);<br />
int nConnectionIndex;<br />
CComVariant* pvars = new CComVariant[1];<br />
int nConnections = m_vec.GetSize();<br />
<br />
for (nConnectionIndex = 0; nConnectionIndex < nConnections; nConnectionIndex++)<br />
{<br />
pT->Lock();<br />
CComPtr<IUnknown> sp = m_vec.GetAt(nConnectionIndex);<br />
pT->Unlock();<br />
IDispatch* pDispatch = reinterpret_cast<IDispatch*>(sp.p);<br />
if (pDispatch != NULL)<br />
{<br />
pvars[0] = str;<br />
DISPPARAMS disp = { pvars, NULL, 1, 0 };<br />
pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);<br />
}<br />
}<br />
delete[] pvars;<br />
<br />
}
I will email to u the application together with program flow for ur reference. Is it possible to put attachments here ?
Thanx a lot in advance.
Regards,
newbie
|
|
|
|
|
Goood morning there
OK, I think I get it. It wasn't too difficult. But first, what I meant by the "the pointers you are using there should be unmarshalled". I saw a people making code like that:
pseudo
MarshalInterface
start thread
Unmarshal Interface to member m_spCorrect;
use completely another member like m_vec.GetAt directly from the new thread (therefore need marshalling but not used on this pointer).
But this was not your case.
Your problem is hidden in, say unrelated, method CIBMSSchedule::Run. Here you have somewhere about line 111 command Sleep(5000); and this is that one causes your problems. How marshalling works is, very shortly, that if he needs to transfer call from thread A to thread B, (s)he/it uses a old plain window messages. Then all threads in STA (you are using) must have the message pump to work correctly.
Then replace your Sleep(5000) with something like:
<br />
MSG msg;<br />
while( ::PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) )<br />
{<br />
BOOL bRet = ::GetMessage(&msg, NULL, 0, 0);<br />
<br />
::TranslateMessage(&msg);<br />
::DispatchMessage(&msg);<br />
<br />
}<br />
and then your code started to work for me (Event received at VB client).
Some another notes:
- consider to somehow remove the Sleep design pattern .
- I see that you are adding thread for each client, but didn't see the remove mechanism (might be my fault, didn't check it too carefully )
- hint: I believe (as I don't work with exe components), that for remove this marshalling pains, you can use CoInitializeEx(NULL,COINIT_MULTITHREADED); for free threading. Then it behaves like normal threads and no need for marshaling (only between VB and VC). Then you don't need to carry about, as the _tWinMain already contains the msg pump doing that.
Hope this helps & enjoy
|
|
|
|
|
hi,
thanx geo. U advice is works. But somehow when I run the application it took a lot of CPU (99 %). I think its b'coz of PeekMessage. Is there any replacement for PeekMessage ?
For ur info i've try to change ur code to prevent this problem, but i cant send message to clients.
Thanx a lot geo. U really help me a lot
Regards,
Din Krop
|
|
|
|
|
You are welcome
This CPU burning is probably again done by the Run function and some more around -> if you minimize it to the smallest possible workflow you get something like:
while( MayIContinue() )<br />
{<br />
if( fire ) {fire_it();};<br />
}
if there is nothing to fire, your thread just dance in the endless loop, and this causes the CPU cycles burning. Better alg. is to have a event, signalled when there is something to fire - then where you set the fire variable to true, you will do SetEvent(hEvt) instead.
in the threadloop you will do something like:
<br />
while( AtlWaitWithMessageLoop(hEvt) )<br />
{<br />
fire_it();<br />
}<br />
this will cause that the thread will be in suspended mode, until the event is not set, or some message arrived.
This will probably introduce some major changes in your app design, but don't worry to ask/look here around. I guess it is described ot this site somewhere how to avoid such a things. Anyway, look carefuly on the event flags (CreateEvent), the bManualReset flag will be important for you to set correctly probably to FALSE, depends on design... But this is out of scope of this thread
Hope this helps
|
|
|
|
|
hi,
Thanx a lot,lot,lot.
I just dont know how to say thanx to u U advice really help me and I really hope I can make u as my guru.
Again thanx a lot.
regards,
Din Krop
|
|
|
|
|
thank you
|
|
|
|
|
Hello,
I'm writing an IE toolbar hosting an activeX control. I used the Class Wizard for getting the interface of the ActiveX : I get 2 classes and they inherit from COleDispatchDriver. One for the methods and the seconds for the events.
I need now to handle the events send by the activeX, and I don't see how to do it.
Has anybody an idea or an example ?
Thanks,
Dezz.
ps : sorry for my poor english.
|
|
|
|
|
Hi,
I have recently moved over atl attributed programming and
created a ActiveX Control which is used in a vb 6
application, but when i call a method, like this:
++++vb code+++++
Private Sub Command1_Click()
Dim a As Long
a = 1
Me.Chh1.test a 'Chh1 is a atl object
End Sub
++++ atl code++++
STDMETHODIMP Chh::test(LONG tt)
,vb say that variable "a" has a type mismath error. This
atl project has used attributed programming in atl wizard.
Then I created another atl project which didn't use
attribute programming, every thing is ok. It's so strange!
How can I correct this problem?
Thanks,
Jeff Xi.
|
|
|
|
|
You could use CSimpleArray.
|
|
|
|
|
I would like to know how to implement a schedule in VC. I am familiar Java than VC. In Java I did use Timer and Thread. But in VC, I dont know.
Please drop to me some line if you know!
Thanks
|
|
|
|
|
What sort of schedule ? Windows works on a message pump, the timer message is WM_TIMER. www.msdn.microsoft.com is the online help that will tell you all you need to know about it.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Maybe, if it will fit into your needs, you can use integrated scheduler installed in windows. Good starting point for this is ITaskScheduler, you should probably find it in index of MSDN. There is a whole documentation, so you can examine it.
|
|
|
|
|
I've been developing a shell extension to 'touch' files -- following from Chris M's recent post. Anyway, it builds fine as a debug project. If I then try to build it in any of the release configurations (MinSize etc.) it comes back with two errors:
error LNK2019: unresolved external symbol _main referenced in function _mainCRTStartup
fatal error LNK1120: 1 unresolved externals
I'm feeling like such a dumbass! Any suggestions would be very much appreciated
--
Paul
"If you can keep your head when all around you have lost theirs, then you probably haven't understood the seriousness of the situation."
- David Brent, from "The Office"
MS Messenger: paul@oobaloo.co.uk
Sonork: 100.22446
|
|
|
|
|
check this out: http://www.codeproject.com/cpp/cppforumfaq.asp#cl_errormain
"Now I guess I'll sit back and watch people misinterpret what I just said......"
Christian Graus At The Soapbox
[^]
|
|
|
|
|
Thanks very much.
--
Paul
"If you can keep your head when all around you have lost theirs, then you probably haven't understood the seriousness of the situation."
- David Brent, from "The Office"
MS Messenger: paul@oobaloo.co.uk
Sonork: 100.22446
|
|
|
|
|
Hi All,
Hope every one is fine out there. I have a problem using STL queue. May be so,e of your have a solution for it. I am using Stl queue with customized struct element as it member, when I push element on queue it increases memeory in Task manager, but when it pops the element it did't seems to release memory. Why is this so ? . Do i need to implement my own meeory releasing schemes. or whats the solution for it ??
Regards
Rizi
|
|
|
|
|
Rizi wrote:
Why is this so ? . Do i need to implement my own meeory releasing schemes. or whats the solution for it ??
The STL itself handles the destruction of its processes (that is one of the reasons why it is so nice), I suppose you won't see the memory being released in task manager until the queue itself is destroyed. Otherwise the overhead on the task manager may go to an extreme and I think you would see performance degredation across the OS, (possibly?).
Nick Parker
May your glass be ever full.
May the roof over your head be always strong.
And may you be in heaven half an hour before the devil knows you’re dead. - Irish Blessing
|
|
|
|
|
I answered this last night - where did it go ?
Anyhow, you can't pass just anything via COM, but I believe you can pass an IUnknown * or IDispatch *.
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Hehe, it's here[^]
We all love crossposts, don't we?
|
|
|
|
|
Well, at least it's on topic in both.....
Christian
No offense, but I don't really want to encourage the creation of another VB developer. - Larry Antram 22 Oct 2002
Hey, at least Logo had, at it's inception, a mechanical turtle. VB has always lacked even that... - Shog9 04-09-2002
Again, you can screw up a C/C++ program just as easily as a VB program. OK, maybe not as easily, but it's certainly doable. - Jamie Nordmeyer - 15-Nov-2002
|
|
|
|
|
Sorry ,never again.
Scratch
|
|
|
|
|