Use OutputDebugString with printf formating
1 void DebugDisplayFmt( const char *str, ... )
2 {
3 char buf[2048];
4
5 va_list ptr;
6 va_start(ptr,str);
7 vsprintf(buf,str,ptr);
8
9 ::OutputDebugString( buf );
10 }
11
12 //Use
13 int value = 123;
14 DebugDisplayFmt( "in %s(%d) : val = %d\n", __FILE__, __LINE__, value );
Return true for match, else false Retourn true en cas d'egalité sinon false
1 public static bool compare<T>(ICollection<T> tabA, ICollection<T> tabB) where T : IComparable
2 {
3 System.Diagnostics.Debug.Assert(tabA != null);
4 System.Diagnostics.Debug.Assert(tabB != null);
5
6 if ( tabA.Count != tabB.Count)
7 return false;
8
9 IEnumerator<T> enumA = tabA.GetEnumerator();
10 IEnumerator<T> enumB = tabB.GetEnumerator();
11 while ( enumA.MoveNext() && enumB.MoveNext() )
12 {
13 if ( enumA.Current.CompareTo(enumB.Current) != 0 )
14 return false;
15 }
16 return true;
17 }
Singleton template inplementation
1 public class Singleton<T> where T : new()
2 {
3 static T _instance = default(T);
4
5 protected Singleton()
6 {
7 }
8
9 public static T Instance
10 {
11 get
12 {
13 if (_instance == null)
14 {
15 _instance = new T();
16 }
17 return _instance;
18 }
19 }
20 }
21
22 public class MySingleton : Singleton<MySingleton>
23 {
24 public void hello() { Debug.WriteLine("Hello"); }
25 }
Rempli la liste des fichiers d'un repertoire et de ses sous-repertoire récusivement.
1 void scan( const std::wstring& path, const std::wstring& filter, std::vector<std::wstring> &list )
2 {
3 WIN32_FIND_DATA FindFileData;
4 HANDLE hFind;
5
6 std::wstring tmp = path + filter;
7 hFind = ::FindFirstFile( tmp.c_str(), &FindFileData);
8
9 if ( hFind == INVALID_HANDLE_VALUE )
10 {
11 throw Exception();
12 return ;
13 }
14
15 do
16 {
17 std::wstring filename = FindFileData.cFileName;
18 if ( filename == TEXT(".") )
19 continue;
20 if ( filename == TEXT("..") )
21 continue;
22 if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
23 scan( path + filename + TEXT("\\"), filter, list );
24 else
25 list.push_back( path + filename );
26
27 } while ( ::FindNextFile(hFind, &FindFileData) != 0 );
28 }
29
30 //Utilisation
31 std::map<std::wstring> list;
32 scan( TEXT("C:\\"), TEXT("*"), list ) ;
Fichier .ini dans le repertoire d'execution: [SECTION] key=value keyInt=123
1 char filename[MAX_PATH];
2 ::GetModuleFileName( NULL, filename, MAX_PATH-1);
3 string str = filename;
4 string path = str.substr( 0, str.find_last_of("\\") );
5 path += "\\config.ini";
6 char val[255];
7 ::GetPrivateProfileString( "SECTION", "key", "", val, sizeof(val), path.c_str() );
8 int iVal = ::GetPrivateProfileInt( "SECTION", "keyInt", -1, path.c_str() );
Pages : 1