//-------------------------------------------------------------------- // spiwrap.c // // Created: 11/20/97 // Author: Matt Kendall // // Copyright (C) 1997 Full Circle Software All Rights Reserved // // Dynamically Load Spiral API // //-------------------------------------------------------------------- #include #include #include "fullsoft.h" #define FC_WRAPPER_VERSION 2 #define FC_WRAPPER_MINIMUM_ACCEPTABLE_LIBRARY_VERSION 1 #if !defined(_WINDOWS) #error This is a Windows only file #endif // _WINDOWS #if !defined(_WIN32) && !defined(_WIN16) #define _WIN16 #endif // ! _WIN32 && ! _WIN16 #if defined(_WIN32) #define DEFINE_CALLNAME(s) const char sz##s[] = #s #else // ! _WIN32 #define DEFINE_CALLNAME(s) const char sz##s[] = "_"#s void FreeOrphanFCLoads() ; #endif // ! _WIN32 void FCUnloadLibrary() ; BOOL FCIsValidFullsoftLibrary(const char *) ; typedef FC_ERROR (FCAPI __cdecl *t_FCInitialize)( void ) ; typedef FC_ERROR (FCAPI __cdecl *t_FCCreateKey)( FC_KEY key, FC_DATA_TYPE type, FC_UINT32 first_count, FC_UINT32 last_count, FC_UINT32 max_element_size) ; typedef FC_ERROR (FCAPI __cdecl *t_FCCreatePersistentKey)( FC_KEY key, FC_DATA_TYPE type, FC_UINT32 first_count, FC_UINT32 last_count, FC_UINT32 max_element_size) ; typedef FC_ERROR (FCAPI __cdecl *t_FCAddDataToKey)( FC_KEY key, FC_PVOID buffer, FC_UINT32 data_length) ; typedef FC_ERROR (FCAPI __cdecl *t_FCAddIntToKey)( FC_KEY key, FC_UINT32 data) ; typedef FC_ERROR (FCAPI __cdecl *t_FCAddStringToKey)( FC_KEY key, FC_STRING string) ; typedef FC_ERROR (FCAPI __cdecl *t_FCRegisterMemory)( FC_KEY key, FC_DATA_TYPE type, FC_PVOID buffer, FC_UINT32 length, FC_UINT32 dereference_count, FC_CONTEXT context) ; typedef FC_ERROR (FCAPI __cdecl *t_FCUnregisterMemory)( FC_CONTEXT context) ; typedef FC_ERROR (FCAPI __cdecl *t_FCAddDateToKey)( FC_KEY key, FC_DATE date) ; typedef FC_ERROR (FCAPI __cdecl *t_FCSetCounter)( FC_KEY key, FC_UINT32 value) ; typedef FC_ERROR (FCAPI __cdecl *t_FCIncrementCounter)( FC_KEY key, FC_UINT32 value) ; typedef FC_ERROR (FCAPI __cdecl *t_FCTrigger)( FC_TRIGGER trigger ) ; typedef FC_ERROR (FCAPI __cdecl *t_FCTriggerInternal)( FC_TRIGGER szTrigger, FC_UINT32 eip, FC_UINT32 esp, FC_UINT32 ebp) ; typedef void (FCAPI __cdecl *t_FCTraceInternal)(FC_STRING fmt,void FAR *) ; typedef void (FCAPI __cdecl *t_FCAssertInternal)(unsigned long) ; typedef FC_ERROR (FCAPI __cdecl *t_FCCleanup)( void ) ; typedef int (FCAPI __cdecl *t_FCOrphanLoadCount)() ; typedef void (FCAPI __cdecl *t_FCAssertParamInternal)(FC_UINT32 pc,FC_UINT32 mask,FC_UINT32 level ) ; typedef void (FCAPI __cdecl *t_FCTraceParamInternal)(FC_UINT32 mask,FC_UINT32 level,FC_STRING fmt,void FAR *args ) ; typedef FC_UINT32 (FCAPI __cdecl *t_FCLibraryVersion)( FC_UINT32 wrap_version ) ; typedef FC_ERROR (FCAPI __cdecl *t_FCInitializeInternal)( FC_UINT32 wrap_version ) ; DEFINE_CALLNAME( FCInitialize ) ; DEFINE_CALLNAME( FCCreateKey ) ; DEFINE_CALLNAME( FCCreatePersistentKey ) ; DEFINE_CALLNAME( FCAddDataToKey ) ; DEFINE_CALLNAME( FCAddIntToKey ) ; DEFINE_CALLNAME( FCAddStringToKey ) ; DEFINE_CALLNAME( FCRegisterMemory ) ; DEFINE_CALLNAME( FCUnregisterMemory ) ; DEFINE_CALLNAME( FCAddDateToKey ) ; DEFINE_CALLNAME( FCSetCounter ) ; DEFINE_CALLNAME( FCIncrementCounter ) ; DEFINE_CALLNAME( FCTrigger ) ; DEFINE_CALLNAME( FCTriggerInternal ) ; DEFINE_CALLNAME( FCTraceInternal ) ; DEFINE_CALLNAME( FCAssertInternal ) ; DEFINE_CALLNAME( FCCleanup ) ; DEFINE_CALLNAME( FCOrphanLoadCount ) ; DEFINE_CALLNAME( FCAssertParamInternal ) ; DEFINE_CALLNAME( FCTraceParamInternal ) ; DEFINE_CALLNAME( FCLibraryVersion ) ; DEFINE_CALLNAME( FCInitializeInternal ) ; t_FCInitialize pfnFCInitialize ; t_FCCreateKey pfnFCCreateKey ; t_FCCreatePersistentKey pfnFCCreatePersistentKey ; t_FCAddDataToKey pfnFCAddDataToKey ; t_FCAddIntToKey pfnFCAddIntToKey ; t_FCAddStringToKey pfnFCAddStringToKey ; t_FCAddDateToKey pfnFCAddDateToKey ; t_FCSetCounter pfnFCSetCounter ; t_FCIncrementCounter pfnFCIncrementCounter ; t_FCRegisterMemory pfnFCRegisterMemory ; t_FCUnregisterMemory pfnFCUnregisterMemory ; t_FCTrigger pfnFCTrigger ; // undocumented dll functions t_FCTraceInternal pfnFCTraceInternal ; t_FCAssertInternal pfnFCAssertInternal ; t_FCCleanup pfnFCCleanup ; t_FCAssertParamInternal pfnFCAssertParamInternal ; t_FCTraceParamInternal pfnFCTraceParamInternal ; t_FCLibraryVersion pfnFCLibraryVersion ; t_FCInitializeInternal pfnFCInitializeInternal ; t_FCTriggerInternal pfnFCTriggerInternal ; static HMODULE gMod = NULL; void ExitFunction( void ); void ExitFunction( void ) { if( pfnFCCleanup!=NULL ) { pfnFCCleanup() ; } if( gMod!=NULL ) { FreeLibrary( gMod ) ; } } FC_ERROR FCAPI FCInitialize() { FC_UINT32 dwLibraryVersion ; char szFullsoftLibrary[MAX_PATH] ; char *p,*pEnd,*pLastSlash ; HMODULE hMod; #if defined(_WIN16) // If Spiral crashed in Win16 than "spiral.dll" will be left in memory with // a bogus reference count. The following routine identifies this and // cleans up FreeOrphanFCLoads() ; #endif // _WIN16 if ( atexit(ExitFunction) != 0 ) { return FC_ERROR_CANT_INITIALIZE; } // Build up a fully qualified path to FULLSOFT.DLL GetModuleFileName( GetModuleHandle(NULL) , szFullsoftLibrary , MAX_PATH ) ; pEnd = szFullsoftLibrary+MAX_PATH ; pLastSlash = szFullsoftLibrary ; for( p = szFullsoftLibrary ; (p