home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 March / CHIPCD_3_98.iso / software / share / sharmies / unixdos / data.z / diff6b.txt < prev    next >
Text File  |  1997-11-18  |  6KB  |  170 lines

  1. #include "RGSTDAFX.H"
  2. #include "cfuncs.hpp"                                                                                   // This is a global C funtion man.
  3.  
  4. CObject* CreateRuntimeClassObject( char* szClassName )
  5. {
  6.   CRuntimeClass* pClassRef = FindRuntimeClass( szClassName, 0 );
  7.   if ( pClassRef )
  8.     {
  9.     // allocate a new object based on the class just acquired
  10.     CObject* object = pClassRef->CreateObject();
  11.     if (object == NULL)
  12.       AfxThrowMemoryException();
  13.     return object; 
  14.     }           
  15.   else
  16.     return NULL;
  17. }
  18.  
  19. CRuntimeClass* PASCAL FindRuntimeClass( char* szClassName, UINT* pwSchemaNum)
  20. {
  21.   CRuntimeClass* pClass;
  22.  
  23. #ifndef _AFXDLL
  24.   for (pClass = CRuntimeClass::pFirstClass; pClass != NULL; pClass = pClass->m_pNextClass)
  25.   {
  26.     if (lstrcmp(szClassName, pClass->m_lpszClassName) == 0)
  27.       return pClass;
  28.   }
  29. #else
  30.   // all registered CRuntimeClasses should be owned by the app or a DLL
  31.   ASSERT(CRuntimeClass::pFirstClass == NULL);
  32.  
  33.   // first walk through the app specific classes
  34.   for (pClass = _AfxGetAppData()->pFirstAppClass; pClass != NULL;
  35.     pClass = pClass->m_pNextClass)
  36.   {
  37.     if (lstrcmp(szClassName, pClass->m_lpszClassName) == 0)
  38.       return pClass;
  39.   }
  40.   // now walk through the classes in different DLLs
  41.   CDynLinkLibrary* pDLL;
  42.   for (pDLL = _AfxGetAppData()->pFirstDLL; pDLL != NULL;
  43.     pDLL = pDLL->m_pNextDLL)
  44.   {
  45.     for (pClass = pDLL->m_pFirstSharedClass; pClass != NULL;
  46.       pClass = pClass->m_pNextClass)
  47.     {
  48.       if (lstrcmp(szClassName, pClass->m_lpszClassName) == 0)
  49.         return pClass;
  50.     }
  51.   }
  52. #endif //_AFXDLL
  53.  
  54.   return NULL; // not found
  55. }
  56.  
  57. void GetOwnerNameFromDisplay( CString &displayString, CString &owner, CString &name )
  58. {
  59.   // Takes strings in format "name(owner)" and makes a owner and a name.
  60.   
  61.   owner.Empty();
  62.   name.Empty();
  63.   
  64.   if ( !displayString.IsEmpty() )
  65.     {
  66.     // Put into proper format.
  67.     int pos = displayString.Find( '(' );
  68.     CString tempOwner = displayString.Right( displayString.GetLength() - pos );
  69.     CString tempName  = displayString.Left( pos );
  70.   
  71.     // Get rid of parens and spaces for owner.
  72.     for( int i=0; i<tempOwner.GetLength(); i++ )
  73.       {
  74.       if ( tempOwner[i] != '(' && tempOwner[i] != ')' && tempOwner[i] != ' ' )
  75.         {
  76.         owner += tempOwner[i];
  77.         }
  78.       }
  79.     // Ditto for name.
  80.     for( i=0; i<tempName.GetLength(); i++ )
  81.       {
  82.       if ( tempName[i] != '(' && tempName[i] != ')' && tempName[i] != ' ' )
  83.         {
  84.         name += tempName[i];
  85.         }
  86.       }
  87.     }
  88. }
  89.  
  90. void GetTempDirectory( CString & pathName, CString & aFileName )
  91. {
  92.   // buffer to compare to find temp
  93.   char    firstfour[6];
  94.   
  95.   // get and hold the dos env. don't change anything!!
  96.   LPSTR   lpszEnv = ::GetDOSEnvironment();
  97.  
  98.   pathName.Empty();
  99.  
  100.   // Get the temp directory.
  101.   while ( *lpszEnv!=0 && pathName.IsEmpty() ) 
  102.     {
  103.     int len = lstrlen(lpszEnv);
  104.     lstrcpyn( firstfour, lpszEnv, ((len>5)?5:len) );
  105.     if ( !lstrcmpi( "temp", firstfour ) )
  106.       {
  107.       pathName = (const char*)&lpszEnv[5];
  108.       }
  109.     lpszEnv += len + 1;
  110.     }
  111.     
  112.   // If we didn't find the temp, use the windows dir.  
  113.   if ( pathName.IsEmpty() )
  114.     {
  115.     char * buf = new char[8000];
  116.     ::GetWindowsDirectory( buf, 8000 );
  117.     pathName = (const char *)buf;
  118.     delete [] buf;
  119.     }
  120.       
  121.   if ( !aFileName.IsEmpty() )
  122.     {
  123.     // caller wants a pathName appended.
  124.     if ( pathName[pathName.GetLength()-1] != '\\' )
  125.       {
  126.       pathName += '\\';
  127.       }
  128.     pathName += aFileName;
  129.     }
  130. }
  131.  
  132. extern "C" int GetOsys_Val = -1;
  133.  
  134. #define WF_WINNT  0x4000
  135. #define WF_WIN95  0x2000
  136.  
  137. //****** RETURN OPERATING SYSTEM ENVIRONMENT ********************************//
  138. // AUTHOR:   Madhur Eichberger                                               //
  139. //                                                                           //
  140. // OBJECTIVE:                                                                //
  141. // Determine the current operation system environment                        //
  142. //                                                                           //
  143. // ARGUMENTS:                                                                //
  144. //                                                                           //
  145. // OUTPUT:                                                                   //
  146. // ret: OS_WIN31 Windows 3.1                                                 //
  147. // ret: OS_WIN95 Windows 95                                                  //
  148. // ret: OS_WINNT Windows NT                                                  //
  149. //                                                                           //
  150. // CREATED   07/18/95 MADHUR EICHBERGER                                      //
  151. //***************************************************************************//
  152. extern "C" int GetOsys()
  153. {
  154. DWORD dwVersion;
  155. int ret;
  156.  
  157.     //****** CHECK IF FIRST TIME **********************************************
  158.     if (GetOsys_Val > 0)
  159.         return(GetOsys_Val);
  160.     
  161.     //****** CHECK FLAGS FOR OPERATION SYSTEM *********************************
  162.     dwVersion = GetWinFlags();
  163.     ret = OS_WIN31;     // assume win 3.11
  164.     if ((dwVersion & WF_WINNT) != 0) ret = OS_WINNT;
  165.     if ((dwVersion & WF_WIN95) != 0) ret = OS_WIN95;
  166.     GetOsys_Val = ret;  // save for direct access next time
  167. TRACE("GetOsys: ret=%d, GetWinFlags: 0x%lX",ret,dwVersion);
  168.     return(ret);
  169. }
  170.