Exemple #1
0
bool J2534_API::selectLibrary(std::string libPath)
{
	if (!libPath.size()) return false;
	void *newJ2534LIB = NULL;
	newJ2534LIB = dlopen( libPath.c_str(), RTLD_LAZY | RTLD_GLOBAL );	// RTLD_GLOBAL ???
	if (newJ2534LIB)
	{
		// Check if library is a valid J2534-library:
		if (!dlsym( newJ2534LIB, "PassThruConnect" ) || !dlsym( newJ2534LIB, "PassThruDisconnect" ))
		{
#ifdef __J2534_API_DEBUG__
			std::cout << "J2534interface::selectLibrary(): Error: the library doesn't provide the PassThruConnect(), and/or PassThruDisconnect() mehtods !\n";
			if (dlclose( newJ2534LIB ))
				std::cout << "J2534interface::selectLibrary(): dlclose() failed with error " << dlerror() << "\n";
#else
			dlclose( newJ2534LIB );
#endif
			return false;
		}
		// Check API-version of the library:
		if (!dlsym( newJ2534LIB, "PassThruOpen" ) || !dlsym( newJ2534LIB, "PassThruClose" ))
			_api_version = J2534_API_v0202;
		else
			_api_version = J2534_API_v0404;
		// Close old library:
		if (_J2534LIB)
		{
#ifdef __J2534_API_DEBUG__
			if (dlclose( _J2534LIB ))
				std::cout << "J2534interface::selectLibrary(): dlclose() failed with error " << dlerror() << "\n";
#else
			dlclose( _J2534LIB );
#endif
		}
		// Save data:
		_J2534LIB = newJ2534LIB;
		_lib_path = libPath;
		assignJ2534fcns();
	}
#ifdef __J2534_API_DEBUG__
	else
		std::cout << "J2534interface::selectLibrary(): dlopen() failed with error " << dlerror() << "\n";
#endif
	return newJ2534LIB;
}
Exemple #2
0
bool J2534_API::selectLibrary(std::string libPath)
{
	if (!libPath.size()) return false;
	HINSTANCE newJ2534LIB = NULL;
	newJ2534LIB = LoadLibraryA( libPath.c_str() );
	if (newJ2534LIB)
	{
		// Check if library is a valid J2534-library:
		if (!GetProcAddress( newJ2534LIB, "PassThruConnect" ) || !GetProcAddress( newJ2534LIB, "PassThruDisconnect" ))
		{
#ifdef __J2534_API_DEBUG__
			std::cout << "J2534interface::selectLibrary(): Error: the library doesn't provide the PassThruConnect(), and/or PassThruDisconnect() mehtods !\n";
			if (!FreeLibrary( newJ2534LIB ))
				std::cout << "J2534interface::selectLibrary(): FreeLibrary() failed with error " << GetLastError() << "\n";
#else
			FreeLibrary( newJ2534LIB );
#endif
			return false;
		}
		// Check API-version of the library:
		if (!GetProcAddress( newJ2534LIB, "PassThruOpen" ) || !GetProcAddress( newJ2534LIB, "PassThruClose" ))
			_api_version = J2534_API_v0202;
		else
			_api_version = J2534_API_v0404;
		// Close old library:
		if (_J2534LIB)
		{
#ifdef __J2534_API_DEBUG__
			if (!FreeLibrary( _J2534LIB ))
				std::cout << "J2534interface::selectLibrary(): FreeLibrary() failed with error " << GetLastError() << "\n";
#else
			FreeLibrary( _J2534LIB );
#endif
		}
		// Save data:
		_J2534LIB = newJ2534LIB;
		_lib_path = libPath;
		assignJ2534fcns();
	}
#ifdef __J2534_API_DEBUG__
	else
		std::cout << "J2534interface::selectLibrary(): LoadLibrary() failed with error " << GetLastError() << "\n";
#endif
	return newJ2534LIB;
}