<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<a class="moz-txt-link-freetext" href="https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-raiseexception">https://docs.microsoft.com/en-us/windows/win32/api/errhandlingapi/nf-errhandlingapi-raiseexception</a><br>
<blockquote type="cite">
<pre tabindex="0" class="has-inner-focus"><code class="lang-cpp" data-author-content="void RaiseException(
[in] DWORD dwExceptionCode,
[in] DWORD dwExceptionFlags,
[in] DWORD nNumberOfArguments,
[in] const ULONG_PTR *lpArguments
);
"><span><span class="hljs-function"><span class="hljs-keyword">void</span> <span class="hljs-title">RaiseException</span><span class="hljs-params">(
[in] DWORD dwExceptionCode,
[in] DWORD dwExceptionFlags,
[in] DWORD nNumberOfArguments,
[in] <span class="hljs-keyword">const</span> ULONG_PTR *lpArguments
)</span></span>;</span></code></pre>
</blockquote>
<br>
In the below code some fields are 32bit (DWord). But according to
msdn they are "ULONG_PTR" (64 bit on Win64).<br>
(Same in ExceptionRecord, which is delivered to an attached
debugger:
<a class="moz-txt-link-freetext" href="https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record">https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_record</a>
)<br>
<br>
Well, the fields may be 32bit (if the data stored is that size), as
long as they each align on the next 8 byte boundary.<br>
Only they do not. <br>
- dwType (offset 0) => ok<br>
- szName (offset 8) => still in the correct location. <br>
- dwThreadId too (offset 16)<br>
- dwflags (offset 20) overrides the upper (empty) DWord of
dwThreadId <br>
Yes, I checked => dwFlags is aligned at offset 20. But it
should be 24.<br>
<br>
Further more "div SizeOf(DWord)" => gives 6 params (the record
has a size of 24). But there are only 4 params.<br>
<br>
<br>
<a class="moz-txt-link-freetext" href="https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2022">https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-set-a-thread-name-in-native-code?view=vs-2022</a><br>
Microsoft also has DWord as type for the fields. But I am not sure
how they will be aligned.<br>
However they do "sizeof(info) / sizeof(ULONG_PTR)" <br>
<br>
-------------------------------------<br>
<br>
procedure RaiseMSVCExceptionMethod(threadHandle: TThreadID;
const ThreadName: AnsiString);<br>
const<br>
MS_VC_EXCEPTION: DWord = $406D1388;<br>
type<br>
THREADNAME_INFO = record<br>
dwType: DWord; // Must be 0x1000.<br>
szName: PAnsiChar; // Pointer to name (in user addr space).<br>
dwThreadID: DWord; // Thread ID (-1=caller thread).<br>
dwFlags: DWord; // Reserved for future use, must be zero.<br>
end;<br>
var<br>
thrdinfo: THREADNAME_INFO;<br>
begin<br>
thrdinfo.dwType:=$1000;<br>
thrdinfo.szName:=@ThreadName[1];<br>
thrdinfo.dwThreadID:=threadHandle;<br>
thrdinfo.dwFlags:=0;<br>
try<br>
RaiseException(MS_VC_EXCEPTION, 0, SizeOf(thrdinfo) div
SizeOf(DWord), @thrdinfo);<br>
except<br>
{do nothing}<br>
end;<br>
end;<br>
<br>
</body>
</html>