|
Get out your classic Petzold 'Programming Windows' (you do have one don't you?) - it's in there. If you want an online sample, there is one here on CP: http://www.codeproject.com/useritems/Brainchild.asp. It's probably quite complex for a starter, though.
|
|
|
|
|
You could check out http://www.relisoft.com[^] which contains some useful articles about this stuff.
Wenn ist das Nunstück git und Slotermeyer? Ja! Beierhund das oder die Flipperwaldt gersput!
|
|
|
|
|
hi,
I've developed one ATL EXE server com. This server contains 2 threads.
The main thread (lets call it T1) will do following tasks:
1. Create second thread ( and this I think should be called T2) using "CoMarshalInterThreadInterfaceInStream".
2. Receive input from client application:
HRESULT CMainThread::ReceiveClientInput(BSTR AnyValue)<br />
{<br />
<br />
EnterCriticalSection(&cs); <br />
m_isFire = true;<br />
LeaveCriticalSection(&cs);<br />
<br />
return S_OK;<br />
}
T2 on the other hand continously (every 2 seconds) check for m_isFire value and fire the event:
void CSecondThread::CheckFlag(void)<br />
{<br />
<br />
EnterCriticalSection(&cs); <br />
<br />
if (isFire == true ){<br />
Fire_NotifyAllConnectedClients();<br />
isFire = false;<br />
}<br />
<br />
LeaveCriticalSection(&cs);<br />
<br />
}
Now, when event fired from above COM method, there is no client receive this event
I guess I've missed something in my code since I'm quite new in using VC++.
Thank u very very much in advance . Any advice, help and suggestions strongly aprreciated.
Regards,
newbie
|
|
|
|
|
Never ever use a shared variable for this. Create a named event and use WaitForObject() and SetEvent/ResetEvent or PulseEvent to set or clear that event.
But your bug, I believe lies inside the Fire_NotifyAllConnectedClients() function. Have a look there.
I don't think this is a serious possesion, and the evil most likely comes from your hand. Colin J Davies, The Lounge
|
|
|
|
|
It might be preferable to use unnamed synchronization objects if they
are only for use within the same process. That way you don't have to
think about naming issues or access by another application.
|
|
|
|
|
Thanks for the reply.
Actually I want to use that variable. Below is my real source code:
struct ScheduledDevice<br />
{<br />
CComBSTR RefID;<br />
CComBSTR Name;<br />
DATE StartTime;<br />
DATE EndTime;<br />
int Status;<br />
long Command;<br />
};<br />
<br />
typedef map<BSTR, ScheduledDevice> SCHEDULELIST;<br />
SCHEDULELIST m_Schedule;<br />
SCHEDULELIST m_SendToOPC;
At main thread I receive input from client:
HRESULT CMonitorDeviceThread::Add(BSTR DeviceName, DATE StartTime, DATE EndsTime, BSTR RefID)<br />
{<br />
ScheduledDevice obj;<br />
<br />
obj.Name = DeviceName;<br />
obj.StartTime = StartTime;<br />
obj.EndTime = EndsTime;<br />
obj.RefID = RefID;<br />
obj.Status = bookOpenStatus;<br />
<br />
EnterCriticalSection(&cs); <br />
m_Schedule[obj.RefID] = obj;<br />
LeaveCriticalSection(&cs);<br />
<br />
return S_OK;<br />
}
And at second thread the code will continously check and intiate the event:
while ( m_IsRun == TRUE )<br />
{<br />
<big>Command();</big><br />
Sleep(10000);
}<br />
<br />
void CMonitorDeviceThread::Command(void)<br />
{<br />
ScheduledDevice obj, OPCDev;<br />
SCHEDULELIST::iterator m_Iterator;<br />
bool IsErase = false;<br />
<br />
EnterCriticalSection(&cs);<br />
<br />
m_SendToOPC.clear();<br />
<br />
for ( m_Iterator = m_Schedule.begin(); m_Iterator != m_Schedule.end(); )<br />
{ <br />
<br />
SYSTEMTIME dtStartTime, dtEndTime, stCurDate;<br />
<br />
VariantTimeToSystemTime( (*m_Iterator).second.StartTime, &dtStartTime );<br />
VariantTimeToSystemTime( (*m_Iterator).second.EndTime, &dtEndTime );<br />
GetLocalTime(&stCurDate);<br />
<br />
CHighTime bookStartTime( dtStartTime ); <br />
CHighTime bookEndTime( dtEndTime ); <br />
CHighTime curTime( stCurDate ); <br />
<br />
CHighTimeSpan sDiffStartTime = bookStartTime - curTime;<br />
CHighTimeSpan sDiffEndTime = bookEndTime - curTime;<br />
<br />
long diffStart = sDiffStartTime.GetTotalMinutes(); <br />
long diffEnd = sDiffEndTime.GetTotalMinutes(); <br />
<br />
if ( ( diffStart == 0 || ( diffStart >= -5 && diffStart <= -1 ) ) && (*m_Iterator).second.Status == bookOpenStatus ) {<br />
<br />
OPCDev = (*m_Iterator).second;<br />
OPCDev.Command = 1;<br />
m_SendToOPC[OPCDev.RefID] = OPCDev;<br />
<br />
(*m_Iterator).second.Status = bookExecuteStatus;<br />
<br />
}<br />
<br />
<br />
if ( ( diffEnd == 0 || ( diffEnd >= -10 && diffEnd <= -1 ) ) && (*m_Iterator).second.Status == bookExecuteStatus ) {<br />
<br />
OPCDev = (*m_Iterator).second; <br />
OPCDev.Command = 0;<br />
m_SendToOPC[OPCDev.RefID] = OPCDev;<br />
<br />
(*m_Iterator).second.Status = bookCloseStatus;<br />
<br />
} else if ( diffEnd <= -11 ){<br />
<br />
m_Iterator=m_Schedule.erase(m_Iterator);<br />
IsErase = true;
}<br />
<br />
if ( !IsErase ){<br />
++m_Iterator;<br />
IsErase = false;<br />
}<br />
<br />
<br />
}
<br />
LeaveCriticalSection(&cs);<br />
<br />
<big>ProcessEvent();</big><br />
}<br />
<br />
void CMonitorDeviceThread::ProcessEvent()<br />
{<br />
<br />
if (m_SendToOPC.size() > 0 ) {<br />
<br />
long recCount = m_SendToOPC.size();<br />
long i=0;<br />
SAFEARRAYBOUND bounds = {recCount, 0};<br />
<br />
VARIANT pItems;<br />
VariantInit(&pItems);<br />
pItems.vt = VT_ARRAY | VT_BSTR | VT_BYREF;<br />
<br />
VARIANT pCommands;<br />
VariantInit(&pCommands);<br />
pCommands.vt = VT_ARRAY | VT_I4 | VT_BYREF;<br />
<br />
SAFEARRAY* psaItems = NULL;<br />
BSTR *strItems;<br />
psaItems = SafeArrayCreate(VT_BSTR, 1, &bounds);<br />
<br />
SAFEARRAY* psaCommands = NULL;<br />
long *lngCommands;<br />
psaCommands = SafeArrayCreate(VT_I4, 1, &bounds);<br />
<br />
SafeArrayAccessData(psaItems, (void**)&strItems);<br />
SafeArrayAccessData(psaCommands, (void**)&lngCommands);<br />
<br />
for ( m_OPCIterator = m_SendToOPC.begin(); m_OPCIterator != m_SendToOPC.end(); m_OPCIterator++)<br />
{<br />
strItems[i] = (*m_OPCIterator).second.Name;<br />
lngCommands[i] = (*m_OPCIterator).second.Command;<br />
i++;<br />
}<br />
<br />
SafeArrayUnaccessData(psaItems);<br />
SafeArrayUnaccessData(psaCommands);<br />
<br />
pItems.pparray = &psaItems;<br />
pCommands.pparray = &psaCommands;<br />
<br />
<big>Fire_NotifyAllConnectedClients(pItems, pCommands, i);</big><br />
<br />
SafeArrayDestroy(psaItems);<br />
SafeArrayDestroy(psaCommands);<br />
<br />
}<br />
<br />
}
Here is ATL wizard generated CP event file :
VOID Fire_NotifyAllConnectedClients(VARIANT Items, VARIANT Command, LONG saje)<br />
{<br />
T* pT = static_cast<T*>(this);<br />
int nConnectionIndex;<br />
CComVariant* pvars = new CComVariant[3];<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[2] = Items;<br />
pvars[1] = Command;<br />
pvars[0] = saje;<br />
DISPPARAMS disp = { pvars, NULL, 3, 0 };<br />
pDispatch->Invoke(0x1, IID_NULL, LOCALE_USER_DEFAULT, DISPATCH_METHOD, &disp, NULL, NULL, NULL);<br />
}<br />
}<br />
delete[] pvars;<br />
<br />
}
Again thank a lot
Regards,
Newbie
|
|
|
|
|
hi,
I've figured out what is the problem is.
When I assign value for variable at main thread, its not available at second thread: Below is the code example where I set the obj at main thread:
<br />
ScheduledDevice obj;
<br />
HRESULT CMonitorDeviceThread::Add(BSTR DeviceName, DATE StartTime, DATE EndsTime, BSTR RefID)<br />
{<br />
ScheduledDevice obj;<br />
<br />
EnterCriticalSection(&cs); <br />
obj.Name = DeviceName;<br />
obj.StartTime = StartTime<br />
obj.EndTime = EndsTime;<br />
obj.RefID = RefID;<br />
<big>obj.Status = 1;</big><br />
LeaveCriticalSection(&cs);<br />
<br />
return S_OK;<br />
}<br />
Below is the code where I refer back to the obj value at second thread for further processing:
<br />
HRESULT CMonitorDeviceThread::Execute()<br />
{<br />
EnterCriticalSection(&cs);<br />
if ( <big>obj.Status == 1</big> ){<br />
<br />
Fire_NotifyAllConnectedClients(Name, Status, ......);<br />
<big>obj.Status = 2;</big><br />
<br />
}<br />
LeaveCriticalSection(&cs);<br />
}<br />
For ur info I've try to declare obj as a static variable and manage to fire event to MFC clients:
<br />
static ScheduledDevice obj;<br />
But when I do simulation testing, after few times its cannot triggered event to clients anymore. It's back to original problem.
Does anybody knows what is the problem actually is ??
Thanx in advance.
Regards,
newbie.
|
|
|
|
|
Does somebody know, when the public DX9 SDK will be released?
Daniel Balas - Student
|
|
|
|
|
I believe that I read Feburary, but I do not know where I read this from.
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
It has been released today... http://msdn.microsoft.com/directx...
Note it you are using VS.Net 2003 Beta then you will need to edit manually install the AppWizards and also edit the vsz files and add .7.1 to VsWizard.VsWizardEngine before the Wizards will work correctly.
Chris
|
|
|
|
|
I am in search of ADO wrapper class in C++ without using MFC. I want to use it in console app. The class should support ADO operations like connection to Data Base source, query execution and execution of stored procedures.
If you know about any such wrapper class/framework then please let me know...
Thanks
|
|
|
|
|
Do you really need a wrapper class. I find that
#import "C:\Program Files\Common Files\System\ADO\msado15.dll"
generates all the wrapper I need for most database stuff.
Michael
Fat bottomed girls
You make the rockin' world go round -- Queen
|
|
|
|
|
Hi, this was an assignment for this year but I never had a chance to do it. I am beginner on c++ abd dont know were to start can anyone give me an idea how I am gone to start for this problem below.
Thank you all even if you at least read this problem.
-------------------------------------------------------------------
The lifelong insurance company offers policies at low premium because it insures only applicants who smoke fewer then 10 cigarettes a day and weigh under 80 kilograms input for each applicant consist of number of cigarettes smoked daily and the weight.
1) Use several functions when writhing a program to process an unknown number of applicants.
2) The output should have each applicant’s number of cigarettes smoked daily, the weight and message ACCEPTED and RECEIVED if the applicant has been rejected, the reason’s should also be output.
3) The program should also output the average number of cigarettes smoked daily and the average weight for the applicants who have been accepted.
4) Data validation is required to test for values of less then zero for the number of cigarettes and the weight.
Tahnk you all for your help
|
|
|
|
|
What have you already done ? What's your first idea about the whole thing ? We will surely bring you on the right way if and only if YOU code and WE correct what you have already done.
~RaGE();
|
|
|
|
|
I need to virus scan a file before uploading it, just like Hotmail or Yahoo does it. How do I go about doing it? Any help would be appreciated.
Thanks
|
|
|
|
|
Get a virus scanner that exposes an API for programmatically controlling it, read docs for API, implement. Easy as that
|
|
|
|
|
Hallo!
For a TreeViewCtrl I need a drag & drop Function, Source or other, which reacts on displacing a folder....
Thank you for help...
|
|
|
|
|
Hi!
I'm working on a CFormView derived class, and i had the need of creating a ownerdraw button.
In the .h file i wrote : CMyButton botao;
...and then, in the .cpp i created like this:
~
botao.Create("Back", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT|BS_OWNERDRAW, CRect(10, m_iLastY+70, 150, m_iLastY+100), this, BTN);
The first time i call that form, no problem it works, but the next time i call it i get an debug assertation error!
In Debug i can see that the hwnd of botao is 0x00000000
and the next time i stop in the line in which i'm creating it i have a
value there.
How can i make botao's hwnd equal to 0x00000000 again?
Thank you
Rui
|
|
|
|
|
Ruca wrote:
In Debug i can see that the hwnd of botao is 0x00000000
and the next time i stop in the line in which i'm creating it i have a
value there.
Sure, because once you successfully create your button, it is assigned a handle, namely the hwnd .
Ruca wrote:
How can i make botao's hwnd equal to 0x00000000 again?
You'll have to destroy your button before recreating it. For that,it may be helpful to run botao.Detach() in such a way :
if (botao.m_hwnd!=NULL)
botao.Detach();
else
botao.Create("Back", WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_FLAT|BS_OWNERDRAW, CRect(10, m_iLastY+70, 150, m_iLastY+100), this, BTN);
Well, that's what i would try. BUT I'm not very qualified, so it can be that this is all wrong.
~RaGE();
|
|
|
|
|
Thank you very much Rage, i tried it, but even with .Deatch()
(i also tryed botao.m_hwnd==NULL) , i get an error when executing, and now i'sure the m_hWnd is 0x000000, is there any other variable i should worry about?.
Thank you
Rui
|
|
|
|
|
I have a toolbar derived from CToolBar consisting of several buttons. I created the toolbar using Insert->Resource->Toolbar but did not add any contents to the different buttons. I now want to add centered text to the different buffers (whose size and position changes when the main window changes) in run-time. Of course I have tried CToolBar.SetButtonText() but it just doesn't work. I have seen other people do the same thing, but my application doesn't work.... What am I doing wrong?
Christoffer Andreas Andersen
"I'm just here to regulate the funkyness!" - Gandolfini
|
|
|
|
|
Hi, how can I avoid that a scrollbar inside my listbox vanishes?
I created a listbox with styles LBS_DISABLENOSCROLL | WS_VSCROLL . But when I resize the listbox so small that the scrollbar is the only visible part, the scrollbar disappears. Thanks for help.
|
|
|
|
|
How can I extract an Icon in C++ from an .exe file?
Do anyone have an Samplecode?
|
|
|
|
|
::ExtractIcon()
Read MSDN Library for more information. It's the best way to learn if you look up things by your own!
Rickard Andersson@Suza Computing
C# and C++ programmer from SWEDEN!
UIN: 50302279
E-Mail: nikado@pc.nu
Speciality: I love C#, ASP.NET and C++!
|
|
|
|
|