home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1996-05-29 | 5.7 KB | 130 lines | [ TEXT/CWIE]
#include <iostream.h> #include <types.h> #include <Errors.h> #include <CodeFragments.h> #include <string.h> #include <stdio.h> #include <sioux.h> void printError(OSErr theError); void main (void) { extern tSIOUXSettings SIOUXSettings; SIOUXSettings.asktosaveonclose = false; OSErr myErr; CFragConnectionID myConnection; Ptr myMainAddr; Str255 myErrName = "\p<n/a>"; char libName[256]; Str255 libNameP; cout << "LibLook 1.0" << endl << endl; cout << "Enter the library name (fragment name) of the shared library. " << endl; cout << "This is not necessarily the file name, but the name in 'cfrg' " << endl; cout << "resource that was entered on the 'CFM68K' or 'PPC PEF' preference " << endl; cout << "page in Code Warrior 7. The shared library must either be in the " << endl; cout << "extensions folder or the same folder as this application. " << endl << endl; cout << "Library Name: "; gets (libName); cout << endl; libNameP[0] = (unsigned char)strlen(libName); strcpy((char *)&libNameP[1],libName); cout << "Attempting to load shared library: " << libName << endl << endl; // dynamicly load the CFM myErr = GetSharedLibrary(libNameP,kAnyCFragArch,kLoadCFrag,&myConnection,&myMainAddr,myErrName); if (myErr==fragNoErr) { cout << "The library opened successfully! [" << myErr << "]" << endl << endl; long index, count; // Get the number of entry points in the CFM myErr = CountSymbols(myConnection, &count); if (myErr==fragNoErr) { cout << "CountSymbols indicated that there were " << count << " symbols in this shared library." << endl << endl; for (index = 0; index < count; index++) { Str255 mySymName; long (*myFuncPtr)(); CFragSymbolClass mySymClass; // Get the info about the entry point myErr = GetIndSymbol(myConnection, index, mySymName, (Ptr *)&myFuncPtr, &mySymClass); if (myErr==fragNoErr) { cout << "Symbol #" << index << " Named:'"; for (int j = 1; j <= mySymName[0]; j++) { cout << mySymName[j]; } // call the entry point (we assume all have no params and return a long cout << "' Addr:" << (long)myFuncPtr << " Class:" << mySymClass << endl; //cout << " Returned:" << myFuncPtr() << endl; } else { cout << "There was an error callling GetIndSymbol! [" << myErr << "]" << endl << endl; printError(myErr); } } } else { cout << "There was an error callling CountSymbols! [" << myErr << "]" << endl << endl; printError(myErr); } myErr = CloseConnection(&myConnection); } else { cout << "There was an error callling GetSharedLibrary! [" << myErr << ":'" << myErrName << "']" << endl << endl; printError(myErr); } cout << endl << "done." << endl; } void printError(OSErr theError) { switch (theError) { #define fragError(name,number,description) case number : { cout << "*** Fragment Manager Error ***" << endl\ << " Error Value : " << number << endl \ << " Error Name : " << name << endl\ << " Description : " << description << endl; break; } /* Reserved values for internal "warnings".*/ fragError("fragNameNoErr",0," No error, why did you get this msg "); fragError("fragNameContextNotFound", -2800," CFM error codes "); fragError("fragNameConnectionIDNotFound", -2801," contextID was not valid "); fragError("fragNameSymbolNotFound", -2802," connecionID was not valid "); fragError("fragNameSectionNotFound", -2803," symbol was not found in connection "); fragError("fragNameLibNotFound", -2804," section was not found "); fragError("fragNameDupRegLibName", -2805," library name not found in Frag registry "); fragError("fragNameFormatUnknown", -2806," registered name already in use "); fragError("fragNameHadUnresolveds", -2807," fragment container format unknown "); fragError("fragNameUnused1", -2808," loaded fragment had 'hard' unresolved imports "); fragError("fragNameNoMem", -2809," unused "); fragError("fragNameNoAddrSpace", -2810," out of memory for interal bookkeeping "); fragError("fragNameNoContextIDs", -2811," out of memory in user's address space for loadable section "); fragError("fragNameObjectInitSeqErr", -2812," no more context id’s "); fragError("fragNameImportTooOld", -2813," order error during user initialization function invocation "); fragError("fragNameImportTooNew", -2814," import library was too old and therefore incompatible "); fragError("fragNameInitLoop", -2815," import library was too new and therefore incompatible "); fragError("fragNameInitRtnUsageErr", -2816," circularity detected in mandatory initialization order "); fragError("fragNameLibConnErr", -2817," boot library has initialization routine "); fragError("fragNameMgrInitErr", -2818," error connecting to library (error occured in sub prepare) "); fragError("fragNameConstErr", -2819," error in initailization of this manager "); fragError("fragNameCorruptErr", -2820," internal inconstistancy "); fragError("fragNameUserInitProcErr", -2821," fragment container corrupted (known format) "); fragError("fragNameAppNotFound", -2822," user intialization routine did not return noErr "); fragError("fragNameArchError", -2823," no application found in cfrg (for Process Manager) "); fragError("fragNameInvalidFragmentUsage", -2824," fragment targeted for an unacceptable architecture "); fragError("fragNameLastErrCode", -2899," ie: an application's main fragment had no entry point - or - an accerated resource had no entry point or it had a termination routine, etc... "); default : { cout << "*** Fragment Manager Error ***" << endl; cout << " Error Value : " << theError << endl ; cout << " Error Name : * unknown *" << endl; cout << " Description : n/a" << endl; break; } } }