- int i_convert = WideCharToMultiByte(CP_ACP, 0, var.bstrVal,
- SysStringLen(var.bstrVal), NULL, 0, NULL, NULL);
- char *p_buf = (char *)alloca( i_convert+1 ); p_buf[0] = 0;
- WideCharToMultiByte( CP_ACP, 0, var.bstrVal,
- SysStringLen(var.bstrVal), p_buf, i_convert, NULL, NULL );
- SysFreeString(var.bstrVal);
- p_buf[i_convert] = '\0';
-
- string devname = string(p_buf);
-
- int dup = 0;
- /* find out if this name is already used by a previously found device */
- list<string>::const_iterator iter = devicelist.begin();
- list<string>::const_iterator end = devicelist.end();
- while ( iter != end )
- {
- if( 0 == (*iter).compare(0, devname.size(), devname) )
- ++dup;
- ++iter;
- }
- if( dup )
- {
- /* we have a duplicate device name, append a sequence number to name
- to provive a unique list back to the user */
- char seq[16];
- sprintf(seq, " #%d", dup);
- devname.append(seq);
- }
- devicelist.push_back( devname );
+ char *p_buf = FromWide( var.bstrVal );
+ string devname = string(p_buf);
+ free( p_buf) ;
+
+ int dup = 0;
+ /* find out if this name is already used by a previously found device */
+ list<string>::const_iterator iter = devicelist.begin();
+ list<string>::const_iterator end = devicelist.end();
+ string ordevname = devname ;
+ while ( iter != end )
+ {
+ if( 0 == (*iter).compare( devname ) )
+ { /* devname is on the list. Try another name with sequence
+ number apended and then rescan until a unique entry is found*/
+ char seq[16];
+ snprintf(seq, 16, " #%d", ++dup);
+ devname = ordevname + seq;
+ iter = devicelist.begin();
+ }
+ else
+ ++iter;
+ }
+ devicelist.push_back( devname );