嵌入循环的代码构建并运行良好。尝试使用它构建它(MBCS中的VS10)在LinkEmbedManifest步骤失败,并出现link 1168错误。
WIN32_FIND_DATA da; // directory data
TCHAR *Path; // directory Pointer
HANDLE ds; // directory handle
int Listindex=0;
Path = "C:\\";
SetCurrentDirectory(Path);
Listindex=0
ds = FindFirstFile(TEXT("*"),&da);
do {
int index = SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, (WPARAM)Listindex, (LPARAM)&da);
SendDlgItemMessage(hwnd, IDC_LIST, LB_SETITEMDATA, (WPARAM)index, (LPARAM)Listindex);
Listindex+=1;
}
while( FindNextFile(ds,&da) != ERROR_NO_MORE_ITEMS);
FindClose(ds);
目的是列出C根中的目录。从LONG_PTR LRESULT隐式转换为带索引的int,并进一步使用LPARAM和WPARAM进行转换。如果用模块范围的decs替换它们会有什么不同吗? 或者改变循环的类型会更好吗?
答案 0 :(得分:0)
FWIW问题有这么多错误,难怪它被标记下来了。最大的问题是在整个da记录上测试ERROR_NO_MORE_ITEMS而不是da.cFileName,因此是无限循环:。
#include <windows.h>
#include <winnt.h>
#include "resource.h" //Listbox data
WIN32_FIND_DATA da; // directory data this will use stack memory as opposed to LPWIN32_FIND_DATA
TCHAR *driveIDptr;
char driveID;
HANDLE ds; // directory handle
BOOL CALLBACK DlgProc(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch(Msg)
{
case WM_INITDIALOG:
{
int listindex = 0;
//Populate List
driveIDptr = "C:\\*";
memset(&da, 0, sizeof(WIN32_FIND_DATA));
ds = FindFirstFile(driveIDptr, &da);
driveIDptr = "C:\\"; //Shocking, but costs less than a strcat in above find function
if (ds == INVALID_HANDLE_VALUE)
{
StringCchPrintf (pszDest, cbDest, TEXT("No directories found."));
return FALSE;
}
while (ds != INVALID_HANDLE_VALUE && ds)
{
if (FindNextFile(ds, &da) == FALSE) break;
if((da.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) && !(da.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM
|| da.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT || da.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE || da.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN )) {
strcpy (&driveID, (char *) driveIDptr);
strcat (&driveID, da.cFileName);
SendDlgItemMessage(hwnd, IDC_LIST, LB_ADDSTRING, (WPARAM)listindex, (LPARAM)&driveID);
SendDlgItemMessage(hwnd, IDC_LIST, LB_SETITEMDATA, (WPARAM)listindex, (LPARAM)listindex);
listindex+=1;
}
}
FindClose(ds);
//other Msg cases...