Once the queue is created, the server process of the queue and the threads of the server process have immediate access to the queue and can proceed to access the queue. A client process must request access to a queue by calling DosOpenQueue. Once the queue is open, the client process can add an element to the queue with DosWriteQueue, and it can query the number of elements in the queue with DosQueryQueue.
DosOpenQueue retrieves the queue handle and the process identifier of the queue owner. The function also increments the queue's access count.
The following code fragment shows how another process would open the queue created with DosCreateQueue.
#define INCL_DOSQUEUES #include<os2.h> #define HF_STDOUT 1 /* Standard output handle */ HQUEUE hq; PID pidOwner; ULONG ulWritten; APIRET ulrc; ulrc = DosOpenQueue(&pidOwner, &hq, "\\queues\\sample.que"); if (ulrc) { DosWrite(HF_STDOUT, "\r\n Queue open failed. \r\n", 24, &ulWritten); DosExit(EXIT_PROCESS, 1); } else { DosWrite(HF_STDOUT, "\r\n Queue opened. \r\n", 19, &ulWritten); }
When it is finished with the queue, a thread in the client process ends its access by calling DosCloseQueue. DosCloseQueue decrements the access count for the process each time it is called. When the access count reaches 0, the connection between the client process and the queue is terminated.
After a process has opened a queue, any thread in that process can access the queue with equal authority.
Note: If a queue was created by a call to the 16-bit DosCreateQueue, then it is not accessible to 32-bit DosOpenQueue requests, and ERROR_QUE_PROC_NO_ACCESS will be returned.