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

/*
 * dynlink2.c
 *
 *	Created by Microsoft Corp. 1987
 *
 * This example illustrates the use of run time dynamic linking.
 * A call to the procedure PRINTDATA is made in the dynamic link library DYNLIB.
 *
 * NB - The DYNLIB.DLL file must be located in the LIBPATH specified in your
 *	config.sys.  You can place your current directory at the beginning
 *	of the LIBPATH by saying libpath=.;c:\; etc.
 *
 */

#define INCL_DOSMODULEMGR
#define INCL_DOSPROCESS

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

#define	MODULE		"DYNLIB"	/* Name of dynamic link module */
#define PROCNAME	"PRINTDATA"	/* Name of routine in dynamic module */
#define FBSZ		32		/* size of failure buffer */

main(argc, argv)
	int	argc;
	char	*argv[];
{
	HMODULE 	ModHdl; 		/* dynamic link module handle */
	unsigned	rc;			/* return code */
	char		fbuf[FBSZ];		/* failure obj name buffer */
	void		(far pascal * DynamicProc)();


	/* Load dynamic link module */

	if (rc = DosLoadModule( fbuf, FBSZ, MODULE, &ModHdl))
	{
		printf("module %s not found, failing obj %s error: %d\n",
			MODULE, fbuf, rc);
		DosExit(EXIT_PROCESS,1);   /* exit with error */
	}
	
	/* Get the address of procedure PROCNAME in the dynamic link module */

	if (rc = DosGetProcAddr( ModHdl, PROCNAME,
				 (PFN far *) &DynamicProc))
	{
		printf("procedure %s not found, error: %d\n", PROCNAME, rc);
		DosExit(EXIT_PROCESS,1);   /* exit with error */
	}

	while(1)
	{
		(*DynamicProc)();   /* display shared and non-shared data   */
		DosSleep(100L);     /* yield the processor		  */
	}
}

unix.superglobalmegacorp.com

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