Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages
Started by Justin Ridge
Thu, 08 May 2003 13:43
FlashWindowEx, USER32.DLL on WinNT
Author: Justin Ridge
Date: Thu, 08 May 2003 13:43
Date: Thu, 08 May 2003 13:43
34 lines
2389 bytes
2389 bytes
Dear all,
My app uses the FlashWindowEx function. It works great when running on Win98 or Win2000. When the app runs on WinNT, I get the error "The procedure entry point FlashWindowEx could not be located in the dynamic link library USER32.DLL".
I understand that FlashWindowEx is not supported on WinNT, and my code checks for its availability (see below). However, this error occurs IMMEDIATELY when I start the app, i.e. way before FlashWindowEx would ever be called.
How can I get the app to start on WinNT?
Thanks!
JR
PS. The code I use to check for the availability of FlashWindowEx is below. It borrows heavily off code others have posted here. The mechanics of how the OS version is checked do not seem to be relevant, because the error occurs prior to this check being done.
// Is this WinNT or Win95?
OSVERSIONINFO ver;
ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
GetVersionEx(&ver);
bool newversion = false;
if (ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) { // Win9x
if ((ver.dwMajorVersion) == 4 && (ver.dwMinorVersion > 0))
newversion = true; // Win98
} else
if (ver.dwMajorVersion > 4)
newversion = true; // Win2000,XP
if (newversion) {
FLASHWINFO info = {sizeof(FLASHWINFO), 0};
info.hwnd = Application->Handle;
info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
info.uCount = 100;
FlashWindowEx(&info);
} else
FlashWindow(Application->Handle, true);
Re: FlashWindowEx, USER32.DLL on WinNT
Author: Ed Mulroy [TeamB]
Date: Thu, 08 May 2003 14:11
Date: Thu, 08 May 2003 14:11
66 lines
3302 bytes
3302 bytes
That is how it is supposed to work. When you call the function in your code
that generates a record in the executable saying that a function of that
name from that DLL is required. The Windows program loader will load any
required DLL's and fill in the address in every place their functions are
called. Because no matching function was found, no address value to place
into the code is available and the error is generated.
You might instead try doing something like the code I show below. It loads
the function address at runtime instead of relying on the program loader to
load it.
I used GetModuleHandle because that DLL should already be loaded. By using
that function instead of LoadLibrary you are freed from the need to call
FreeLibrary.
--------------
BOOL (WINAPI *FlashWindowExPtr)(PFLASHWINFO);
HINSTANCE user32_hinst = GetModuleHandle("USER32.DLL");
(FARPROC) FlashWindowExPtr =
GetProcAddress(user32_hinst, "FlashWindowEx");
if ((user32_hinst != NULL) && (FlashWindowExPtr != NULL))
{
FLASHWINFO info = {sizeof(FLASHWINFO), 0};
info.hwnd = Application->Handle;
info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
info.uCount = 100;
FlashWindowExPtr(&info);
}
else
{
FlashWindow(Application->Handle, true);
}
--------------
. Ed
> Justin Ridge wrote in message
> news:3eba5f0e$2@newsgroups.borland.com...
>
> My app uses the FlashWindowEx function. It works
> great when running on Win98 or Win2000. When the
> app runs on WinNT, I get the error "The procedure
> entry point FlashWindowEx could not be located in the
> dynamic link library USER32.DLL".
>
> I understand that FlashWindowEx is not supported on
> WinNT, and my code checks for its availability (see below).
> However, this error occurs IMMEDIATELY when I start the
> app, i.e. way before FlashWindowEx would ever be called.
>
> How can I get the app to start on WinNT?
>
> PS. The code I use to check for the availability of FlashWindowEx
> is below. ...
> :
> if (newversion) {
> FLASHWINFO info = {sizeof(FLASHWINFO), 0};
> info.hwnd = Application->Handle;
> info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
> info.uCount = 100;
> FlashWindowEx(&info);
> } else
> FlashWindow(Application->Handle, true);
Re: FlashWindowEx, USER32.DLL on WinNT
Author: Justin Ridge
Date: Thu, 08 May 2003 15:49
Date: Thu, 08 May 2003 15:49
73 lines
3764 bytes
3764 bytes
Ed, thanks for your reply. My app already looks for "plugins" and loads them at runtime, and I use a similar approach to yours for that. I didn't know if that would be a good idea (e.g. memory- or performance-wise) for a WinAPI call, but I guess it is! Thanks again.
"Ed Mulroy [TeamB]" <ed@mulroyREMOVETHESECHARS.org> wrote:
>That is how it is supposed to work. When you call the function in your code
>that generates a record in the executable saying that a function of that
>name from that DLL is required. The Windows program loader will load any
>required DLL's and fill in the address in every place their functions are
>called. Because no matching function was found, no address value to place
>into the code is available and the error is generated.
>
>You might instead try doing something like the code I show below. It loads
>the function address at runtime instead of relying on the program loader to
>load it.
>
>I used GetModuleHandle because that DLL should already be loaded. By using
>that function instead of LoadLibrary you are freed from the need to call
>FreeLibrary.
>
> --------------
> BOOL (WINAPI *FlashWindowExPtr)(PFLASHWINFO);
> HINSTANCE user32_hinst = GetModuleHandle("USER32.DLL");
>
> (FARPROC) FlashWindowExPtr =
> GetProcAddress(user32_hinst, "FlashWindowEx");
>
> if ((user32_hinst != NULL) && (FlashWindowExPtr != NULL))
> {
> FLASHWINFO info = {sizeof(FLASHWINFO), 0};
>
> info.hwnd = Application->Handle;
> info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
> info.uCount = 100;
> FlashWindowExPtr(&info);
> }
> else
> {
> FlashWindow(Application->Handle, true);
> }
> --------------
>
>.. Ed
>
>> Justin Ridge wrote in message
>> news:3eba5f0e$2@newsgroups.borland.com...
>>
>> My app uses the FlashWindowEx function. It works
>> great when running on Win98 or Win2000. When the
>> app runs on WinNT, I get the error "The procedure
>> entry point FlashWindowEx could not be located in the
>> dynamic link library USER32.DLL".
>>
>> I understand that FlashWindowEx is not supported on
>> WinNT, and my code checks for its availability (see below).
>> However, this error occurs IMMEDIATELY when I start the
>> app, i.e. way before FlashWindowEx would ever be called.
>>
>> How can I get the app to start on WinNT?
>>
>> PS. The code I use to check for the availability of FlashWindowEx
>> is below. ...
>> :
>> if (newversion) {
>> FLASHWINFO info = {sizeof(FLASHWINFO), 0};
>> info.hwnd = Application->Handle;
>> info.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;
>> info.uCount = 100;
>> FlashWindowEx(&info);
>> } else
>> FlashWindow(Application->Handle, true);
>
>
Re: FlashWindowEx, USER32.DLL on WinNT
Author: Remy Lebeau (TeamB)
Date: Thu, 08 May 2003 16:52
Date: Thu, 08 May 2003 16:52
50 lines
2678 bytes
2678 bytes
"Justin Ridge" <spamstop@terriertech.com> wrote in message
news:3eba5f0e$2@newsgroups.borland.com...
> I understand that FlashWindowEx is not supported on WinNT
Correct.
> and my code checks for its availability (see below).
No, it is not. Even though you are testing the OS version, you are still
statically linking to the function itself without testing for the specific
availability of the function itself. Which is evident by the fact that you
got the error in the first place.
> However, this error occurs IMMEDIATELY when I start the app
Correct, because you are still static linking to a function that doesn't
exist on that machine, so the OS loader fails to load the process
immediately, before it ever gets a chance to execute its first instruction.
Just because you are using a conditional statement to control the *run-time*
behavior of the code does not negate that you are still linking to both
functions at *compile-time*.
> How can I get the app to start on WinNT?
You need to use GetProcAddress() to dynamically obtain the actual pointer to
FlashWindowEx() at runtime, instead of linking to it at compile-time. Then
you don't even need to do OS version checking at all - if the function is
available on a given machine, you will have a pointer to it. Otherwise, you
will have a NULL pointer and can call FlashWindow() instead:
// Is FlashWindowEx available?
typedef BOOL WINAPI PFWEX(PFLASHWINFO);
PFWEX lpFlashWindowEx = (PFWEX)
GetProcAddress(GetModuleHandle("USER32"), "FlashWindowEx");
if( lpFlashWindowEx )
{
//...
lpFlashWindowEx(&info);
}
else
FlashWindow(Application->Handle, true);
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads