|
Hi,
I have a few thread questions
Would anyone know why someone would use _beginthreadex instead of CreateThread or visa versa
What is the difference between The Value return from GetCurrentthreadId and GetCurrentThread
In processing my DLL ATTACH_THREAD message I am able to get the threadid of the thread being created but not the thread
handle The GetCurrentthread API returns -1
Can I get the Thread handle if I have the the thread id
Thankx
|
|
|
|
|
ForNow wrote: _beginthreadex instead of CreateThread or visa versa
_beginthreadex() internally calls CreateThread for creating thread. In addition to creating thread, it will perform some CRT initializations also. So if you want to call some CRT functions inside the new thread, its better to use the _beginthreadex() function.
ForNow wrote: The Value return from GetCurrentthreadId and GetCurrentThread
GetCurrentthreadId return the current thread ID where GetCurrentThread return the handle to current Thread.
ForNow wrote: handle The GetCurrentthread API returns -1
If you call the GetCurrentthread(), it will always return 0xfffffffe. Actually this is a pseudo handle to the current thread. This value can be used only in that thread. The GetCurrentProcess() also returns a similar value - 0xffffffff.
If you want to get the correct handle value, you need to use the DuplicateHandle() function
HANDLE hRealHandle = 0;
DuplicateHandle( GetCurrentProcess(),
GetCurrentThread(),
GetCurrentProcess(),
&hRealHandle,
0,
TRUE,
DUPLICATE_SAME_ACCESS );
|
|
|
|
|
|
If a message is simulated using SendInput(), is there a way in themessage handler to detect the simulated events?
For instance, if someone uses SendInput with MOUSEEVENTF_LEFTDOWN over my window, is there any way to know or are those messages indistinguishable?
|
|
|
|
|
Unfortunately you are correct that those messages are indistinguishable. SendInput() inserts the input messages directly into the kernel input stream. You can read one of my prior posts[^] regarding how SendInput is actually invoking a privileged system call. [^]
If there is a security reason as to why you want to block this function then the only way I can think of is a driver implementing a SYSENTER hook[^].
Best Wishes,
-David Delaune
|
|
|
|
|
Interesting.
I was afraid there wasn't a way to differentiate those.
Thanks for taking the time to assist.
|
|
|
|
|
Hello.
I am having trouble capturing the mouse wheel messages. Everything works except when WM_MOUSEWHEEL is called, the HIWORD of wParam (combination of WHEEL_DELTAs, positive value means wheel is moved away from the user, negative is towards) is always 0. What is the problem? I am using Visual Studio 2003 btw.
// mousehook.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "mousehook.h"
#define MAX_LOADSTRING 100
HHOOK MouseHook;
static LRESULT CALLBACK MouseProc(UINT nCode, WPARAM wParam, LPARAM lParam)
{
if(nCode < 0)
{
CallNextHookEx(MouseHook, nCode, wParam, lParam);
return 0;
}
int zDelta = ((short)HIWORD(wParam));
if(wParam == WM_MOUSEWHEEL) // This is called properly. I need to know which way the wheel moves, but zDelta is always 0. What could be the problem?
{
}
return CallNextHookEx(MouseHook, nCode, wParam, lParam);
}
int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
MouseHook = SetWindowsHookEx(WH_MOUSE_LL, (HOOKPROC)MouseProc, hInstance, 0);
MessageBox(0,"Press ok to unhook","Hooked",0);
UnhookWindowsHookEx(MouseHook);
return 0;
}
I would really appreciate it if someone helped me..please.
|
|
|
|
|
how can wParam be equal to WM_MOUSEWHEEL and, at same time, give you meaningful info about wheel delta?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
|
|
|
|
|
Sorry forgot to mention..
http://msdn2.microsoft.com/en-us/library/ms645617(VS.85).aspx[^]
wParam
The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.
so ((short)HIWORD(wParam)) should give me what i want, but it gives me 0 all the time.
|
|
|
|
|
sdfghjkqwer wrote: so ((short)HIWORD(wParam)) should give me what i want, but it gives me 0 all the time.
It's a sign thing. the HIWORD macro returns a WORD which is 16bit unsigned integer. The compiler is silently doing some sign extension/conversion magic for you, before casting to a short.
The document page you linked to has a (different) way of getting zDelta - why not use that method?
|
|
|
|
|
How? Please explain, I'm new to programming 
|
|
|
|
|
sdfghjkqwer wrote: How?
By reading the Remarks section.
"Love people and use things, not love things and use people." - Unknown
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Oh I tried that long time ago. It is the same thing as using ((short)HIWORD(wParam));
It doesn't work.
|
|
|
|
|
// Using this instead
SetWindowsHookEx(WH_MOUSE, ...
static LRESULT CALLBACK MouseProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if ((nCode==HC_ACTION) && (wParam==WM_MOUSEWHEEL)) {
MOUSEHOOKSTRUCTEX* pMH=(MOUSEHOOKSTRUCTEX*)lParam;
WPARAM param=pMH->mouseData;
short zDelta=(short)HIWORD(param);
TRACE("zDelta = %d\n",zDelta);
/*
Output in trace for wheely going up
zDelta = 120
Output in trace for wheely going down
zDelta = -120
*/
}
return CallNextHookEx(MouseHook, nCode, wParam, lParam);
}
<div class="ForumMod">modified on Monday, April 14, 2008 5:48 PM</div>
|
|
|
|
|
I cant find where MOUSEHOOKSTRUCTEX or TRACE are defined
is this it?
typedef struct {
MOUSEHOOKSTRUCT MOUSEHOOKSTRUCT;
DWORD mouseData;
} MOUSEHOOKSTRUCTEX, *PMOUSEHOOKSTRUCTEX;
what bout trace?
Thanks.
|
|
|
|
|
Oops, I forgot about that. Yep, I have
typedef struct {
MOUSEHOOKSTRUCT MOUSEHOOKSTRUCT;
DWORD mouseData;
} MOUSEHOOKSTRUCTEX, *PMOUSEHOOKSTRUCTEX;
The TRACE is just something to use in MFC apps. If you don't use MFC, just ignore it and use printf or something of the sort. I was just trying to demonstrate the value of zDelta and needed an output mechanism.
|
|
|
|
|
There are LOTS of utilities (executables) for mounting ISO files to drive letters, but I want to open and read the contents of an ISO file through some kind of library, not a separate EXE. Any way to do that? I don't mind mind mounting the ISO to a drive letter or directory, I just don't want to make the user do it manually.
|
|
|
|
|
You could add the ISO reading functionality to a DLL or COM Object and use it that way.
You'll probably have to write the ISO code yourself, but it's not too difficult and there is a full ISO spec on the web.
Google for ISO9660, Joliet, etc, here is the wikipedia[^] entry for example.
|
|
|
|
|
It's not that critical, just a "nice to have" for my app. Besides, if it was that easy, it seems like there would already be a free code library available for this. Heck, my boss may even be willing to pay a reasonable price for one.
|
|
|
|
|
Hi, I added code for supporting multiple languages and are suprised about the following behaviour of Windows XP.
I have an English Windows version and selected English (United Kingdom) as my user interface language, I verified this in Control Panel -> Regional and Language Options. The function GetUserDefaultUILanguage from kernel32.dll returns 0x0409 (ENU, United States) and GetSystemDefaultLangID returns 0x0809 (ENG, United Kingdom)... shouldn't they both return the same?
Thanks for help
/M
|
|
|
|
|
What does GetUserDefaultLangID() and GetThreadLocale() return? I've always used those.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Jim Crafton wrote: GetUserDefaultLangID()
A current user locale - formatting stuff mostly, like currency, and date/time. Can be set from Control Panel->"regional and language options"->"regional options" tab.
Jim Crafton wrote: GetThreadLocale()
The same as the user locale - only on per-thread basis. It can be set programmatically.
|
|
|
|
|
GetSystemDefaultLangID() returns the system locale. This is used to determine which code page is used for non-Unicode (aka "ANSI") text on a system. It can be changed (on XP) from the advanced tab on the "regional and language options" in Control Panel (probably needs to be rebooted before the change takes effect)
GetUserDefaultUILanguage()
returns the current UI language which can be set by a user if MUI pack is installed.
|
|
|
|
|
Thanks for the info. What I don't understand that if I detect the language according to MSDN[^] then I would detect the wrong language (in a case where both UK and US language resources are available for an application).
GetUserDefaultUILanguage() Win32 API: 0x0409 US English
GetSystemDefaultUILanguage() Win32 API: 0x0409 US English
GetSystemDefaultLangID() Win32 API: 0x0809 UK English
What would be the correct order in an application to check?
modified on Monday, April 14, 2008 12:21 PM
|
|
|
|
|
Moak wrote: What would be the correct order in an application to check?
I am not sure what you are trying to check from your application. The link you left points to the article explaining how MFC is choosing a satelite dll.
|
|
|
|