Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CallWindowProc() for ms-word problem!

22 views
Skip to first unread message

Prashant Shelar

unread,
Jan 18, 2010, 1:30:02 AM1/18/10
to
Hello,

I have explained my problem step by step:

1. Firstly I have sub-classed the winword with my windows procedure
with appropriate sub-classing requirement (rules).

2. After sub-classing, from my own application i am sending WM_USER +
40 message with character 'x' to winword.

3. As i have sub-classed first this 'x' will come to my WndProc then i
will do some operation on 'x' and processed 'x' will forward to
original winwords 's WndProc. See following my WndProc

LRESULT CALLBACK
NewWndProcFocused(
HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam
)
{
LRESULT lResult;

switch (message)
{
case WM_USER + 40:
message = WM_CHAR;
break;
}

//
// Calling original focused window procedure.
//
lResult = CallWindowProc(
g_WndProcFocusedOrignl,
hwnd,
message,
wParam,
lParam
);
return lResult;
}

4. Now words WndProc supposed to write 'x' at ms-word .

5. But i am not seeing any result.

But for other application's like Internet Explore, Notepad, Wordpad
every where it is working.


Thanks and Regards
Joseph.

Christian ASTOR

unread,
Jan 18, 2010, 5:53:33 AM1/18/10
to
On 18 jan, 07:30, Prashant Shelar <shelar...@gmail.com> wrote:

> 1. Firstly I have sub-classed the winword with my windows procedure
> with appropriate sub-classing requirement (rules).

You must use OLE Automation to automate Winword

Prashant Shelar

unread,
Jan 19, 2010, 12:24:39 AM1/19/10
to

Ohh !

But when i use SendMessage(); to send a character to word it succeeds
and writes that character to ms-word.
Then in this case whether it uses OEL automation.

Thanks.

Friedel Jantzen

unread,
Jan 19, 2010, 1:26:53 AM1/19/10
to

Subclassing works only in the address space of the same process:
http://msdn.microsoft.com/en-us/library/ms997565.aspx

If you do a SendMessage, and you send a value, and not an address, this
works.
For WM_GETTEXT and WM_SETTEXT Microsoft implemented a transfer of the
string to annother address space, thus this works, too.

HTH,
Friedel

Prashant Shelar

unread,
Jan 19, 2010, 1:43:37 AM1/19/10
to

Yes Friedel, i have sub-classed the window procedure into target
process only. And then i have sent a MSG to my window proc and then i
am calling CallWindowProc();

Friedel Jantzen

unread,
Jan 20, 2010, 2:14:33 AM1/20/10
to

You posted:

>>>>> 1. Firstly I have sub-classed the winword with my windows procedure
>>>>> with appropriate sub-classing requirement (rules).

This cannot work, for your application and WinWord are different processes
with separate address spaces. The WinWord window cannot access a procedure
in your process and vice versa.

Please read the link I posted, it gives useful information on subclassing:
http://msdn.microsoft.com/en-us/library/ms997565.aspx

HTH,
Friedel

Richard Russell

unread,
Jan 20, 2010, 5:14:59 AM1/20/10
to
On Jan 20, 7:14 am, Friedel Jantzen <nospam_...@freenet.de> wrote:
> This cannot work, for your application and WinWord are different processes
> with separate address spaces. The WinWord window cannot access a procedure
> in your process and vice versa.

I understood the OP to be saying he had subclassed the window
procedure by injecting code into the remote process, presumably using
WriteProcessMemory and CreateRemoteThread, which is legitimate (though
tricky to do correctly). It may well not be possible to achieve what
he wants with WinWord that way, but the subclassing itself should
work.

Richard.
http://www.rtrussell.co.uk/

Prashant Shelar

unread,
Jan 20, 2010, 6:13:26 AM1/20/10
to

Yes Richard, i have used CreateRemoteThread() for injecting a DLL into
target application.
Once the DLL is loaded i have sub-classed a window who is having caret
blinking.
And now i am calling CallWindowProc() to write a character to focused
window. And this is working for wordpad, notepad, other windows but
NOT winword, power point, excel.

Thanks,

Friedel Jantzen

unread,
Jan 21, 2010, 1:33:10 AM1/21/10
to
Am Wed, 20 Jan 2010 03:13:26 -0800 (PST) schrieb Prashant Shelar:

> On Jan 20, 3:14�pm, Richard Russell <n...@rtrussell.co.uk> wrote:
>> On Jan 20, 7:14�am, Friedel Jantzen <nospam_...@freenet.de> wrote:
>>
>>> This cannot work, for your application and WinWord are different processes
>>> with separate address spaces. The WinWord window cannot access a procedure
>>> in your process and vice versa.
>>
>> I understood the OP to be saying he had subclassed the window
>> procedure by injecting code into the remote process, presumably using
>> WriteProcessMemory and CreateRemoteThread, which is legitimate (though
>> tricky to do correctly). �It may well not be possible to achieve what
>> he wants with WinWord that way, but the subclassing itself should
>> work.
>>
>> Richard.http://www.rtrussell.co.uk/
>
> Yes Richard, i have used CreateRemoteThread() for injecting a DLL into
> target application.

Sorry, I missed this point.

> Once the DLL is loaded i have sub-classed a window who is having caret
> blinking.
> And now i am calling CallWindowProc() to write a character to focused
> window. And this is working for wordpad, notepad, other windows but
> NOT winword, power point, excel.

It would be interesting, if the target window of WinWord processes WM_CHAR
(rsp. what you send) on regular keyboard input.

IMO dll injecting with subclassing is useful for debugging and
experimenting, but could break with the next update.

Regards,
Friedel

Prashant Shelar

unread,
Jan 21, 2010, 5:32:32 AM1/21/10
to

Yes this is main doubt when we press any key on physical keyboard then
KEYDOWN->CHAR->KEYUP is sent and it is processed by WinWord but this
is failing. Also i have not understood your two lines:

> IMO dll injecting with subclassing is useful for debugging and
> experimenting, but could break with the next update.


Thanks
Joseph.

Friedel Jantzen

unread,
Jan 22, 2010, 2:35:14 AM1/22/10
to
Am Thu, 21 Jan 2010 02:32:32 -0800 (PST) schrieb Prashant Shelar:
>
> Yes this is main doubt when we press any key on physical keyboard then
> KEYDOWN->CHAR->KEYUP is sent and it is processed by WinWord but this
> is failing.

Does the window you subclassed receive WM_CHAR when you press a key on the
keyboard with the pressed char code in wParam and the key data in lParam?
(I cannot test it, because I use OpenOffice.org.)

> Also i have not understood your two lines:
>
>> IMO dll injecting with subclassing is useful for debugging and
>> experimenting, but could break with the next update.

Microsoft can change the design of WinWord any time, and we cannot be sure
to subclass the correct window in the future.
So even if it works with a version, it could break with the next.
Microsoft thinks, we should use OLE or macros. (BTW Macros can call
functions in a dll.)

Regards,
Friedel

Prashant Shelar

unread,
Jan 27, 2010, 1:01:59 AM1/27/10
to
On Jan 22, 12:35 pm, Friedel Jantzen <nospam_...@freenet.de> wrote:
> Am Thu, 21 Jan 2010 02:32:32 -0800 (PST) schrieb Prashant Shelar:
>
>
>
> > Yes this is main doubt when we press any key on physical keyboard then
> > KEYDOWN->CHAR->KEYUP is sent and it is processed by WinWord but this
> > is failing.
>
> Does the window you subclassed receive WM_CHAR when you press a key on the
> keyboard with the pressed char code in wParam and the key data in lParam?
> (I cannot test it, because I use OpenOffice.org.)
>

Yes the window i have subclassed receives a WM_CHAR when i press a key
on the keyboard with the pressed char code in wParam and key data in
lParam.

> > Also i have not understood your two lines:
>
> >> IMO dll injecting with subclassing is useful for debugging and
> >> experimenting, but could break with the next update.
>
> Microsoft can change the design of WinWord any time, and we cannot be sure
> to subclass the correct window in the future.
> So even if it works with a version, it could break with the next.
> Microsoft thinks, we should use OLE or macros. (BTW Macros can call
> functions in a dll.)
>
> Regards,
> Friedel

Regards,
Joseph.

0 new messages