Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am dumping characters one by one of a script file path onto powershell console using SendMessage API.

At the first execution of program, powershell skips the repeated character from a path which creates an issue.

For e.g. "C:\myFolder\abbc\test.ps1"

From above path when I dump a characters onto powershell window, it skips 1 b from "abbc" so the final path that gets dumped on console is "C:\myFolder\abc\test.ps1".

This happens only first execution of application, on subsequent executions it works fine and accepts repeat characters as well.

What I have tried:

I tried adding sleep time of 1 seconds after before dumping other character.

[EDIT by Jochen Arndt: Copied code and text from comment]
C++
for(int i = 0;scriptPath[i] != '\0';i++)
{
    ::SendMessage(g_hwndConsole,WM_CHAR,scriptPath[i],1L);
    Sleep(3*1000);
}
Here g_hwndConsole is the powershell console handle
[/EDIT]
Posted
Updated 2-Aug-17 22:49pm
v2
Comments
Jochen Arndt 3-Aug-17 3:44am    
Please show the code that dumps (the message that is send).

When sending to another application you should generally use PostMessage instead of SendMessage.
GVS13 3-Aug-17 3:59am    
for(int i = 0;scriptPath[i] != '\0';i++)
{
::SendMessage(g_hwndConsole,WM_CHAR,scriptPath[i],1L);
Sleep(3*1000);
}

Here g_hwndConsole is the powershell console handle

As already mentioned in my comment:
Never use SendMessage when the receiving window is not owned by the thread sending the message. Use PostMessage instead. There should be also no need to set a repeat count of one. Try this instead:
::PostMessage(g_hwndConsole, WM_CHAR, scriptPath[i], 0);
 
Share this answer
 
See WM_CHAR message (Windows)[^] for a proper explanation of this message.
 
Share this answer
 
Comments
GVS13 3-Aug-17 5:06am    
Am I missing something in that? Can you please help me to get that point?
Richard MacCutchan 3-Aug-17 5:13am    
You need to look at the LPARAM value you are sending, which specifies a repeat count. That may be the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900