C++
MFC CFileDialog using filters
by paulorb on mar.20, 2017, under C++, MFC
This is a class that is commonly used when working with MFC dialogs,
Using CFileDialog consists of following steps:
1. Create an instance of CFileDialog
2. Set or Modify m_ofn structure.
3. Call DoModal function of CFileDialog
4. When DoModal returns, we can call GetPathName() function to retrieve the selected filename.
First lets create the simple CFiledialog
TCHAR szFilters[] = _T("Text Files (*.dat)|*.NC|Text Files (*.txt)|*.txt|All Files (*.*)|*.*||"); // Create an Open dialog; the default file name extension is ".my". CFileDialog fileDlg(TRUE, _T("txt"), _T("*.txt"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters, this); // Display the file dialog. When user clicks OK, fileDlg.DoModal() // returns IDOK. if (fileDlg.DoModal() == IDOK) { }
Now lets think about the filters, first example we will filter *.txt *.dat and *.* file formats:
TCHAR szFilters[] = _T("Doc Files (*.pdf;*.txt;*.dat)||")
This will be one item in the dropdown of the CFileDialog, if we want multiple items we can create something like this:
TCHAR szFilters[] = _T("Text Files (*.pdf;*.jpg)|*.pdf;*.jpg|") _T("PDF Files (*.pdf)|*.pdf||");
In this case we will have one item described as “Text files” with filter *.pdf;*.jpg and the second item on the dropdown will be described as “PDF Files” and will have a filter for *.pdf
Compatibilidade entre VS2012 C++ e Windows XP
by paulorb on mar.06, 2013, under C++
Existe problemas de compatibilidade em programas compilados no vs2012 quando tenta-se roda-los no XP. Inicialmente a Microsoft estabeleceu um requisito minimo para rodar programas feitos em vs2012 que era roda-los no Win Vista. Porem ela a pouco tempo publicou uma solucao para o problema de compatibilidade. Segue o Link abaixo:
http://blogs.msdn.com/b/vcblog/archive/2012/10/08/10357555.aspx
Remover Char de String em C++
by paulorb on jan.03, 2013, under C++
Achei uma funcao para remover um char de uma string e converti essa funcao para trabalhar com TCHAR ao inves de char podendo assim ser compilada tanto pra ASCII quanto UNICODE.
void RemoveChar(TCHAR *str, TCHAR garbage) { TCHAR *src, *dst; for (src = dst = str; *src != _T('\0'); src++) { *dst = *src; if (*dst != garbage) dst++; } *dst = _T('\0'); }
Debugging – Técnicas para facilitar sua vida – Parte 1
by paulorb on mai.16, 2012, under C++, Debug
LoadLibrary Falhou
by paulorb on abr.13, 2012, under C++
Como analisar problemas com o LoadLibrary. O LoadLibrary é umas das mais complexas APIs do Windows e por isso mesmo a Microsoft como formade facilitar o debug em casos do LoadLibrary falhar criou o “loader snaps” nos Debbuging Tools.
Como funciona: Voce deve instalar o debbuging tools
http://msdn.microsoft.com/en-us/windows/hardware/gg463009.aspx
Ai entao rode o gflags.exe e habilite o “Show Loader Snaps”.Rode o “WinDbg.exe” e execute a aplicação que você deseja analisar.No Log voce vera as DLLs sendo carregadas e as que não forem aparecerão tambem.
Referencias:http://blogs.msdn.com/b/junfeng/archive/2006/11/20/debugging-loadlibrary-failures.aspxhttp://blogs.msdn.com/b/mgrier/archive/2005/06/18/430402.aspx
Descobrindo funções exportadas e dependencias de importação em uma DLL
by paulorb on abr.13, 2012, under C++
Para descobrir as funções exportadas e as dependencias de uma DLL use o comando:
Dumpbin /exports NomeDaDLL.dll
Dumpbin /imports NomeDaDLL.dll
Referencias:
http://support.microsoft.com/kb/177429
http://stackoverflow.com/questions/3497301/what-exactly-means-error-invalid-ordinal
Bitwise em float e double
by paulorb on fev.15, 2012, under C++
Não da pra fazer normalmente veja o link abaixo.
Re-throw Exception sem criar objeto de Exception
by paulorb on fev.01, 2012, under C++, C++/CLI
Dica rápida: veja a situação abaixo
try{ //something }catch(Exception^ e) { return false; }
Se você não usa o Objeto tratador da exception então não DECLARE-O.
Solução:
try{ //something }catch(...) { return false; }
E se precisar passar a diante qualquer exception use:
try{ //something }catch(...) { throw; }
Referencia: http://msdn.microsoft.com/en-us/library/6dekhbbc(v=vs.80).aspx