[an error occurred while processing this directive]

HP OpenVMS Systems

Ask the Wizard
» 

HP OpenVMS Systems

OpenVMS information

» What's new on our site
» Upcoming events
» Configuration and buying assistance
» Send us your comments

HP OpenVMS systems

» OpenVMS software
» Supported Servers
» OpenVMS virtualization
» OpenVMS solutions and partners
» OpenVMS success stories
» OpenVMS service and support
» OpenVMS resources and information
» OpenVMS documentation
» Education and training

Quick Links

» Non-javascript page
» Ask the Wizard
» OpenVMS FAQ

Test Drive OpenVMS

» OpenVMS I64 test drive
» Java test drive

Other information resources available to you include:

» OpenVMS freeware
» ECO kits, software and hardware support, prior version support
» Alpha SRM, ARC, and AlphaBIOS firmware updates
» ENCOMPASS - HP user group
» OpenVMS software downloads, OpenVMS freeware CD-ROM
» OpenVMS firmware locations
» DECconnect passive adaptor charts
» Cables reference guide
» MicroVAX console commands
» OpenVMS student research

Select a topic below to see Questions Frequently Asked by partners

» Using the online documentation library(installing BNU from the asap SDK)
» Global sections(how to create and use.)
» xx$CREATE_BUFOBJ system service(usage)
» Ethernet address(methods of determination)
» Shareable images(cookbook approach to creating one)
» Sharing data/code at absolute addresses(a guide with examples)
» Determining the Alpha microprocessor
» Using GETSYI to get hardware status

Evolving business value

» Business Systems Evolution
» AlphaServer systems transition planning
» Alpha RetainTrust program

Related links

» HP Integrity servers
» HP Alpha systems
» HP storage
» HP software
» HP products and services
» HP solutions
» HP support
disaster proof
HP Integrity server animation
HP Integrity server animation
Content starts here

Ask the Wizard Questions

Mailbox from C

The Question is:

Dear Wizard,

   I am in search of an internet site where I can scan and
peruse VAX C or DEC C code examples pertaining to OpenVMS's
use of Mailboxes.

Can you point me in the right area to look?

Thank You

In the meantime, I shall continue to practice the art of
futility ...



The Answer is:

      Call your local customer support centre and have them activate your
    DIA account. This is dial in access to the DSNlink system - a service
    to which you are entitled as long as you have a support contract.

      The service is also available on the internet (telnet to
    dia.service.digital.com) and on the web at http://www.service.digital.com
    (note, the web site may not be available in all areas). Using the
    query "example c mailbox" I found 157 articles, most of which are
    example programs using mailboxes (though not all are in C). I've
    appended one.

Example-C  How To Create, Write To, And Read A Mailbox


COPYRIGHT (c) 1988, 1993 by Digital Equipment Corporation.
ALL RIGHTS RESERVED. No distribution except as provided under contract.

Copyright (c) Digital Equipment Corporation 1994.  All rights reserved.

PRODUCT:    VAX C/DEC C
            DEC C for OpenVMS AXP

OP/SYS:     OpenVMS VAX
            OpenVMS AXP

SOURCE:     Digital Equipment Corporation


OVERVIEW:

This example shows how to create a temporary mailbox, read from a mailbox,
and write to a mailbox.

*** CAUTION ***

This sample program has been tested using VAX C V3.2 on OpenVMS VAX V6.1,
DEC C V4.0 on OpenVMS VAX V6.1, and DEC C V4.0 on OpenVMS AXP V6.1.
However, we cannot guarantee its effectiveness because of the possibility
of error in transmitting or implementing it.  It is meant to be used as a
template for writing your own program, and it may require modification for
use on your system.


SOURCE:

This programming example was taken from the VAX/VMS Education Series,
UTILIZING VMS FEATURES FROM VAX C, C Language Workbook, (Aug 86).


PROGRAM NOTES:

The programs MAILS and MAILR must be run from two processes in the same
group.  To run the programs, log in at one terminal, execute the DEFINE
command as explained below, and run one program.  Then log onto another
terminal, execute the DEFINE command for that process and run the other
terminal.

Because both MAILS and MAILR use $CREMBX to create a temporary mailbox
with the logical name FOZZIE_BEAR (if no such mailbox exists) and assign
a channel to it, the programs can be run in any order.  If MAILS had used
$CREMBX and MAILR had used $ASSIGN, for example, it would be necessary to
run MAILS first.

When you specify a logical name for a temporary mailbox, the $CREMBX
service enters the name into the LNM$TEMPORARY_MAILBOX logical name table.

Normally, LNM$TEMPORARY_MAILBOX specifies LNM$JOB, the job-wide logical
name table; thus, only processes in the same job as the process that first
creates the mailbox can use the logical name to access the temporary
mailbox.  If you want to use the temporary mailbox to enable communication
between processes in different jobs, you must redefine LNM$TEMPORARY_
MAILBOX in the process logical name directory table (LNM$PROCESS_
DIRECTORY), to specify a logical name table that those processes can
access.

For instance, if you want to use the mailbox as a communication device for
processes in the same group, you must redefine LNM$TEMPORARY_MAILBOX to
specify LNM$GROUP, the group logical name table.  The following DCL command
assigns temporary mailbox logical names to the group logical name table:

     $DEFINE/TABLE=LNM$PROCESS_DIRECTORY  LNM$TEMPORARY_MAILBOX  LNM$GROUP

Because $QIOW is used for input and output rather than $QIO, both MAILS
and MAILR wait for I/O to complete before advancing to the next program
statement.

The P1 argument of $QIOW is the address of a buffer of ASCII text, not the
address of an ASCII string descriptor.


PROGRAMS:

/* MAILS.C
   This program writes to a mailbox with the
   logical name FOZZIE_BEAR. Since this is a
   synchronous operation, the write does not
   complete until the process MAILR reads the message. */

#include 
#include 
#include 
#include 
#include 
main()
{
typedef struct
           {
           short cond_value;
           short count;
           int info;
           }  io_statblk;

io_statblk iosb;
short channel;
$DESCRIPTOR(mailbox_name, "FOZZIE_BEAR");
char message[]="This is a message.";
register status;

/* create mailbox and/or assign channel to it */
if (((status = sys$crembx(0,&channel,0,0,0,0,&mailbox_name)) &1) !=1)
   lib$stop(status);

/* write a message to the mailbox */
if (((status = sys$qiow(1, channel, IO$_WRITEVBLK, &iosb, 0, 0,
                  message, sizeof(message), 0,0,0,0)) &1) != 1)
   lib$stop(status);
if ((iosb.cond_value &1) != 1)
   lib$stop(iosb.cond_value);

/* notify user */
printf("\nMAILS has completed mailbox write.\n");
}

/* MAILR.C
   This program reads from the mailbox created by
   MAILS. As soon as it reads the mailbox, MAILS
   can continue. */

#include 
#include 
#include 
#include 
#include 

main()
{
typedef struct
           {
           short cond_value;
           short count;
           int info;
           }  io_statblk;

io_statblk iosb;
short channel;
$DESCRIPTOR(mailbox_name, "FOZZIE_BEAR");
char input[30];
register status;

/* create mailbox and/or assign channel to it */
if (((status = sys$crembx(0,&channel,0,0,0,0,&mailbox_name)) &1) !=1)
   lib$stop(status);

/* read the mailbox */
if (((status = sys$qiow(2, channel, IO$_READVBLK, &iosb, 0, 0,
                     input, sizeof(input)-1, 0,0,0,0)) &1) != 1)
   lib$stop(status);
if ((iosb.cond_value &1) != 1)
   lib$stop(iosb.cond_value);

/* output the mailbox message */
input[iosb.count] = '\0';
printf("\n%s\n", input);
}

RUNNING THE PROGRAM:

$ ! RUN FROM ONE TERMINAL
$
$ SET PROCESS/PRIV=GRPNAM
$ DEFINE/TABLE=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
$
$ CC MAILS
$!
$! If this program is compiled with Dec C (VAX or AXP), use the following
$! command to link it.
$ LINK MAILS
$!
$! If this program is compiled with VAX C, use this command to link it.
$! Be sure to comment out the link command used for DEC C and uncomment
$! this.
$! LINK MAILS,SYS$INPUT/OPTIONS
!sys$share:vaxcrtl.exe/share 
$ RUN MAILS

MAILS has completed mailbox write.


$ ! RUN FROM ANOTHER TERMINAL
$
$ SET PROCESS/PRIV=GRPNAM
$ DEFINE/TABLE=LNM$PROCESS_DIRECTORY LNM$TEMPORARY_MAILBOX LNM$GROUP
$
$ CC MAILR
$!
$! If this program is compiled with Dec C (VAX or AXP), use the following
$! command to link it.
$ LINK MAILR
$!
$! If this program is compiled with VAX C, use this command to link it.
$! Be sure to comment out the link command used for DEC C and uncomment
$! this.
$! LINK MAILR,SYS$INPUT/OPTIONS
!sys$share:vaxcrtl.exe/share 
$ RUN MAILR

This is a message.


REFERENCE(S):

"OpenVMS System Services Reference Manual: A-GETMSG", May 1993, (AA-PV6FA-TK)

"OpenVMS System Services Reference Manual: GETQUI-Z", May 1993 (AA-PV6GA-TK)

"OpenVMS System I/O User's Reference Manual", May 1993 (AA-PV6SA-TK), Chapter 4