Esempio n. 1
0
static BOOL IsDCPostscript( HDC hDC )
{
    int         nEscapeCode;
    CHAR        szTechnology[MAX_PATH] = "";

    // If it supports POSTSCRIPT_PASSTHROUGH, it must be PS.
    nEscapeCode = POSTSCRIPT_PASSTHROUGH;
    if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
                     (LPCSTR)&nEscapeCode, 0, NULL ) > 0 )
        return TRUE;

    // If it doesn't support GETTECHNOLOGY, we won't be able to tell.
    nEscapeCode = GETTECHNOLOGY;
    if( ::ExtEscape( hDC, QUERYESCSUPPORT, sizeof(int),
                     (LPCSTR)&nEscapeCode, 0, NULL ) <= 0 )
        return FALSE;

    // Get the technology string and check if the word "postscript" is in it.
    if( ::ExtEscape( hDC, GETTECHNOLOGY, 0, NULL, MAX_PATH,
                     (LPSTR)szTechnology ) <= 0 )
        return FALSE;
    _strupr_s(szTechnology, MAX_PATH);
    if(!strstr( szTechnology, "POSTSCRIPT" ) == NULL )
        return TRUE;

    // The word "postscript" was not found and it didn't support
    //   POSTSCRIPT_PASSTHROUGH, so it's not a PS printer.
        return FALSE;
}
Esempio n. 2
0
//A simple example of call tips
void CCppDocContentView::OnDwellStart(_Inout_ SCNotification* pSCNotification)
{
	CScintillaCtrl& rCtrl = GetCtrl();

	//Only display the call tip if the scintilla window has focus
	CWnd* pFocusWnd = GetFocus();
	if (pFocusWnd)
	{
		if (pFocusWnd->GetSafeHwnd() == rCtrl.GetSafeHwnd())
		{
			//Get the previous 7 characters and next 7 characters around
			//the current dwell position and if it is "author " case insensitive
			//then display "PJ Naughter" as a call tip
			Sci_TextRange tr;
			tr.chrg.cpMin = max(0, pSCNotification->position - 7);
			tr.chrg.cpMax = min(pSCNotification->position + 7, rCtrl.GetLength());
			char sText[15];
			sText[0] = '\0';
			tr.lpstrText = sText;
			rCtrl.GetTextRange(&tr);

			//Display the call tip
			_strupr_s(sText, sizeof(sText));
			if (strstr(sText, "AUTHOR "))
				rCtrl.CallTipShow(pSCNotification->position, _T("PJ Naughter"));
		}
	}
}
Esempio n. 3
0
/**********************************************************************************************************************
	NStringUtils::To_Upper_Case - converts a string to uppercase characters

		source -- source string
		dest -- output parameter to store conversion in

**********************************************************************************************************************/
void NStringUtils::To_Upper_Case( const std::string &source, std::string &dest )
{
	size_t buffer_size = source.size() + 1;
	char *buffer = new char[ buffer_size ];
	strcpy_s( buffer, buffer_size, source.c_str() );
	_strupr_s( buffer, buffer_size );

	dest = std::string( buffer );

	delete buffer;
}
Esempio n. 4
0
char* strustr(char *source, char *s)
{
	//make an uppercase copy af source and s
	char *csource = _strdup(source);
	char *cs = _strdup(s);
	_strupr_s(csource,strlen(source)+1);
	_strupr_s(cs,strlen(s)+1);
	//find cs in csource...LAST-MODIFIED
	char *result = strstr(csource, cs);
	if (result != NULL)
	{
		//cs is somewhere in csource
		int pos = result - csource;
		result = source;
		result += pos;
	}
	//clean up
	free(csource);
	free(cs);
	return result;
}
int _tmain(int argc, _TCHAR *argv[]) {
    InitializeCriticalSection(&csOutput);

    for (int i = 0; i < 26; i++) {
        watchRootInfos[i].driveLetter = 'A' + i;
        watchRootInfos[i].bInitialized = false;
        watchRootInfos[i].bUsed = false;
    }

    char buffer[8192];
    while (true) {
        if (!gets_s(buffer, sizeof(buffer) - 1))
            break;

        if (!strcmp(buffer, "ROOTS")) {
            MarkAllRootsUnused();
            FreeWatchRootsList();
            bool failed = false;
            while (true) {
                if (!gets_s(buffer, sizeof(buffer) - 1)) {
                    failed = true;
                    break;
                }
                if (buffer[0] == '#')
                    break;
                int driveLetterPos = 0;
                char *pDriveLetter = buffer;
                if (*pDriveLetter == '|')
                    pDriveLetter++;

                AddWatchRoot(pDriveLetter);

                _strupr_s(buffer, sizeof(buffer) - 1);
                char driveLetter = *pDriveLetter;
                if (driveLetter >= 'A' && driveLetter <= 'Z') {
                    watchRootInfos[driveLetter - 'A'].bUsed = true;
                }
            }
            if (failed)
                break;

            UpdateRoots(true);
        }

        if (!strcmp(buffer, "EXIT"))
            break;
    }

    MarkAllRootsUnused();
    UpdateRoots(false);

    DeleteCriticalSection(&csOutput);
}
static void l_Build_Common_Info(__in PKLST_DEVINFO_EL devItem)
{
	PKLST_DEV_COMMON_INFO commonInfo = &devItem->Public.Common;
	CHAR devID[KLST_STRING_MAX_LEN];
	PCHAR chLast;
	PCHAR chNext;
	ULONG pos = 0;

	commonInfo->MI = UINT_MAX;
	commonInfo->Vid = UINT_MAX;
	commonInfo->Pid = UINT_MAX;

	strcpy_s(devID, sizeof(devID), devItem->Public.DeviceID);
	_strupr_s(devID, sizeof(devID));
	chLast = chNext = devID;

	while(chLast && chLast[0])
	{
		if ((chNext = strchr(chNext, '\\')) != NULL)
		{
			*chNext = '\0';
			chNext = &chNext[1];
		}
		switch(pos)
		{
		case 0:	// USB
			break;
		case 1:	// VID_%04X&PID_%04X
			if (sscanf_s(chLast, "VID_%04X&PID_%04X&MI_%02X", &commonInfo->Vid, &commonInfo->Pid, &commonInfo->MI) < 2)
				USBWRNN("Failed scanning vid/pid into common info.");
			break;
		case 2:	// InstanceID
			strcpy_s(commonInfo->InstanceID, sizeof(commonInfo->InstanceID), chLast);
			break;
		default:
			USBWRNN("Unknown device instance id element: %s.", chLast);
			break;
		}

		pos++;
		chLast = chNext;
	}

	if (commonInfo->Vid != UINT_MAX)
		commonInfo->Vid &= 0xFFFF;

	if (commonInfo->Pid != UINT_MAX)
		commonInfo->Pid &= 0xFFFF;

	if (commonInfo->MI != UINT_MAX)
		commonInfo->MI &= 0x7F;
}
Esempio n. 7
0
String String::ToUpper() const
{
	MUTEX_LOCK(str_mutex);

	String strRet(this->str_szBuffer);
#ifdef SCRATCH_NO_UTF8
#if WINDOWS
	int len = strlen(this->str_szBuffer);
	_strupr_s(strRet.str_szBuffer, len + 1);
#else
	strupr(strRet.str_szBuffer);
#endif
#else
	utf8upr(strRet.str_szBuffer);
#endif
	return strRet;
}
Bool Find3DCoat_win()
{
#if defined _WIN32 || defined _WIN64
    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
	PROCESSENTRY32 pe;
	if(!hSnapshot)return false;	
	pe.dwSize = sizeof(pe);
	for(int i = Process32First(hSnapshot, &pe); i; i = Process32Next(hSnapshot, &pe))
	{
		HANDLE hModuleSnap = NULL;
		MODULEENTRY32 me;
		hModuleSnap = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, pe.th32ProcessID);
		if(hModuleSnap == (HANDLE) -1)continue;
		me.dwSize = sizeof(MODULEENTRY32);
		if(Module32First(hModuleSnap, &me))
		{
			do
			{
				char temp[MAX_PATH];
				char *pMBBuffer = (char *)malloc(MAX_PATH);
				wcstombs(pMBBuffer, me.szExePath, MAX_PATH);

				strcpy_s(temp, MAX_PATH, pMBBuffer);
				_strupr_s(temp, MAX_PATH);
				int p = (int)strlen(temp);
				char c = 0;
				while(c != '\\' && c != '/' && p != 0)
				{
					c = temp[p--];
				}
				char* s = temp + p;
				strupr(s);
				if(strstr(s,"3D-COAT"))
				{
					return true;
				}
				break;
			}while(Module32Next(hModuleSnap, &me));
		}
	}
	CloseHandle(hSnapshot);
#endif
	return false;
}
/* construct username from the HTTP header */
static void construct_username(sspi_auth_ctx* ctx)
{
	/* removing the domain part from the username */
	if (ctx->crec->sspi_omitdomain) {
		char *s = strchr(ctx->scr->username, '\\'); 

		if (s)
			ctx->scr->username = s+1;
	}

	if (ctx->crec->sspi_usernamecase == NULL) {
	}
	else if (!lstrcmpi(ctx->crec->sspi_usernamecase, "Lower")) {
		_strlwr_s(ctx->scr->username, strlen(ctx->scr->username)+1);
	}
	else if (!lstrcmpi(ctx->crec->sspi_usernamecase, "Upper")) {
		_strupr_s(ctx->scr->username, strlen(ctx->scr->username)+1);
	};
}
Esempio n. 10
0
int CExpressionCaculator::AddFaction(const char * FactionName, int ParaCount,INT_PTR FnParam,FactionFN * faction)
{
	CFaction * pFaction=m_FactionList.GetObject(FactionName);
	if(pFaction==NULL)
	{
		UINT ID=m_FactionList.NewObject(&pFaction,FactionName);
		if(ID)
		{
			pFaction->ID=ID;
			strncpy_s(pFaction->FnName,MAX_IDENTIFIER_LENGTH+1,FactionName,MAX_IDENTIFIER_LENGTH);
			_strupr_s(pFaction->FnName,MAX_IDENTIFIER_LENGTH);
			pFaction->ParaCount=ParaCount;
			pFaction->FnParam=FnParam;
			pFaction->Fn=faction;
			return 0;
		}

		return 2;
	}	

	return 1;	
}
Esempio n. 11
0
int CExpressionCaculator::AddVariable(const char * VarName,int type, double value,const char * StrValue)
{	
	CVariable * pVar=m_VarList.GetObject(VarName);
	if(pVar==NULL)
	{
		UINT ID=m_VarList.NewObject(&pVar,VarName);
		if(ID)
		{
			pVar->ID=ID;
			strncpy_0(pVar->name,MAX_IDENTIFIER_LENGTH+1,VarName,MAX_IDENTIFIER_LENGTH);
			_strupr_s(pVar->name,MAX_IDENTIFIER_LENGTH);
			pVar->type=type;
			pVar->value=value;
			if(StrValue)
				pVar->StrValue=StrValue;
			return 0;
		}

		return 2;
	}	
	return 1;
}
Esempio n. 12
0
	AString aupper(const AString& string)
	{
		AString result = string.Buffer();
		_strupr_s((char*)result.Buffer(), result.Length() + 1);
		return result;
	}
Esempio n. 13
0
// Establish an Oracle DSN.  Oracle does not have a constant name, but rather
// a formulated one based on installed instance.  We'll look for the substrings
// "Oracle" and "10g", unless the user has overridden this pattern using
// the "odbcoracledriver" environment variable.
void OdbcConnectionUtil::SetupOracleDSN()
{
    char driverDesc[1024];
    char driverAttrs[1024];
    theOracleDriverName[0] = '\0';
	char teststr[1024];
	BOOL ret = false;
	SQLRETURN rc = SQL_ERROR;
    m_SetupOracleDSNdone = true;

    SQLHENV sqlenv = SQL_NULL_HENV;
    rc = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HENV, &sqlenv);
    if ( SQLRETURN_OK(rc) )
        rc = SQLSetEnvAttr(sqlenv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, SQL_IS_INTEGER);

    if ( SQLRETURN_OK(rc) )
    {
        SQLUSMALLINT direction = SQL_FETCH_FIRST;
        SQLSMALLINT driverDescLength = 0;
        SQLSMALLINT driverAttrsLength = 0;
        do
        {
            driverDescLength = 0;
            driverAttrsLength = 0;
            rc = SQLDrivers(sqlenv, direction, (SQLCHAR *) driverDesc, (SQLSMALLINT) sizeof(driverDesc), &driverDescLength,
                (SQLCHAR *) driverAttrs, (SQLSMALLINT) sizeof(driverAttrs), &driverAttrsLength);
            if (SQLRETURN_OK(rc))
            {
                #ifdef WIN32
                #pragma message("TODO: update this with each Oracle version update")
                #endif
                if (NULL != strstr(driverDesc, "Oracle") && (NULL != strstr(driverDesc, "10") || NULL != strstr(driverDesc, "11")))
                    strcpy(theOracleDriverName, driverDesc);
            }
            direction = SQL_FETCH_NEXT;
        }
        while ( SQLRETURN_OK(rc) && SQL_NO_DATA != rc && '\0' == theOracleDriverName[0] );
	    
        if (m_SetupValues->PropertyExist( L"enableOracleSetup" ))
	    {
		    FdoStringP pValue = m_SetupValues->GetPropertyValue( L"enableOracleSetup" );
		    if (pValue != L"true")
			    return;
	    }
        if (SQL_NO_DATA == rc)
            rc = SQL_SUCCESS;
		direction = SQL_FETCH_FIRST;
		FdoStringP pDSNOracle = m_SetupValues->GetPropertyValue( L"DSNOracle");
		while(SQLRETURN_OK(SQLDataSources(sqlenv, direction, (SQLCHAR *)teststr, sizeof(teststr), &driverAttrsLength, (SQLCHAR *)driverDesc, sizeof(driverDesc), &driverDescLength)))
		{
			direction = SQL_FETCH_NEXT;
			if (pDSNOracle == (FdoStringP)teststr)
			{
				SQLFreeHandle(SQL_HANDLE_ENV, sqlenv);
				return;
			}
		}
    }
    if (SQLRETURN_OK(rc) && '\0' != theOracleDriverName[0])
    {
        char* datastoreUpper = driverDesc;
        sprintf(datastoreUpper, "%ls", (FdoString*) UnitTestUtil::GetEnviron("datastore", L""));
        (void) _strupr_s(datastoreUpper, 1024);

        sprintf ( teststr, "DSN=%s%cDescription=Oracle DSN for FDO ODBC provider%cServerName=%s%cUserID=%s%c%c", (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"DSNOracle"), '\0',
            '\0', (const char*)(FdoStringP)m_SetupValues->GetPropertyValue( L"serviceOracle" ), '\0', datastoreUpper, '\0', '\0', '\0');
		ret = SQLConfigDataSource (NULL, ODBC_ADD_DSN, theOracleDriverName, teststr);
    }

    if (!SQLRETURN_OK(rc))
    {
    	SQLSMALLINT cRecNmbr = 1;
	    UCHAR		szSqlState[MAX_PATH] = "";
	    UCHAR 	 	szErrorMsg[MAX_PATH] = "";
	    SDWORD		pfNativeError = 0L;
	    SWORD	 	pcbErrorMsg = 0;

		rc = SQLGetDiagRec(SQL_HANDLE_ENV, sqlenv, 1, szSqlState, &pfNativeError, szErrorMsg, MAX_PATH-1, &pcbErrorMsg);
        printf("%.200s\n", (char *)szErrorMsg);
        throw FdoException::Create (L"Oracle DSN setup failed");
    }
	if (sqlenv != SQL_NULL_HENV)
		SQLFreeHandle(SQL_HANDLE_ENV, sqlenv);
    if (!ret )
    {
        DWORD error;
        WORD count;
        SQLInstallerError (1, &error, teststr, sizeof (teststr), &count);
        printf (teststr);
        throw FdoException::Create (L"Oracle DSN setup failed");
    }

    if ('\0' == theOracleDriverName[0])
        throw FdoException::Create (L"Oracle DSN setup failed");
}
Esempio n. 14
0
bool CPeakObj::open( const char *szFileName, unsigned long flags )
{
    const char *p;
    uint32_t busspeed = 125;
    uint16_t btr0btr1 = 0x031C;
    char szDrvParams[ MAX_PATH ];
    int port;
    int irq;
    int hwtype = 0;
    char *next_token = NULL;


    // Save flags
    m_initFlag = flags;

    // save parameter string and convert to upper case
#ifdef WIN32
    strncpy_s( szDrvParams, sizeof( szDrvParams ), szFileName, MAX_PATH );
    _strupr_s( szDrvParams );
#else
    strncpy( szDrvParams, szFileName, MAX_PATH );
    _strupr( szDrvParams );
#endif


    // Initiate statistics
    m_stat.cntReceiveData = 0;
    m_stat.cntReceiveFrames = 0;
    m_stat.cntTransmitData = 0;
    m_stat.cntTransmitFrames = 0;

    m_stat.cntBusOff = 0;
    m_stat.cntBusWarnings = 0;
    m_stat.cntOverruns = 0;


    // if open we have noting to do
    if ( m_bRun ) return true;

    // Boardtype
#ifdef WIN32
    p = strtok_s( (char * )szDrvParams, ";", &next_token );
#else
    p = strtok( (char * )szDrvParams, ";" );
#endif
    if ( NULL != p ) {

        if ( isalpha( *p ) ) {

            // Symbolic form
            int symidx = 0;
            while( -1 != peaksymtbl[ symidx ]. id ) {

                if ( NULL != strstr( peaksymtbl[ symidx ]. symname, p ) ) {
                    m_dwBrdType = peaksymtbl[ symidx ]. id;
                    m_bPnp = peaksymtbl[ symidx ].bPnp;
#ifdef WIN32
                    strcpy_s( m_dllName, sizeof( m_dllName ), peaksymtbl[ symidx ]. dllname );
#else
                    strcpy( m_dllName, peaksymtbl[ symidx ]. dllname );
#endif
                    break;
                }

                symidx++;

            }

        }
        else {

            // Numeric form
            m_dwBrdType = atoi( p );
            m_bPnp = peaksymtbl[ m_dwBrdType ].bPnp;
#ifdef WIN32
            strcpy_s( m_dllName, sizeof( m_dllName ), peaksymtbl[ m_dwBrdType ]. dllname );
#else
            strcpy_s( m_dllName, peaksymtbl[ m_dwBrdType ]. dllname );
#endif

        }

    }

    // Set default values from board-type
    m_channel = 0;
    port = -1;
    irq = -1;


    // Bus-Speed
#ifdef WIN32
    p = strtok_s( NULL, ";", &next_token );
#else
    p = strtok( NULL, ";" );
#endif
    if ( NULL != p ) {
        if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
            sscanf_s( p + 2, "%x", &busspeed );
#else
            sscanf( p + 2, "%x", &busspeed );
#endif
        }
        else {
            busspeed = atol( p );
        }
    }


    // Handle busspeed
    switch ( busspeed ) {

    case 5:
        btr0btr1 = 0x7F7F;
        break;

    case 10:
        btr0btr1 = 0x672F;
        break;

    case 20:
        btr0btr1 = 0x532F;
        break;

    case 50:
        btr0btr1 = 0x472F;
        break;

    case 100:
        btr0btr1 = 0x432F;
        break;

    case 125:
        btr0btr1 = 0x031C;
        break;

    case 250:
        btr0btr1 = 0x011C;
        break;

    case 500:
        btr0btr1 = 0x001C;
        break;

    case 800:
        btr0btr1 = 0x0016;
        break;

    case 1000:
        btr0btr1 = 0x0014;
        break;

    }


    if ( !m_bPnp ) {

        // hwtype
#ifdef WIN32
        p = strtok_s( NULL, ";", &next_token );
#else
        p = strtok( NULL, ";" );
#endif
        if ( NULL != p ) {
            if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
                sscanf( p + 2, "%x", &hwtype );
#else
                sscanf( p + 2, "%x", &hwtype );
#endif
            }
            else {
                hwtype = atoi( p );
            }
        }

        // port
#ifdef WIN32
        p = strtok_s( NULL, ";", &next_token );
#else
        p = strtok( NULL, ";" );
#endif
        if ( NULL != p ) {
            if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
                sscanf( p + 2, "%x", &port );
#else
                sscanf( p + 2, "%x", &port );
#endif
            }
            else {
                port = atoi( p );
            }
        }


        // irq
#ifdef WIN32
        p = strtok_s( NULL, ";", &next_token );
#else
        p = strtok( NULL, ";" );
#endif
        if ( NULL != p ) {
            if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
                sscanf( p + 2, "%x", &irq );
#else
                sscanf( p + 2, "%x", &irq );
#endif
            }
            else {
                irq = atoi( p );
            }
        }

    }


    // channel
#ifdef WIN32
    p = strtok_s( NULL, ";", &next_token );
#else
    p = strtok( NULL, ";" );
#endif
    if ( NULL != p ) {
        if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
            sscanf( p + 2, "%x", &m_channel );
#else
            sscanf( p + 2, "%x", &m_channel );
#endif
        }
        else {
            m_channel = atoi( p );
        }
    }


    // Filter
#ifdef WIN32
    p = strtok_s( NULL, ";", &next_token );
#else
    p = strtok( NULL, ";" );
#endif
    if ( NULL != p ) {
        if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
            sscanf( p + 2, "%x", &m_Peak_filter );
#else
            sscanf( p + 2, "%x", &m_Peak_filter );
#endif
        }
        else {
            m_Peak_filter = atol( p );
        }
    }


    // Mask
#ifdef WIN32
    p = strtok_s( NULL, ";", &next_token );
#else
    p = strtok( NULL, ";" );
#endif
    if ( NULL != p ) {
        if ( ( NULL != strstr( p, "0x" ) ) || ( NULL != strstr( p, "0X" ) )  ) {
#ifdef WIN32
            sscanf( p + 2, "%x", &m_Peak_mask );
#else
            sscanf( p + 2, "%x", &m_Peak_mask );
#endif
        }
        else {
            m_Peak_mask = atol( p );
        }
    }


    switch ( m_dwBrdType ) {

    case 0:	// CAN DONGLE
        if ( !nDongleDriverUseCnt ) {

            // Initialize Driver DLL
            if ( !initialize( m_dllName, m_bPnp ) ) {

                // Failed to initialize
                return false;
            }
        }
        else if ( 1 == nDongleDriverUseCnt ) {
            // Only one instance allowed
            setLastError( CANAL_ERROR_ONLY_ONE_INSTANCE,
                          GetLastError(),
                          "PEAK CAN DONGLE accept only one instance");
            return false;
        }
        nDongleDriverUseCnt++;
        port = 0x378;
        irq = 7;
        break;

    case 1:	// CAN DONGLE PRO
        if ( !nDongleProDriverUseCnt ) {

            // Initialize Driver DLL
            if ( !initialize( m_dllName, m_bPnp ) ) {

                // Failed to initialize
                return false;
            }
        }
        else if ( 1 == nDongleProDriverUseCnt ) {
            // Only one instance allowed
            setLastError( CANAL_ERROR_ONLY_ONE_INSTANCE,
                          GetLastError(),
                          "PEAK CAN DONGLE PRO accept only one instance");
            return false;
        }
        nDongleProDriverUseCnt++;
        port = 0x378;
        irq = 7;
        break;

    case 2:	// ISA
        if ( !nIsaDriverUseCnt ) {

            // Initialize Driver DLL
            if ( !initialize( m_dllName, m_bPnp ) ) {

                // Failed to initialize
                return false;
            }

        }
        else if ( 1 == nIsaDriverUseCnt ) {
            // Only one instance allowed
            setLastError( CANAL_ERROR_ONLY_ONE_INSTANCE,
                          GetLastError(),
                          "PEAK CAN ISA accept only one instance");
            return false;
        }
        nIsaDriverUseCnt++;
        port = 0x300;
        irq = 10;
        break;

    case 3:	// PCI
        if ( !nPciDriverUseCnt ) {

            // Initialize Driver DLL
            if ( !initialize( m_dllName, m_bPnp ) ) {

                // Failed to initialize
                return false;
            }
        }
        else if ( 1 == nPciDriverUseCnt ) {
            // Only one instance allowed
            setLastError( CANAL_ERROR_ONLY_ONE_INSTANCE,
                          GetLastError(),
                          "PEAK CAN PCI accept only one instance");
            return false;
        }
        nPciDriverUseCnt++;
        break;

    case 4:	// PCI2
        if ( !nPci2DriverUseCnt ) {

            // Initialize Driver DLL
            if ( !initialize( m_dllName, m_bPnp ) ) {

                // Failed to initialize
                return false;
            }
        }
        else if ( 1 == nPci2DriverUseCnt ) {
            // Only one instance allowed
            setLastError( CANAL_ERROR_ONLY_ONE_INSTANCE,
                          GetLastError(),
                          "PEAK CAN PCI2 accept only one instance");
            return false;
        }
        nPci2DriverUseCnt++;
        break;

    case 5:	// USB
        if ( !nUSBDriverUseCnt ) {

            // Initialize Driver DLL
            if ( !initialize( m_dllName, m_bPnp ) ) {

                // Failed to initialize
                return false;
            }
        }
        else if ( 1 == nUSBDriverUseCnt ) {
            // Only one instance allowed
            setLastError( CANAL_ERROR_ONLY_ONE_INSTANCE,
                          GetLastError(),
                          "PEAK CAN USB accept only one instance");
            return false;
        }
        nUSBDriverUseCnt++;

        break;
    }

    // Init the device
    unsigned long rv;
    if ( m_bPnp ) {
        rv = m_procInitPnp( btr0btr1, ( m_initFlag & 1 ) );
        if ( PEAK_CAN_ERR_OK != rv ) {
            setLastError( CANAL_ERROR_INIT_FAIL,
                          rv,
                          "Init error (PCI): suberror is driver failure code");
            return false;
        }
    }
    else {
        rv = m_procInit( btr0btr1, ( m_initFlag & 1 ), hwtype, port, irq );
        if ( PEAK_CAN_ERR_OK != rv ) {
            setLastError( CANAL_ERROR_INIT_FAIL,
                          rv,
                          "Init error: suberror is driver failure code");
            return false;
        }
    }

    // Run run run .....
    // (otional (for hard - fellow - rockers) "to the hills..."
    m_bRun = true;

#ifdef WIN32

    // Start write thread
    DWORD threadId;
    if ( NULL ==
            ( m_hTreadTransmit = CreateThread(	NULL,
                                 0,
                                 (LPTHREAD_START_ROUTINE) workThreadTransmit,
                                 this,
                                 0,
                                 &threadId ) ) ) {
        // Failure
        setLastError( CANAL_ERROR_INIT_FAIL,
                      GetLastError(),
                      "Init error: Unable to create transmit thread");
        close();
        return false;
    }

    // Start read thread
    if ( NULL ==
            ( m_hTreadReceive = CreateThread(	NULL,
                                0,
                                (LPTHREAD_START_ROUTINE) workThreadReceive,
                                this,
                                0,
                                &threadId ) ) ) {
        // Failure
        setLastError( CANAL_ERROR_INIT_FAIL,
                      GetLastError(),
                      "Init error: Unable to create receive thread");
        close();
        return  false;
    }

    // Release the mutex
    UNLOCK_MUTEX( m_peakMutex );
    UNLOCK_MUTEX( m_receiveMutex );
    UNLOCK_MUTEX( m_transmitMutex );


#else // LINUX


    pthread_attr_t thread_attr;
    pthread_attr_init( &thread_attr );


    // Create the log write thread.
    if ( pthread_create( 	&m_threadId,
                            &thread_attr,
                            workThreadTransmit,
                            this ) ) {

        syslog( LOG_CRIT, "canallogger: Unable to create peakdrv write thread.");
        setLastError( CANAL_ERROR_INIT_FAIL,
                      GetLastError(),
                      "Init error: Unable to create transmit thread");
        rv = false;
        fclose( m_flog );
    }


    // Create the log write thread.
    if ( pthread_create( 	&m_threadId,
                            &thread_attr,
                            workThreadReceive,
                            this ) ) {

        syslog( LOG_CRIT, "canallogger: Unable to create peakdrv receive thread.");
        setLastError( CANAL_ERROR_INIT_FAIL,
                      GetLastError(),
                      "Init error: Unable to create receive thread");
        rv = false;
        fclose( m_flog );
    }


    // Release the mutex
    pthread_mutex_unlock( &m_ixxMutex );

#endif

    // We are open
    m_bOpen = true;

    return true;
}
Esempio n. 15
0
/****************************************************************************
* FillSymbolInfo *
*----------------*
*   Description:  
*       Fills in a SYM_INFO structure
****************************************************************************/
void FillSymbolInfo
(
SYM_INFO *psi,
DWORD_PTR dwAddr
)
{
    STATIC_CONTRACT_NOTHROW;
    STATIC_CONTRACT_GC_NOTRIGGER;
    STATIC_CONTRACT_CANNOT_TAKE_LOCK;
    
    if (!g_fLoadedImageHlp)
    {
        return;
    }

    LOCAL_ASSERT(psi);
    memset(psi, 0, sizeof(SYM_INFO));

    PLAT_IMAGEHLP_MODULE  mi;
    mi.SizeOfStruct = sizeof(mi);
    
    if (!_SymGetModuleInfo(g_hProcess, dwAddr, &mi))
    {
        strcpy_s(psi->achModule, _countof(psi->achModule), "<no module>");
    }
    else
    {
        strcpy_s(psi->achModule, _countof(psi->achModule), mi.ModuleName);
        _strupr_s(psi->achModule, _countof(psi->achModule));
    }

    CHAR rgchUndec[256];
    const CHAR * pszSymbol = NULL;

    // Name field of IMAGEHLP_SYMBOL is dynamically sized.
    // Pad with space for 255 characters.
    union
    {
        CHAR rgchSymbol[sizeof(PLAT_IMAGEHLP_SYMBOL) + 255];
        PLAT_IMAGEHLP_SYMBOL  sym;
    };

    __try
    {
        sym.SizeOfStruct = sizeof(PLAT_IMAGEHLP_SYMBOL);
        sym.Address = dwAddr;
        sym.MaxNameLength = 255;

        if (_SymGetSymFromAddr(g_hProcess, dwAddr, &psi->dwOffset, &sym))
        {
            pszSymbol = sym.Name;

            if (_SymUnDName(&sym, rgchUndec, COUNT_OF(rgchUndec)-1))
            {
                pszSymbol = rgchUndec;
            }
        }
        else
        {
            pszSymbol = "<no symbol>";
        }
    }
    __except (EXCEPTION_EXECUTE_HANDLER)
    {
        pszSymbol = "<EX: no symbol>";
        psi->dwOffset = dwAddr - mi.BaseOfImage;
    }

    strcpy_s(psi->achSymbol, _countof(psi->achSymbol), pszSymbol);
}