salve a tutti, sono un neo programmatore in c++. Sviluppo in ambiente Win (Win XP) con DEVC++.
Ho il seguente problema :
ho definito la seguente classe:
private:
...
pciDevList_t *pciDevList;
unsigned int listSize;
public :
/* costruttore */
PciDev_C(void);
/* distruttore */
~PciDev_C(void);
...
unsigned int pciEnum();
void PciDev_C::addPciDevice(char *newPciDevName);
}
dove pciDevList e' una lista dinamica :
typedef struct pciDevList {
char *cpPciVenId;
char *cpPciDevId;
char *cpPciSubSysId;
char *cpPciRevId;
pciDevList *nextDev;
} pciDevList_t;
nel costruttore inizializzo la lista a null :
PciDev_C::PciDev_C(void){
pciDevList = new pciDevList_t;
pciDevList = NULL;
listSize = 0;
};
poi in enum vado a leggere le chiavi del reg per avere l'elenco dei dispositivi sul PCI:
unsigned int PciDev_C::pciEnum(){
...
char *lpName;
DWORD lValSize=MAX_KEY_NAME_LENGHT;
unsigned int idKey=0;
char lpBuffer[MAX_KEY_NAME_LENGHT];
DWORD nSize=MAX_KEY_NAME_LENGHT;
lpName = new char;
lpName = "a";
l_Error = RegOpenKeyEx (HKEY_LOCAL_MACHINE,cp_PciPath,0,KEY_READ,&hk_RetKey);
...
while(l_Error != ERROR_NO_MORE_ITEMS){
l_Error = RegEnumKeyEx (hk_RetKey,idKey++,lpName,&lValSize,NULL,NULL,NULL,NULL);
addPciDevice(lpName);
...
lValSize += sizeof(lpName);
}*/
while (pciDevList != NULL){
MessageBox(NULL,pciDevList->cpPciDevId,"nome",MB_ICONWARNING);
pciDevList = pciDevList->nextDev;
}
};
come vedete per ogni nome trovato chiavo la addPciDevice(lpName) che dovrebbe aggiungere il nome alla lista:
void PciDev_C::addPciDevice(char *newPciDevName){
pciDevList_t *newDev = new pciDevList_t;
pciDevList_t *lastPciDevList;
newDev->cpPciDevId = newPciDevName;
newDev->nextDev = NULL;
if (pciDevList == NULL){
pciDevList = newDev;
}
else {
lastPciDevList->nextDev = newDev;
}
lastPciDevList = newDev;
listSize++;
}
dico dovrebbe perche' in effetti sembra che tutti gli elemnti della lista vengano settati con il nome dell'ultimo dispositivo trovato... infatti quando alla fine enum ciclo sugli elementi della lista e li stampi con la message box ma sono tutti uguali!!!!
qual'e' l'inghippo????
ciao e grazie
dev75