int SendFilesToOldTiMidity(int nfiles, char **files) { int i; HANDLE hmailslot; char buffer[1024]; int size; hmailslot = OpenMailslot(); if(hmailslot==NULL) return FALSE; strcpy(buffer,MC_HEADER); size = strlen(buffer); WriteMailslot(hmailslot,buffer,size); strcpy(buffer,MC_FILES); size = strlen(buffer); WriteMailslot(hmailslot,buffer,size); sprintf(buffer,"%d",nfiles); size = strlen(buffer); WriteMailslot(hmailslot,buffer,size); for(i=0;i<nfiles;i++){ char filepath[1024]; char *p; // if(url_check_type(files[i])==-1 && GetFullPathName(files[i],1000,filepath,&p)!=0){ if(isURLFile(files[i])==FALSE && GetFullPathName(files[i],1000,filepath,&p)!=0){ size = strlen(filepath); WriteMailslot(hmailslot,filepath,size); } else { size = strlen(files[i]); WriteMailslot(hmailslot,files[i],size); } } CloseMailslot(hmailslot); return TRUE; }
int _tmain(int argc, _TCHAR* argv[]) { ///////////////////////////////////////////////////////////////////////// // Open the mailslot. // // Prepare the slot name CString strMailslotName; strMailslotName.Format(_T("\\\\%s\\mailslot\\%s"), _T("."), // Server name _T("HelloWorld") // Pipe name ); HANDLE hFile = CreateFile( strMailslotName, // The name of the mailslot GENERIC_WRITE, // Write access (Mailslot is a mechanism // for one-way IPC. The client is just // responsible for writing to the slot) FILE_SHARE_READ, // Share mode NULL, // Default security attributes OPEN_EXISTING, // Opens existing mailslot FILE_ATTRIBUTE_NORMAL, // The file has no other attributes set NULL); // No template file if (hFile == INVALID_HANDLE_VALUE) { _tprintf(_T("Unable to open mailslot %s w/err 0x%08lx\n"), strMailslotName, GetLastError()); return 1; } ///////////////////////////////////////////////////////////////////////// // Write messages to the mailslot. // WriteMailslot(hFile, _T("Message 1 for mailslot")); WriteMailslot(hFile, _T("Message 2 for mailslot")); Sleep(3000); // Sleep 3 seconds WriteMailslot(hFile, _T("Message 3 for mailslot")); ///////////////////////////////////////////////////////////////////////// // Close the slot. // CloseHandle(hFile); return 0; }
int wmain(int argc, wchar_t *argv[]) { // The name of the mailslot. It is in the form of \\.\mailslot\[path]name // The name field must be unique. The name may include multiple levels of // pseudo directories separated by backslashes. For example, both // \\.\mailslot\mailslot_name and \\.\mailslot\abc\def\ghi are valid. const PCWSTR MAILSLOT_NAME = L"\\\\.\\mailslot\\SampleMailslot"; HANDLE hMailslot = INVALID_HANDLE_VALUE; DWORD dwError = ERROR_SUCCESS; // Open the mailslot with write access (Mailslot is a mechanism for one- // way IPC. The client is just responsible for writing to the mailslot.) hMailslot = CreateFile( MAILSLOT_NAME, // The name of the mailslot GENERIC_WRITE, // Write access FILE_SHARE_READ, // Share mode NULL, // Default security attributes OPEN_EXISTING, // Opens existing mailslot FILE_ATTRIBUTE_NORMAL, // The file has no other attributes set NULL // No template file ); if (hMailslot == INVALID_HANDLE_VALUE) { dwError = GetLastError(); wprintf(L"Unable to open mailslot w/err 0x%08lx\n", dwError); goto Cleanup; } wprintf(L"The mailslot (%s) is opened.\n", MAILSLOT_NAME); // Write messages to the mailslot. WriteMailslot(hMailslot, L"Message 1 for mailslot"); WriteMailslot(hMailslot, L"Message 2 for mailslot"); Sleep(3000); // Sleep for 3 seconds for the demo purpose WriteMailslot(hMailslot, L"Message 3 for mailslot"); Cleanup: // Centralized cleanup for all allocated resources. if (hMailslot != INVALID_HANDLE_VALUE) { CloseHandle(hMailslot); hMailslot = INVALID_HANDLE_VALUE; } return dwError; }
int SendCommandNoParamOldTiMidity(char *command) { HANDLE hmailslot; char buffer[1024]; int size; hmailslot = OpenMailslot(); if(hmailslot==NULL) return FALSE; strcpy(buffer,MC_HEADER); size = strlen(buffer); WriteMailslot(hmailslot,buffer,size); strcpy(buffer,command); size = strlen(buffer); WriteMailslot(hmailslot,buffer,size); strcpy(buffer,"0"); size = strlen(buffer); WriteMailslot(hmailslot,buffer,size); CloseMailslot(hmailslot); return TRUE; }