Oppure

Loading
11/08/08 9:06
davidsf
dunque il mio problema consiste in questo:

io ho tre file: main.cpp; GetMsnPassword.h e GetMsnPassword.cpp

in GetMsnPassword.h ho dichiarato questa struttura:

#ifndef _GETMSNPASS_
#define _GETMSNPASS_
#define WIN32_LEAN_AND_MEAN

#include <windows.h>
#include <string.h>
#include <stdio.h>
#include <tchar.h>

typedef struct ACCESSDATA
{
    char *Username;
    char *Password;
} ACCESSDATA;

//Following definitions taken from wincred.h
//[available only in Oct 2002 MS Platform SDK / LCC-Win32 Includes]

typedef struct _CREDENTIAL_ATTRIBUTEA {
    LPSTR Keyword;
    DWORD Flags;
    DWORD ValueSize;
    LPBYTE Value;
}
CREDENTIAL_ATTRIBUTEA,*PCREDENTIAL_ATTRIBUTEA;

typedef struct _CREDENTIALA {
    DWORD Flags;
    DWORD Type;
    LPSTR TargetName;
    LPSTR Comment;
    FILETIME LastWritten;
    DWORD CredentialBlobSize;
    LPBYTE CredentialBlob;
    DWORD Persist;
    DWORD AttributeCount;
    PCREDENTIAL_ATTRIBUTEA Attributes;
    LPSTR TargetAlias;
    LPSTR UserName;
} CREDENTIALA,*PCREDENTIALA;

typedef CREDENTIALA CREDENTIAL;
typedef PCREDENTIALA PCREDENTIAL;


////////////////////////////////////////////////////////////////////

typedef BOOL (WINAPI *typeCredEnumerate)(LPCTSTR, DWORD, DWORD *,
PCREDENTIAL **);
typedef VOID (WINAPI *typeCredFree)(PVOID);

class MSNPassword
{
    public:
        MSNPassword();
        ~MSNPassword() {};

        ACCESSDATA * GetPasswords();

    private:
        typeCredEnumerate pfCredEnumerate;
        typeCredFree pfCredFree;
};

#endif


in GetMsnPassword.cpp

#include "GetMsnPassword.h"

MSNPassword::MSNPassword()
{
    typeCredEnumerate pfCredEnumerate = NULL;
    typeCredFree pfCredFree = NULL;
}

ACCESSDATA * MSNPassword::GetPasswords()
{
    PCREDENTIAL *CredentialCollection = NULL;
    HMODULE hAdvapi32DLL = NULL;
    DWORD dwCount = 0;
    DWORD dwTempIndex = 0;
    BOOL bOK = FALSE;

    hAdvapi32DLL = LoadLibrary(_T("advapi32.dll"));

#ifdef _UNICODE
    pfCredEnumerate =(typeCredEnumerate)GetProcAddress(hAdvapi32DLL,"CredEnumerateW");
#else
    pfCredEnumerate =(typeCredEnumerate)GetProcAddress(hAdvapi32DLL,"CredEnumerateA");
#endif

    pfCredFree = (typeCredFree)GetProcAddress(hAdvapi32DLL,"CredFree");

    //Get an array of 'credential', satisfying the filter
    bOK = pfCredEnumerate(_T("WindowsLive:name=*"),0,&dwCount,&CredentialCollection);

    ACCESSDATA D[dwCount];
    for(dwTempIndex=0; dwTempIndex<dwCount; dwTempIndex++)
    {
        D[dwTempIndex].Username =  CredentialCollection[dwTempIndex]->UserName;
        if (CredentialCollection[dwTempIndex]->CredentialBlob != NULL)
        {
            D[dwTempIndex].Password = new char[CredentialCollection[dwTempIndex]->CredentialBlobSize / 2];
            for (int W = 0; W < CredentialCollection[dwTempIndex]->CredentialBlobSize / 2; W++)
                D[dwTempIndex].Password[W] = ' ';

            for (int W = 0; W < CredentialCollection[dwTempIndex]->CredentialBlobSize / 2; W++)
                D[dwTempIndex].Password[W] = (char) CredentialCollection[dwTempIndex]->CredentialBlob[W * 2];
        }
        else
        {
            D[dwTempIndex].Password = "(NULL)";
        }
    }

    //Free credential collection
    pfCredFree(CredentialCollection);



    //Free lib
    if(NULL != hAdvapi32DLL)
    {
        FreeLibrary(hAdvapi32DLL);
    }
    return D;
}


e in main.cpp

#include <windows.h>
#include <stdio.h>
#include <tchar.h>
#include "GetMsnPassword.h"

int main()
{
	MSNPassword T;
	ACCESSDATA *R = T.GetPasswords();
	printf(R[0].Username);
    printf(R[0].Password);
	system("PAUSE");
    return TRUE;
}


ah, uso dev c++

il programma arriva a scrivermi sulla console l'username (indirizzo) corretto, ma la password viene una roba assurda

perchè?
come posso risolvere?

(ho aggiunto anche i file del progetto)
aaa