ques for Saturn/author if this c++ sendmirc code - 08/06/06 11:33 AM
Code:
void sendmirc(HWND hwnd, const char *data) { HANDLE hmap, hmutex; char *ptr; // create the filemapping object if ((hmap = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, 1024, "mIRC")) == NULL) return; // at this point we SHOULD check GetLastError() to see if it's set to // ERROR_ALREADY_EXISTS; that's how mIRC prescribes that it must be done, // and if all DLL coders did this, we would not need a mutex at all. // map the shared memory onto our address space if ((ptr = (char *)MapViewOfFile(hmap, FILE_MAP_ALL_ACCESS, 0, 0, 0)) == NULL) { CloseHandle(hmap); return; } // the creation and mapping of the virtual file done so far, can not lead to // synchronization problems on itself; we only need to protect actual access // so, create or open a mutex that will protect the shared memory access if ((hmutex = CreateMutex(NULL, FALSE, "mIRC_SendMessage")) != NULL) { // wait for this mutex to be released - if it is currently locked, wait! WaitForSingleObject(hmutex, INFINITE); // now that we hold the mutex, we can access the shared memory safely lstrcpyn(ptr, data, 4096); // and tell mIRC to execute our command SendMessage(hwnd, WM_USER + 200, 0, NULL); // release and destroy the mutex ReleaseMutex(hmutex); CloseHandle(hmutex); } // unmap and close the filemapping UnmapViewOfFile(ptr); CloseHandle(hmap); }
I changed the 1024 to 4096 for it to hold more data in ptr
problem im having is im making the c++ open like 20/30 sockets and im getting information of these sockets and sending them to mIRC, sometimes it sends me back the full 30 results (in the form of echos), and sometimes it doesnt echo anything
im thinking that sometimes it doesnt echo anything, is this to do with the mutex to the mapped file? i thought the mutex would be released upon a certain amount of time - milisecs?
ive been using this function for a while now and thats my only problem, when i open the sockets (by calling a mirc alias which runs a dll function) it echos me results, then when i run the alias again, for e.g., 2 secs later, it wont echo anything