Я удивлен, что код достигает строки, которую вы упомянули - возможно, просто удача - потому что у вас есть серьезные ошибки в другом месте. Это приведет к неопределенному поведению . Смотрите комментарии и исправления в приведенном ниже коде:
BOOL CALLBACK WindowFoundCB(HWND hwnd, char* param) {
char *strIn2 = (char*) param;
// char *strIte; // You are not actually allocating any memory here!
char strIte[256]; // This way, you have allocated 256 bytes for the Window name.
GetWindowText(hwnd, strIte, 256); // In the uncorrected version, this is UB!
if (IsWindowVisible(hwnd)){
idx++;
hwndCollection = (uint64_t *)realloc(hwndCollection,idx*sizeof(uint64_t));
hwndCollection[idx-1] = hwnd;
printf("**** get a window's number ****\n");
printf("----%d----%d\n",hwnd,hwndCollection[idx-1]);
// EDIT (1a)!
// The following line allocates pointers to strings, but no memory for the strings...
hwndTitlePtrCollection = (char**)realloc(hwndTitlePtrCollection,idx*sizeof(char*));
// Here, we allocate memory for the new string …
// EDIT (1b)!
hwndTitlePtrCollection[idx-1] = malloc(256 * sizeof(char));
// hwndTitlePtrCollection[idx-1] = strIte; // Wrong! This just copies the pointer...
strcpy(hwndTitlePtrCollection[idx-1], strIte); // ...this copies the contents.
printf("**** get a window's Title ****\n");
// this line if delete, runs OK. If exist, got stuck here
printf("----%s\n",hwndTitlePtrCollection[idx-1]);
}
return TRUE;
}
Попробуйте это (могут быть и другие ошибки, но давайте разберемся с этим)! Не стесняйтесь просить дальнейших объяснений и / или разъяснений.