File:  [OS/2 SDKs] / os2sdk / demos / examples / dynlink / dynlib.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs
Thu Aug 9 12:26:22 2018 UTC (7 years, 9 months ago) by root
Branches: msft, MAIN
CVS tags: os2sdk-1988, HEAD
Microsoft OS/2 SDK 03-01-1988

/*
 * dynlib.c
 *
 *   Created by Microsoft Corp. 1987
 *
 * Dynamic link library demo module with non-shared data.
 *
 */

/*
 * NB - The variable _acrtused must be declared in one of the modules of the
 *	dll.  The C compiler generates this symbol as an extern to ensure
 *	that the runtime library startup module crt0 will be pulled in by the
 *	linker.  Declaring _acrtused will keep this unwanted code out.
 *
 * NB - To be made part of the named data segment, variables at the external
 *	level must be declared static or they must be initialized or both.
 *
 */

/*
 * NB - This version must be compiled with the -Asnu compiler option.
 *	s => short code pointers
 *	n => near data pointers
 *	u => upon function entry, DS is saved, then made to point to the named
 *	     data segment.  DS is restored on exit from the function.
 *
 */

#define INCL_DOSFILEMGR

#include <os2def.h>
#include <bsedos.h>

int _acrtused=0;
unsigned id=0;		    /* process-unique identifier		     */
unsigned far * pcount=0;    /* pointer to the shared process count	     */

void APIENTRY		    /* This routine is called during per-process     */
init_id(pc)		    /* initialization to pass the pointer to the     */
unsigned far * pc;	    /* shared count and to set the non-shared id.    */
{
    pcount = pc;
    id = *pc;
}

void APIENTRY		    /* This routine is called by the process to show */
printdata()		    /* on the screen the current values of the	     */
			    /* non-shared id and the shared count.	     */
{
    static char beg[]="I am number ";
    static char mid[]=".  There are ";
    static char end[]=" processes attached.\r";
    char c;
    USHORT Written;

    DosWrite(1, beg, sizeof(beg)-1, &Written);
    c = id + '0';
    DosWrite(1, &c, sizeof(char), &Written);
    DosWrite(1, mid, sizeof(mid)-1, &Written);
    c = *pcount + '0';
    DosWrite(1, &c, sizeof(char), &Written);
    DosWrite(1, end, sizeof(end)-1, &Written);
}

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.