1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::IO;
using namespace System::Text;
public ref class FichierINI
{
private:
System::String ^ filename;
[DllImport("kernel32")]
static long WritePrivateProfileString(
System::String ^ section,
System::String ^ key,
System::String ^ val,
System::String ^ filePath);
[DllImport("kernel32")]
static int GetPrivateProfileString(
System::String ^ section,
System::String ^ key,
System::String ^ def,
System::String ^ retVal,
int size,
System::String ^ filePath);
public:
FichierINI(System::String ^ fichier);
~FichierINI(void);
void EcrireCle(System::String ^ section, System::String ^ cle,
System::String ^ valeur);
System::String ^ LireCle(System::String ^ section,
System::String ^ cle);
};
// Constructeur
FichierINI::FichierINI(System::String ^ fichier)
{
this->filename = fichier;
if(!File::Exists(fichier))
{
FichierINI::EcrireCle("MYSQL","serveur","");
FichierINI::EcrireCle("MYSQL","port","");
FichierINI::EcrireCle("MYSQL","bd","");
FichierINI::EcrireCle("MYSQL","user","");
FichierINI::EcrireCle("MYSQL","password","");
FichierINI::EcrireCle("LDAP","serveur","");
FichierINI::EcrireCle("LDAP","port","");
FichierINI::EcrireCle("LDAP","baseDN","");
FichierINI::EcrireCle("LDAP","user","");
FichierINI::EcrireCle("LDAP","password","");
}
}
FichierINI::~FichierINI(void)
{ /* RIEN A FAIRE DANS LE DESTRUCTEUR */ }
void FichierINI::EcrireCle(System::String ^ section,System::String ^ cle,
System::String ^ valeur)
{
WritePrivateProfileString(section,cle,valeur,this->filename);
}
System::String ^ FichierINI::LireCle(System::String ^ section,
System::String ^ cle)
{
System::String ^ temp;
int i = GetPrivateProfileString(section,cle,"",temp,255, this->filename);
return temp->ToString;
} |
Partager