So Something like that ? (the functions of my .lib begins with imi_) :
void UMyCaptureComponent::SetImitationDirectory(FString targetName)
{
try {
UE_LOG(LogTemp, Warning, TEXT("SetImitationDirectory: %s"), *GetModelPath(targetName));
//add try and catch to check if the function of the .lib is loaded
if (!m_imiHandle)
imi_trans_delete(m_imiHandle);
strcpy_s(m_imiParams.voice_dir, TCHAR_TO_ANSI(*GetModelPath(targetName)));
imi_number_of_trans_handle(1);
m_imiHandle = 0;
/** Constructor for the zero delay method */
imi_trans_zd_new(m_imiHandle, &m_imiParams, mSampleRate, mSampleRate);
}
catch (const std::exception& e)
{
FString ErrorMessage = FString::Printf(TEXT("Exception caught: %s"), UTF8_TO_TCHAR(e.what()));
// Write error message to log file
FString LogFilePath = FPaths::ProjectLogDir() + TEXT("ExceptionLog.txt");
FFileHelper::SaveStringToFile(ErrorMessage, *LogFilePath);
UE_LOG(LogTemp, Error, TEXT("%s"), *ErrorMessage);
}
catch (...)
{
// Catch any other exceptions
FString ErrorMessage = TEXT("Unknown exception caught in SetImitationDirectory");
// Write error message to log file
FString LogFilePath = FPaths::ProjectLogDir() + TEXT("ExceptionLog.txt");
FFileHelper::SaveStringToFile(ErrorMessage, *LogFilePath);
UE_LOG(LogTemp, Error, TEXT("%s"), *ErrorMessage);
}
}