Archived

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

Gorf_Rules

Question On SendMessage

Recommended Posts

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 this post


Link to post
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

here is my header:


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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites