NO

Author Topic: CreateThread  (Read 3328 times)

Offline John Z

  • Member
  • *
  • Posts: 841
CreateThread
« on: August 09, 2024, 11:54:28 PM »
Help - well hopefully

A program that uses a CreateThread function to show a dialog that allows the user to abort the processing of a perhaps long running operation works very well on three different i7 computers and on a Ryzen computer but when run on an i5 LG Gram it chokes and in one case hangs the program and in another crashes it.  In all cases of not invoking the CreateThread function the program runs perfectly fine on the i5 LG Gram no matter how many records are processed.

The attached project shows basically how I'm using CreateThread, perhaps I'm doing something fundamentally wrong.  The main.c simulates work in a loop. The escapedlg.c is exactly what the original main program uses...  BTW I ran the  sfc /scannow on the i5 LG and problem still manifests.

When the actual program crashed the system event log showed
Faulting module name: textinputframework.dll, version: 10.0.22621.3810, time stamp: 0xe148209c
Exception code: 0xc0000005

I could of course just do away with the user ability to abort but that is not learning anything...

John Z
 
« Last Edit: August 12, 2024, 08:21:29 AM by John Z »

Offline John Z

  • Member
  • *
  • Posts: 841
Re: CreateThread
« Reply #1 on: August 12, 2024, 08:26:08 AM »
I have figured out an interaction that causes the issue, and it is an easy fix.  What is unclear is why it is affected by the PC system it is running on with the i5 processor but not other several systems with i7 or AMD Ryzen processors.

Anyway don't invest time on this.  I'll post more later describing the 'fix' and what is/was happening.

John Z

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2112
Re: CreateThread
« Reply #2 on: August 22, 2024, 12:34:00 PM »
John try this version.
« Last Edit: August 22, 2024, 07:26:47 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline John Z

  • Member
  • *
  • Posts: 841
Re: CreateThread
« Reply #3 on: August 22, 2024, 11:20:17 PM »
Thanks frankie!

I'll give it a go, and study it as well.

John Z

Appreciate your time on this very much!

Offline Marco

  • Member
  • *
  • Posts: 44
Re: CreateThread
« Reply #4 on: August 23, 2024, 11:08:21 AM »
Hi guys,

just a little hint when using WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file. This is what Microsoft says:

member: cbWndExtra

Type: int

The number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA.

Link: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexa

Marco

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2112
Re: CreateThread
« Reply #5 on: August 23, 2024, 11:46:51 AM »
Hi guys,

just a little hint when using WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file. This is what Microsoft says:

member: cbWndExtra

Type: int

The number of extra bytes to allocate following the window instance. The system initializes the bytes to zero. If an application uses WNDCLASSEX to register a dialog box created by using the CLASS directive in the resource file, it must set this member to DLGWINDOWEXTRA.

Link: https://learn.microsoft.com/en-us/windows/win32/api/winuser/ns-winuser-wndclassexa

Marco
Thanks Marco what you outlined is important.
In our case we are copying our WNDCLASSEX from the system DLG class 32770:
Code: [Select]
GetClassInfoEx(NULL, MAKEINTRESOURCE(32770), &wcx)If you check in debug you'll see that the member cbWndExtra is correctly set to decimal 30 which is the defined value of DLGWINDOWEXTRA.
See winuser.h:
Code: [Select]
#define DLGWINDOWEXTRA 30
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline Marco

  • Member
  • *
  • Posts: 44
Re: CreateThread
« Reply #6 on: August 23, 2024, 01:14:57 PM »
Yep, when you ask GetClassInfoEx to retrieve information about a system dialog box class (32770), it correctly sets the value of the cbWndExtra member.

Mea culpa: I had not seen the function call in the .c file.

Marco