|
Go to your project settings. Select "Use MFC in a static library". Rebuild all. Your exe will be bigger, but you won't need to include the mfc dll's.
-----------------------
New and improved: kwakkelflap.com
My first CP article: Pseudoregisters[^]
"When I hear of Schrödinger's cat, I reach for my gun." - Stephen Hawking
|
|
|
|
|
Hello,
INTRODUCTION:
I create Numerical Controls with a specially desgined soft in order to do that.
This soft has a special function that I can call in order to know the value of the variable passed as a parameter.
I can create a timer in order to check continuously the value of it's variable but I think that this is not a very effective way to do it...
QUESTION:
Can I create an event (CreateEvent(...)) that look for the change of that variable and then wait for that change (WaitForSingleObject(...))?
I have to do this mechanism for 40 variables (more or less) but I have no clue of where to begin, which do you think that can be the best solution?
As always thank you in advance.
|
|
|
|
|
You can't specifically wait for a change in a value of a variable.
But, if create an event for each variable you want to monitor, you could trigger the event whenever you change the variable. This is very easy to implement if you encapsulate your variable as a protected member of a class, and only access it through accessor methods. here's an example
class CMyData
{
protected:
long m_lMyVar;
public:
long GetMyVar();
void SetMyVar(long lVal);
HANDLE m_hEvent;
CMyData();
}
CMyData::CMyData()
{
m_hEvent = CreateEvent(NULL,TRUE,FALSE,NULL);
long CMyData::GetMyVar()
{
return m_lMyVar;
}
void CMyData::SetMyVar(long lVal)
{
m_lMyVar = lVal;
SetEvent(m_hEvent);
}
.... then later on ....
if (WaitForSingleObject(mydataobj.m_hEvent, INFINITE) == WAIT_OBJECT_0)
{
}
Obviously, your app needs to be multi threaded, becuase if you enter the wait function in a single threaded app when the event is not set, your app will deadlock.
Jon
Signature space for rent. Apply by email to....
|
|
|
|
|
OK,
but I cannot set the value from the external software, I can only check that value from my VC++ app.
This means that I cannot set the event manually...
That software has some callback functions (in a dll) that I can access in order to get information of some kind of variables...
I want to simulate that behaviour:
I need to be able to know when some variables (in the external software) have changed and when this has happened fire an event...
As always thank you in advance...
|
|
|
|
|
Do you really mean callback? If the external softwares provides an API by which it can callback a function in your program, when the var is changed, then you're on to a winner.
But, if it doesn't then you are stuck.
Signature space for rent. Apply by email to....
|
|
|
|
|
Yes, I can do it only with variables with a phisical adress (that external software is intended to control machines and to create PLC and Numerical Control programs) and with those variables I can do it, but they don't allow me to do the same with the logical variables:
the ones that I use in order to process things: operations running, alarms active...
I want to reach those variables without check their state each x ms.
That's all...
And as I've seen that they have that function taht I can access, and program as a callback function in my VC++ app, then I've thought that it must be any other similar way to do the same from the other side:
Not being alerted by their callback and checking those changes in a better way than using a timer...
|
|
|
|
|
So if they are providing a facility whereby you can register a callback function, why don't you use that?
Signature space for rent. Apply by email to....
|
|
|
|
|
Yes, they notify my app only in some types of variables, the ones that are linked to the sensors and actuators of the machine, but the other ones, the ones that interest me are not included in this group.
this is my problem...
and I needed only to know which is the best way to do some checks without consumption of a lot of system resources...
what I've been doing till now is to create a timer in the main dialog, and re-send the WM_TIMER message to each dialog, window... that need to check some variables, in order to use only one timer and not to use a lot of processor...
NOTE:
I need all the processor that I can get because I need to control the machine granting that it will be well controlled...
|
|
|
|
|
this is how I access the callback function...
<br />
lError = AdsSyncAddDeviceNotificationReq(m_pAddr, this->m_iGrupADSTCAT, (iComptador * this->m_iBytesElementADSTCAT) + this->m_iOffsetInicialADSTCAT, &this->m_ArrDadesADSCallback[iComptador].m_adsNotificationAttrib, this->CallbackFX1, this->m_ArrDadesADSCallback[iComptador].m_hUser, &this->m_ArrDadesADSCallback[iComptador].m_hNotification);<br />
and this is the callback function...
<br />
void CMonitor::CallbackFX1(AmsAddr *pAddr, AdsNotificationHeader *pNotification, ULONG hUser)<br />
{<br />
printf("hUser: %.2u >> Contingut: %.10u\n",hUser, *(ULONG *)pNotification->data);<br />
}<br />
|
|
|
|
|
Hi,
Question:
How to Post Message with parameters?
How to use wParam and lParam??
Examples are welcome!!!
Thanks
Extreme programming. Do the No.1
|
|
|
|
|
Depends of the type of the message to post:
u should use PostMessage or SendMessage
an exemple :
MFC:
void CMXAutoDlg::SendStringToWnd ( CWnd * pWnd , CString sString )
{
pWnd->SetForegroundWindow() ;
pWnd->SetFocus();
pWnd->CenterWindow ( ) ;
for ( int iCounter = 0 ; iCounter < sString.GetLength ( ) ; iCounter ++)
{
pWnd->PostMessage ( WM_CHAR, sString [ iCounter ] , 0 );
Sleep ( 100 );
}
}
Non MFC:
PostMessage(hWnd , ...) same params
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
In this case, I use PostThreadMessage, then how to use wParam and lParam?
Extreme programming. Do the No.1
|
|
|
|
|
MSDN:
You can use the PostThreadMessage function to post a message to a specific thread message queue. PostThreadMessage is similar to PostMessage, except the first parameter is a thread identifier rather than a window handle. You can retrieve the thread identifier by calling theGetCurrentThreadId function.
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
After I use wParam & lParam in PostThreadMessage, then I use GetMessage() to accept them, then where can I get the wParam & lParam sent from PostThreadMessage. Appreciation.
Extreme programming. Do the No.1
|
|
|
|
|
BOOL GetMessage(
LPMSG lpMsg,
HWND hWnd,
UINT wMsgFilterMin,
UINT wMsgFilterMax
);
Pass a pointer to a MSG variable to GetMessage()
The MSG Struct has LPARAM and WPARAM members.
Signature space for rent. Apply by email to....
|
|
|
|
|
Still can't work, because of datatype casting.
suppose, I want to send two parameters, one is BYTE* m_pByte, the other, int m_nLen. Then, I use PostThreadMessage Like this,
::PostThreadMessage(m_threadID,WM_DATA_ARRIVAL,(WPARAM)m_pByte,(LPARAM)m_nLen);
Now I use GetMessage() to get the message (here is WM_DATA_ARRIVAL) as well as m_pByte and m_nLen,
<br />
...<br />
MSG msg;<br />
while(::GetMessage(&msg, NULL, 0,0))<br />
{<br />
switch(msg.message)<br />
{<br />
case WM_RXD_ARRIVAL:<br />
AfxMessageBox(msg.lParam);<br />
break;<br />
default:<br />
break;<br />
<br />
};<br />
};<br />
...<br />
and I got the Error MessageBox.
Extreme programming. Do the No.1
|
|
|
|
|
I you cast your datatypes to WPARAM and LPARAM, just cast them back again:-
MSG msg;
while(::GetMessage(&msg, NULL, 0,0))
{
switch(msg.message)
{
case WM_RXD_ARRIVAL:
BYTE* m_pByte = (BYTE *) msg.wParam;
int m_nLen = (int) msg.lParam;
break;
default:
break;
}
}
Thanks
JOn
PS. Have you considered using VB?
Signature space for rent. Apply by email to....
|
|
|
|
|
hi
I want to access a windowsregistry-value. The problem is the value has no name, except for "standard" or "default".
So without a name i can't read the value.
In example :
HKEY_CLASSES_ROOT\http\shell\open\command - the key for the standard-browser.
thanx
|
|
|
|
|
dont send a name for the value u want to read in that case
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
How can I send a e-mail in my mfc application under WinCE?
The ShellExecute function does not exist under WinCE!
I think it works with ShellExecuteEx ?!?
But how to init. the SHELLEXECUTEINFO members ?
Any sample????
|
|
|
|
|
hi,
how to wrap a CALLBACK function into a class?
Thanks in advance.
Extreme programming. Do the No.1
|
|
|
|
|
|
I remember it used #pragmas. I've searched with the above Search box. I've tried Google. I looked in "What's New" all the way back to August. Does anyone know where it is?
Cathy
Life's uncertain, have dessert first!
|
|
|
|
|
#pragma message("this is just how to do it")
You could also take a look at my article about compiler messages[^]
...if you're under 8 or younger. Chris Maunder, the Lounge
|
|
|
|
|
Thanks! That was the article I was looking for.
Cathy
Life's uncertain, have dessert first!
|
|
|
|