static USHORT Load_API(PSZ module, PSZ proc, PFN FAR *addr) { int rc, rc1 = 0; HMODULE mh; if ((rc = DosGetModHandle(module, &mh)) == 0) rc1 = DosGetProcAddr(mh, proc, addr); if (rc || rc1) { rc = DosLoadModule(NULL, 0, module, &mh); rc1 = 1; } if (rc == 0 && rc1) rc = DosGetProcAddr(mh, proc, addr); return rc; }
mad_status MADSysLoad( char *path, mad_client_routines *cli, mad_imp_routines **imp, mad_sys_handle *sys_hdl ) { HMODULE dll; mad_init_func *init_func; mad_status status; if( DosLoadModule( NULL, 0, path, &dll ) != 0 ) { return( MS_ERR|MS_FOPEN_FAILED ); } status = MS_ERR|MS_INVALID_MAD; if( DosGetProcAddr( dll, "MADLOAD", (PFN FAR *)&init_func ) == 0 && (*imp = init_func( &status, cli )) != NULL ) { *sys_hdl = dll; return( MS_OK ); } DosFreeModule( dll ); return( status ); }
/* * Load an external function from a file. This routine assumes that the * file has the same name as the resource. */ int (*os_exfil(const char *name))(void *) { FILE *fp; unsigned len; int (*extfn)(void *); #ifdef MSOS2 /* load the function from a DLL of the same name as the function */ # ifdef MICROSOFT if (_osmode == OS2_MODE) # endif /* MICROSOFT */ { CHAR failname[128]; HMODULE hmod; PFN pfn; if (DosLoadModule(failname, sizeof(failname), (PSZ)name, &hmod) || DosGetProcAddr(hmod, (PSZ)"_main", &pfn)) { return((int (*)(void))0); } return((int (*)(void))pfn); } #endif /* MSOS2 */ #ifdef __DPMI16__ #endif /* open the file and see how big it is to determine our memory needs */ if ( !( fp = fopen( name, "rb" ))) return( (int (*)(void *))0 ); (void)fseek( fp, 0L, 2 ); len = (unsigned)ftell( fp ); /* total length of file */ (void)fseek( fp, 0L, 0 ); extfn = os_exfld(fp, len); fclose( fp ); return( extfn ); }
char *RemoteLink( char *name, bool server ) { unsigned i; server = server; if( name == NULL || *name == '\0' ) name = DefLinkName; #if defined(__OS2__) #if defined(__386__) { HMODULE hmod; if( DosLoadModule( NULL, 0, "NETAPI32", &hmod ) != 0 ) { return( NotThere ); } if( DosQueryProcAddr( hmod, 0, "NetBios32Submit", (PFN*)&NetBiosSubmit ) != 0 ) { return( NotThere ); } } #else { HMODULE hmod; if( DosLoadModule( NULL, 0, "NETAPI", &hmod ) != 0 ) { return( NotThere ); } if( DosGetProcAddr( hmod, "NETBIOSSUBMIT", &NetBiosSubmit ) != 0 ) { return( NotThere ); } } #endif #elif !defined( __WINDOWS__ ) && !defined( __NT__ ) { byte *net_bios; tiny_dos_version dos_ver; int is_nt = 0; net_bios = (void *)TinyGetVect( NET_BIOS_INT ); if( net_bios == 0 || *net_bios == 0xcf ) { return( NotThere ); } /* Check if running under NT; based on MS KB 100290. */ dos_ver = GetTrueDOSVersion(); if( dos_ver.major == 5 && dos_ver.minor == 50 ) is_nt = 1; if( !is_nt ) SkipEnum = 1; } #endif NetCtlBlk.ncb_command = NET_INVALID_CMD; NetBIOS( &NetCtlBlk ); if( NetCtlBlk.ncb_retcode != NRC_ILLCMD ) { return( NotThere ); } LanaNum = GetLanaNum(); /* NetBIOS reset is required on NT, but kills connections on DOS. */ #ifdef __NT__ memset( &NetCtlBlk, 0, sizeof( NetCtlBlk ) ); NetCtlBlk.ncb_command = NCBRESET; NetCtlBlk.ncb_lana_num = LanaNum; NetBIOS( &NetCtlBlk ); if( NetCtlBlk.ncb_retcode != NRC_GOODRET ) { return( NotThere ); } #endif memset( &NetCtlBlk, 0, sizeof( NetCtlBlk ) ); for( i = 1; i < NCBNAMSZ; ++i ) { NetCtlBlk.ncb_name[i] = (*name != '\0') ? *name++ : ' '; } NetCtlBlk.ncb_name[0] = ( server ) ? 'S' : 'C'; NetCtlBlk.ncb_command = NCBADDNAME; NetCtlBlk.ncb_lana_num = LanaNum; NetBIOS( &NetCtlBlk ); if( NetCtlBlk.ncb_retcode == NRC_DUPNAME || NetCtlBlk.ncb_retcode == NRC_INUSE ) { return( TRP_ERR_server_name_already_in_use ); } else if( NetCtlBlk.ncb_retcode != NRC_GOODRET ) { return( TRP_ERR_NetBIOS_name_add_failed ); } memcpy( NetCtlBlk.ncb_callname, NetCtlBlk.ncb_name, NCBNAMSZ ); NetCtlBlk.ncb_callname[0] = ( !server ) ? 'S' : 'C'; if( server ) { if( !PostListen() ) { return( TRP_ERR_can_not_start_server ); } } return( NULL ); }