|
|
Comments and Discussions
|
|
 |

|
I was doing the same as Step 1 in an app of mine, but I then realized that it doesn't work when the window is hidden using:
RemoveTaskbarIcon(pWnd);
pWnd->ModifyStyle(WS_VISIBLE, 0);
Do you know any simple way around this?
I thought of using ::PostThreadMessage(), but it doesn't seem to work either (I post the message and no-one seems to get it).
I don't know if I'm doing sth wrong...
UINT m_WinMsg_ui = ::RegisterWindowMessage(_T("MY_MESSAGE_BLAH_BLAH"));
SendMessageToAppByName(_T("AppFileName.exe"));
or
::SendMessage(HWND_BROADCAST, m_WinMsg_ui, GetCurrentProcessId(), 0);
DWORD GetProcessMainThreadId(DWORD ProcessID)
{
shared_ptr<void> hThreadSnapshot(CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, 0), CloseHandle);
if (hThreadSnapshot.get() == INVALID_HANDLE_VALUE)
{
throw std::runtime_error("GetMainThreadId failed");
}
THREADENTRY32 tEntry;
tEntry.dwSize = sizeof(THREADENTRY32);
DWORD result = 0;
for (BOOL success = Thread32First(hThreadSnapshot.get(), &tEntry);
!result && success && GetLastError() != ERROR_NO_MORE_FILES;
success = Thread32Next(hThreadSnapshot.get(), &tEntry))
{
if (tEntry.th32OwnerProcessID == ProcessID)
{
result = tEntry.th32ThreadID;
}
}
return result;
}
bool CMyApp::SendMessageToAppByName(LPCTSTR AppFileName)
{
PROCESSENTRY32 entry;
entry.dwSize = sizeof(PROCESSENTRY32);
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
if (Process32First(snapshot, &entry) == TRUE)
{
while (Process32Next(snapshot, &entry) == TRUE)
{
if (_wcsicmp(entry.szExeFile, AppFileName) == 0)
{
DWORD ThreadID = GetProcessMainThreadId(entry.th32ProcessID);
::PostThreadMessage(ThreadID, m_WinMsg_ui, GetCurrentProcessId(), 0);
}
}
}
CloseHandle(snapshot);
return false;
}
kostas KEL
modified 6-Apr-13 7:52am.
|
|
|
|

|
I say i can commute between two dialog in an application. Or two form in TabControl.
If every one have sample about commute between two form (difference class) of TabControl. Please tell me. Thank so much
Bùi Đình Bá - Mechatronic Engineer
-------------------------------------------------------------
|
|
|
|

|
Is it possible to send a function(-pointers) over IPC to a hook dll, which executes the function when the hook is called (the function pointer is in the main exe and needs information from the main exe)?
|
|
|
|

|
Hi Alex, Thanks for your great paper. I learned a lot from it. I was trying to use mutex between different processes (they need to use shared memory) in my project, i found that when process1 and process2 use different mutex name when calling m_hMutex = CreateMutex( NULL, FALSE, sxMutex); they can still communicate with each other. For this i am not sure if they are really locking the shared memory. I tried your example in "step 3", and set sxMutex as one value compiled and built SameText1.exe, then set sxMutex as ANOTHER value compiled and built SameText2.exe. When i run SameText1 and SameText2, sames they also get the same results as building them with the same mutex name. Could you please tell me why or where i am wrong? Many Thanks! Vic Thanks! vic
|
|
|
|

|
Can I use a similar method to perform the following?
Application launches, and detects that the nessessary thread is not running in memory, and launches it.
New child thread configures itself and stays memory resident.
Once the new child is spawned, attach to it using events/properties to connumicate with it (like most multithreaded applications would)
Now the tricky part, start a differant application and connect to the same instance of the child thread started by the first application and listen to the same events occuring and such??
-CS
|
|
|
|

|
Hi there !
This is a really good example on this topic. I have tested out the demo, and it seems to be working nice. The only thing is that I think that the MS guys could have implemented more standard ways of IPC in their new framework. It seems like the good old stuff must be used to gain speed.
However, I have to ensure that the readers get all the data from the writers. So a synchronization mechanism must be implemented. The windowsmessage only tells the readers that new data is arrived. The readers can not say when they have received the data. I implemented two counters, one number of subscribers, and a counter for how many that are finished reading. This seems to be working, but is a little bit tricky when readers dies ( if it is possible that a windows app do so
Do you have any suggestion on how to implement such a synchronization mechanism on top of this good framework ?
Tore
|
|
|
|

|
First i would like to say this is an excellent article. It has certainly helped me.
I would like to ask if I may use your CIPCReadWriteLock class in the source code to an article I am writing for CP. I must point out that I have modified the code and merged it into my own class, though I have given you the credit in the source code and the article.
I would also like to ask if there are any commercial restrictions placed on using this class?
Regards
|
|
|
|

|
The class seems like giving me problem in new compiler.(above VC6)
Like will crash in the destructor.
To solve this, I just set HANDLE member variables as NULL in the constructor.
CIPCReadWriteLock::CIPCReadWriteLock(
LPCTSTR sName, // [in] name
DWORD dwMilliseconds) // [in] maximum number of milliseconds to wait
// or INFINITE
{
// Generate names for mutex and semaphores.
// Names start from sName string and finish with
// _Mutex, _SemRd and _SemWr.
// If number of instances of this class are created
// in the same process with the same name (also NULL),
// they will guard the same resource.
int n = 0;
if ( sName )
n = lstrlen(sName);
n += c_nLen + 1;
m_sMutexName = new TCHAR[n];
m_sSemReadersName = new TCHAR[n];
m_sSemWritersName = new TCHAR[n];
m_sMemFileName = new TCHAR[n];
*m_sMutexName = *m_sSemReadersName = *m_sSemWritersName = 0;
if ( sName )
{
lstrcpy(m_sMutexName, sName);
lstrcpy(m_sSemReadersName, sName);
lstrcpy(m_sSemWritersName, sName);
lstrcpy(m_sMemFileName, sName);
}
lstrcat(m_sMutexName, c_sMutexName);
lstrcat(m_sSemReadersName, c_sSemReader);
lstrcat(m_sSemWritersName, c_sSemWriter);
lstrcat(m_sMemFileName, c_sMemFile);
// keep time interval
m_dwMilliseconds = dwMilliseconds;
//////////////////////////////////////////////////////////////////////////
//NULLify all
m_hMutex = NULL;
m_hsemReaders = NULL;
m_hsemWriters = NULL;
m_hFileMapping = NULL;
//////////////////////////////////////////////////////////////////////////
m_bInitSucceded = InitSyncObjects();
}
Sonork 100.41263:Anthony_Yio
|
|
|
|

|
Here is the example. You have 2 processes. The first process calls WaitForWrite(), and let's say it has a lot to write. The second process calls WaitForWrite() also and waits for the first process to finish. BUT, all of a sudden the first process crashes! Thus, the second process will never wake up, because someone (the first process) has to call the function Done().
The solution here is to wait for mutex (instead of semaphore) until it returns WAIT_OBJECT_0 or WAIT_ABANDONED (btw, the provided code does not process this return for the mutex that can happen one day).
Dima.
|
|
|
|

|
Hello,
I have the next problem : I'm writing IE toolbar with ATL Com Wizard (non MFC application). So I have a dll with the toolbar which is used from IE.I have a button on the toolbar which state can be connected/not connected (this is determined by the user). It is possible more than one IE be opened at the same time. I want when user changes state of the button, the change be invalidated in all other opened explorer's tollbars. That's why I need a mechanism similar to this here, but it doesn't work in an ATL project.Can anyone tell me why?
Thanks very much
|
|
|
|

|
I have done a wh_getmessage hook
and in that i got wparam character message
say wparam= 'c'
{
Then i have to post another character using PostMessage
PostMessage(msg->hwnd,WM_CHAR, dwPrevChar, 1);
msg->hwnd is the handle of the active window AND dwPrevChar is the character which i am sending
}
Let us assume
dwPrevChar='r' then i got the r printed on the active applications
but these are my problems
in notepad i got cr
in wordpad i got crr
in winword i got crrr
in photoshop i got crr
i couldnt figure out why is this happening
Please help me if there is somebody who know why is this problem occurs.
Thanks in advance
vimal
|
|
|
|

|
i think // Ensure exclusive access to the member variables WaitForSingleObject(m_hMutex, m_dwMilliseconds) can return timeout... and you will not change intrinsic variables ie writer allways think, what reader still reading ) and can not get access to memory use WaitForSingleObject(m_hMutex, INFINITE) in Done
|
|
|
|

|
Folks,
Just wondering if any one of you help me in a particular problem. I have 2 programs, one a VC++ program that generates numbers (coordinates) at the rate of 50 per second, and the second, a flash program that reads in these coordinates 50 times a second and displays a 3D graph accordingly. My question is, how do I make the 2 programs communicate? One obivious solution would be to keep writing to a file and have the flash prog read from this file (Actually, the flash program needs input in the form of a file). In this case, how do I synchronise the 2 programs. And, are there any other alternatives?
In the initial phase of development, we do not have the flash program ready, to test the system. So, we'll have to test the coordinate generator with a stub program which just reads and displays the values generated by the first vc++ program.
The intended flow is like:
(VC++ prog generating cordinates) ---> (medium for inter-program communication) ---> (a stub program that just reads/displays these values, to be replaced later by the flash prog as soon as it is ready).
Here, the middle part "medium for inter program communication" is the part we are not too sure about. If we use an ascii file into which the coordinates are written into/read from, how do we synchronise it so that the read happens only after the write. Can a Windows equivalent of Unix semaphores be implemented.
Thanks,
Hans
|
|
|
|

|
good,
but can i send a pointer to a string between application?
application A:
HWND hAppWnd; // handle of other application
...
UINT myMsg = RegisterWindowMessage( "xyz" );
...
bRet = SendMessage( hAppWnd,myMsg,strlen( sParam ),(LPARAM)sParam );
...
application B
void myFunction( WPARAM wLen,LPARAM lMessage ) {
char *sParam;
sParam = (char *)malloc(wLen,sizeof( char ) );
sprintf( sParam,"%s",(LPSTR)lMessage ); // Error
}
sParam and lMessage have the same address.
where is the problem? i have read the some function cannot send a pointer. ok. but WM_SETTEXT how it works?
|
|
|
|

|
I know it sound stupid...
Can we used the same method between the exe and dll files...
:_Rocket_:
|
|
|
|

|
Does anyone know of a class that does read-write guarding like CIPCReadWriteLock but uses Critical Sections rather than Mutexes and Semaphores? I have an in-process resource that could benefit from the read-write guarding, but because its not inter-process the performance would be better if only Critical Sections were used....
|
|
|
|

|
I have hidden one part of my program with the same technique as discussed here. And this part is not receiving HWND_BROADCAST messages. Anyone have an idea how to resolve this?
--
David
|
|
|
|
|

|
Hi!
I absolutely agree, it's well done. But for me personally it would be very interesting and useful, if you could add the consideration of the IPC in the context of WorkStation concept. In other words, how may be established connection between services, running (by default) each one in it's own WorkStation. AFAIK all global objects (mutexes, atoms, etc.) are "global" in the scope of workstation.
Thanks.
Regards,
Gennady
|
|
|
|
|

|
It only talks about may be 1 in 1000000 possible ways of doing interprocess communication.
|
|
|
|
 |
|
|
General News Suggestion Question Bug Answer Joke Rant Admin
|
Using memory mapped files, mutexes and HWND_BROADCAST messages for interprocess communication
| Type | Article |
| Licence | CPOL |
| First Posted | 1 Oct 2001 |
| Views | 239,628 |
| Bookmarked | 116 times |
|
|