/* Make */ static rc_t KDylibMake ( KDylib **libp, const WString *path ) { wchar_t *cpy; KDylib *lib = malloc ( sizeof * lib + path -> size + 4 ); if ( lib == NULL ) return RC ( rcFS, rcDylib, rcConstructing, rcMemory, rcExhausted ); cpy = ( wchar_t* ) ( lib + 1 ); lib -> handle = NULL; memcpy ( cpy, path -> addr, path -> size ); cpy [ path -> len ] = 0; WStringInit ( & lib -> path, cpy, path -> size, path -> len ); KRefcountInit ( & lib -> refcount, 1, "KDylib", "make", "WinDLL" ); * libp = lib; return 0; }
LIB_EXPORT rc_t CC KDyldVLoadLib ( KDyld *self, KDylib **lib, const char *path, va_list args ) { rc_t rc; if ( lib == NULL ) rc = RC ( rcFS, rcDylib, rcLoading, rcParam, rcNull ); else { if ( self == NULL ) rc = RC ( rcFS, rcDylib, rcLoading, rcSelf, rcNull ); else if ( path == NULL || path [ 0 ] == 0 ) { WString pstr; CONST_WSTRING ( & pstr, "" ); rc = KDylibMake ( lib, & pstr ); if ( rc == 0 ) { rc = KDyldLoad ( self, * lib, NULL ); if ( rc == 0 ) return 0; free ( * lib ); } } else { uint32_t i = VectorStart ( & self -> search ); uint32_t end = i + VectorLength ( & self -> search ); if ( i == end ) { char name [ 4096 ]; int len = vsnprintf ( name, sizeof name, path, args ); if ( len < 0 || len >= sizeof name ) rc = RC ( rcFS, rcDylib, rcLoading, rcPath, rcExcessive ); else { WString pstr; wchar_t wname [ 4096 ]; size_t wsize = string_cvt_wchar_copy ( wname, sizeof wname, name, len ); WStringInit ( & pstr, wname, wsize * sizeof wname [ 0 ], string_len ( name, len ) ); rc = KDylibMake ( lib, & pstr ); if ( rc == 0 ) { rc = KDyldLoad ( self, * lib, wname ); if ( rc == 0 ) return 0; free ( * lib ); } } } else { for ( * lib = NULL; i < end; ++ i ) { const KDirectory *dir; va_list cpy; va_copy ( cpy, args ); dir = ( const void* ) VectorGet ( & self -> search, i ); rc = KDyldVTryLoadLib ( self, lib, dir, path, cpy ); va_end ( cpy ); if ( rc == 0 || GetRCState ( rc ) != rcNotFound ) return rc; } rc = RC ( rcFS, rcDylib, rcLoading, rcPath, rcNotFound ); } } * lib = NULL; } return rc; }
int PASCAL WinMain( HINSTANCE hinstCurrent, HINSTANCE hinstPrevious, LPSTR lpszCmdLine, int nCmdShow ) { extern char **_argv; extern int _argc; MSG msg; Bool ret; /* touch unused vars to get rid of warning */ _wre_touch( lpszCmdLine ); _wre_touch( nCmdShow ); #ifdef __NT__ _wre_touch( hinstPrevious ); #endif WRInit(); WAccelInit(); WMenuInit(); WStringInit(); WREInitDisplayError( hinstCurrent ); /* store the handle to this instance of WRE in a static variable */ WREInst = hinstCurrent; peekArgs( _argv, _argc ); /* is this the first instance of the application? */ #ifndef __NT__ if( hinstPrevious == NULL ) { #endif /* if so call the routine to initialize the application */ if( !WREInit( hinstCurrent ) ) { return( FALSE ); } #ifndef __NT__ } #endif if( !WREInitInst( hinstCurrent ) ) { WREDisplayErrorMsg( WRE_INITFAILED ); return( FALSE ); } if( !WREDDEStart( hinstCurrent ) ) { WREDisplayErrorMsg( WRE_DDEINITFAILED ); return( FALSE ); } ret = WREProcessArgs( _argv, _argc ); startEditors(); // create a new empty res if none have been created at this point if( ret && WREGetNumRes() == 0 ) { WRECreateNewResource( NULL ); } /* create the message loop */ while( GetMessage( &msg, (HWND)NULL, 0, 0 ) ) { if( !WREIsEditWindowDialogMessage( &msg ) && !WREWasAcceleratorHandled( &msg ) && !WREIsResInfoWinMsg( &msg ) && !WRIsWRDialogMsg( &msg ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } WREDDEEnd(); WStringFini(); WMenuFini(); WAccelFini(); WRFini(); return( msg.wParam ); }