有谁知道为什么它不从路径中提取 mp3。szFile 是文件的完整路径。有没有更安全的方法来转换数据类型?
我是 C++ 编码的新手,我不知道如何很好地管理数据类型转换,我目前正在为我的项目使用 Visual Studio 2019
Node* Load(LPCWSTR szFile, Node* Song, HWND hWnd, std::string Album_, std::string Name, int a)
{
try
{
std::wstring ws(szFile);
std::string filename = std::string(ws.begin(), ws.end());
std::regex re("[a-zA-Z0-9]*.mp3");
std::smatch match;
std::regex_match (filename, match, re);
Song->Name = match.str(1);
if (a == 0)
{
if (Album_ != "")
{
std::string SQL_base_albumes = "INSERT INTO ALBUMES VALUES";
SQL_base_albumes += " " + Album_;
char* Error;
connection = sqlite3_exec(Database, SQL_base_albumes.c_str(), NULL, 0, &Error);
if (connection != SQLITE_OK)
{
std::string str(Error);
std::wstring Conversion = std::wstring(str.begin(), str.end());
LPCWSTR Convertido = Conversion.c_str();
::MessageBox(hWnd, Convertido, L"Error | Carga de MP3", NULL);
}
}
}
Cleanup(Song);
Song->ready = false;
if (SUCCEEDED(CoCreateInstance(CLSID_FilterGraph,
NULL,
CLSCTX_INPROC_SERVER,
IID_IGraphBuilder,
(void**)&Song->Graphs)))
{
Song->Graphs->QueryInterface(IID_IMediaControl, (void**)&Song->Controls);
Song->Graphs->QueryInterface(IID_IMediaEventEx, (void**)&Song->Events);
Song->Graphs->QueryInterface(IID_IBasicAudio, (void**)&Song->Basic);
Song->Graphs->QueryInterface(IID_IMediaSeeking, (void**)&Song->Seeking);
HRESULT Graphics = Song->Graphs->RenderFile(szFile, NULL);
if (SUCCEEDED(Graphics))
{
Song->ready = true;
if (Song->Seeking)
{
Song->Seeking->SetTimeFormat(&TIME_FORMAT_MEDIA_TIME);
Song->Seeking->GetDuration(&Song->duration);
if (a == 0)
{
std::string SQL_base_canciones = "INSERT INTO MUSICA VALUES";
Song->Album_p = Album_;
SQL_base_canciones += "('" + Song->Name + "','" + Album_ + "');";
char* Error_;
connection = sqlite3_exec(Database, SQL_base_canciones.c_str(), NULL, 0, &Error_);
if (connection != SQLITE_OK)
{
std::string str(Error_);
std::wstring Conversion = std::wstring(str.begin(), str.end());
LPCWSTR Convertido = Conversion.c_str();
::MessageBox(hWnd, Convertido, L"Error | Carga de MP3", NULL);
return NULL;
}
}
}
else
{
::MessageBox(hWnd, L"No ha sido posible cargar y establecer los tiempos de su MP3", L"Error | Carga de MP3", NULL);
}
}
else
{
::MessageBox(hWnd, L"No ha sido posible abrir el archivo seleccionado", L"Error | Carga de MP3", NULL);
}
}
else
{
::MessageBox(hWnd, L"No ha sido posible cargar su archivo.", L"Error | Carga de MP3", NULL);
}
return Song;
}
catch(...)
{
return NULL;
}
}