From: Albe on
Hi Joe,
thank you very much for the explanation, I have to use rundll32
because is a customer requirement, he doesn't want any executable file
(if I understood correctly the dll is inserted in a distribution list
or something like this).
This is the reason why I chose the dll way, rundll32 is automatically
starts at the windows start-up and I have only to add in the windows
registry somethig like

rundll32 CustomDll.dll,DllMain

but unfortunally doesn't work.
However, we have fixed a point, I don't have to use the MFC dll but a
"normal" dll. thank you.

My question now is: is necessary an application that call the dll or
is enough an hook?

Thank you very much, in a couple of post I solved more dubts than a
normal research.

Best regards

Alberto
From: Joseph M. Newcomer on
See below...
On Thu, 29 Oct 2009 07:26:32 -0700 (PDT), Albe <alberto_ressia(a)tiscali.it> wrote:

>Hi Joe,
>thank you very much for the explanation, I have to use rundll32
>because is a customer requirement, he doesn't want any executable file
>(if I understood correctly the dll is inserted in a distribution list
>or something like this).
>This is the reason why I chose the dll way, rundll32 is automatically
>starts at the windows start-up and I have only to add in the windows
>registry somethig like
>
>rundll32 CustomDll.dll,DllMain
****
This would be incorrect. The function you mention for rundll32 must be a C-style function
of with a specific set of parameters (HWND, HINSTANCE, LPSTR, int); Alternatively, for
Unicode, a W-surnamed entry point with an LPWSTR parameter could be used. DllMain does
not constitute a qualifying function name. The function must be an exported name; DllMain
is not an exported name. DllMain is called when the Dll starts, exits, and when threads
start and stop, and it would completely and utterly inappropriate to specify it on the
rundll32 command line.

So why should you expect the line that you show could ever possibly work under any
imaginable conditions? RTFM. KB164787 might be a good start.
****
>
>but unfortunally doesn't work.
****
Why would you expect it should? It violates the interface specifications and common
sense!
****
>However, we have fixed a point, I don't have to use the MFC dll but a
>"normal" dll. thank you.
>
>My question now is: is necessary an application that call the dll or
>is enough an hook?
****
If you were to call rundll32 in conformance with the documented interface specification,
you could have it set a hook, and it should work. But you have to use it in accordance
with its specifications. Which are documented.
****
>
>Thank you very much, in a couple of post I solved more dubts than a
>normal research.
>
>Best regards
>
>Alberto
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
See below...
On Thu, 29 Oct 2009 06:43:29 -0700 (PDT), Albe <alberto_ressia(a)tiscali.it> wrote:

>Hi all and thank you for the support,
>sorry for my soft explanation, I'm going to explain you better. First
>of all, usually I write the code for MFC application, for this work I
>wrote an MFC application that works fine and the customer ask me to do
>the same things with a simple dll (I'm not an expert in dll, I simply
>did a file with a couple of function). So, I started from my MFC
>application and I rewrote the code for a dll.
>The dll works fine but now I have to add, in the application and in
>the dll, a special behaviour before the windows goes in sleep mode
>(S3).
>
>In the application no problem, I added WM_POWERBROADCAST message in
>the message map and I can do the special code. Now I have to do the
>same in the dll, I used:
>- GetMessage
>- PreTranslateMessage
>- PeekMessage
****
You will only get WM_POWERBROADCAST if you are a top-level window. Therefore, you cannot
get this message unless you create a top-level window (it does not need to be visible).

There is no PreTranslateMessage in a non-MFC app; you mean TranslateMessage. You would
not need PeekMessage, you would use DispatchMessage.
>
>Unfortunally no one catchs the message, the strange thingh is that I
>can intercept some message (WM_TIMER etc etc) but no the
>WM_POWERBROADCAST.
****
Not surprising, since you need to be a top-level window to qualify for that message.
****
>
>It seems that is related to the assence of dialog.
****
No, it is probably related to the absence of a top-level window. You have shown
absolutely no code, so it is impossible to guess what is happening.
****
>
>So I was trying to do a MFC dll because there is the message map as
>the application but if I try to start the dll with rundll32 a
>messagebox advise me that is not possible (it seems that the sistem
>can't find the Dll EntryPoint).
*****
The message map won't help because the message map only decodes the messages you receive,
and if you are not a top-level window, you won't get the message, whether you use MFC or
raw Win32 API programming.
****
>
>What can I do?
****
(a) use rundll in accordance with its documentation
(b) WM_POWERBROADCAST is only sent to top-level windows
****
>
>Best regards
>
>Alberto
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Albe on
Hi Joseph,
thank you very much for the support, Il'' try to use use your
suggestion and I let you know as soon as possible.

Best regards

Alberto