bonjour tout le monde,
je suis tonber sur un source qui permet de convertir un BSTR en chaîne ordinaire et vice-versa ? dans ces fonction il y a une multitude de fonction qui sont utilisé mais que je ne comprend pas tre bien meme avec l'aide ( en plus el est en anglais !)
voici le code :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
void BSTRtoASC (BSTR str, char * &strRet)
{
    if ( str != NULL )
   {
       unsigned long length = WideCharToMultiByte (CP_ACP, 0, str, SysStringLen(str),
                                            NULL, 0, NULL, NULL);
       strRet = new char[length];
        length = WideCharToMultiByte (CP_ACP, 0, str, SysStringLen(str),
                           reinterpret_cast <char *>(strRet), length, NULL, NULL);
        strRet[length] = '\0';
    }
}
 
void ASCtoBSTR (char * str, BSTR * strRet)
{
    if ( str != NULL )
    {
        unsigned long length = strlen(str);
        int ResultLength = MultiByteToWideChar (CP_ACP,MB_PRECOMPOSED,
                           reinterpret_cast <char *>(str),length,NULL,0);
        *strRet = SysAllocStringLen( NULL, ResultLength);
        MultiByteToWideChar (CP_ACP,MB_PRECOMPOSED,
                           reinterpret_cast <char *>(str),length,*strRet,ResultLength);
    }
}
jaimerai une petite explicatoin pour les fonction :
WideCharToMultiByte, reinterpret_cast, strRet, MultiByteToWideChar, SysAllocStringLen.

merci pour toute information