#### Archived

This topic is now archived and is closed to further replies.

# Question On SendMessage

This topic is 5206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

SendMessage(hList, LB_ADDSTRING|LB_INSERTSTRING, 0, dLetters + ":"); How do I get my array and : to output into the ListBox? Also thanks to everyone for the help on these forums.

##### Share on other sites
I'll assume dLetters is a char array...

char cString[255];for (index = 0; index < (the number of elements in your array), index++){    sprintf(cString, "%c:", dLetters[index]);    SendMessage(hList, LB_ADDSTRING, 255, (LPARAM)(LPCSTR)cString);}

[edited by - Programmer One on November 18, 2003 12:07:52 PM]

##### Share on other sites
Humm now its come down to a logic issue.
case  ID_DRIVE_GETDRIVEINFORMATION:for(int index= 0; index < 26; index++){    drive = GetLogicalDrives();    if(drive&(1<<(index)))    {	strncpy(cString, &dLetters[index],1);	driveT = GetDriveType(cString);	switch(driveT)		{		   case DRIVE_UNKNOWN:		   driveT2 = "UNKNOWN";		   break;		   case DRIVE_NO_ROOT_DIR:		   driveT2 = "NOROOTDIR";		   break;		   case DRIVE_REMOVABLE:		   driveT2 = "REMOVABLE";		   break;		   case DRIVE_FIXED:		   driveT2 = "FIXED";		   break;		   case DRIVE_REMOTE:		   driveT2 = "REMOTE";		   break;		   case DRIVE_CDROM:		   driveT2 = "CDROM";		   break;		   case DRIVE_RAMDISK:		   driveT2 = "RAMDISK";		   break;		   default:		   break;                   }   strcat(cString,"  ");   strcat(cString,driveT2);  SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)(LPCSTR)cString);    }}break;

that is the case

HWND hList;
DWORD drive;
LPCTSTR driveT2;
UINT driveT;
char cString[3];
char dLetters[]={''A'',''B'',''C'',''D'',''E'',''F'',''G'',''H'',''I'',''J'',''K'',''L'',''M'',''N'',''O'',''P'',''Q'',''R'',''S'',''T'',''U'',''V'',''W'',''X'',''Y'',''Z''};

##### Share on other sites
Oops I thought I posted this. The Problem is its outputting the first drive C and its outputting the type but its outputting the wrong type and then its not getting d for some odd reason though initially it knows d is there also as the DWORD is 12 meaning 1100.

##### Share on other sites
I think the problem is that cString isn''t being cleared, how could I clear a char[3]? Its probably something simple, well I know it is but I can''t seem to get it to accept anything.

##### Share on other sites
An immediate problem is that strncpy does not place a terminating null in your string so you will find that strcat just keep appending text to the end of your buffer.

If you want to clear the whole thing you can use memset. Otherwise just add this line after the strncpy:

cString[1] = 0;

"Absorb what is useful, reject what is useless, and add what is specifically your own." - Lee Jun Fan

##### Share on other sites
thanks a mil that fixed it