StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Monday, June 17, 2019 8:18:57 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Starting with version 0.3.1.3, StrokesPlus.net accepts receiving a WM_COPYDATA message to execute scripts via another program.
(Note: In version 0.3.1.4, the WParam parameter can be sent as 0 (zero, default) to signal the script string is Unicode, send 1 (one) to signal the script string is ANSI.)

This is a very specific use case that 99% of people will never need, but it was fairly easy to add, so why not!

NOTE:
If StrokesPlus.net is running elevated (installer version or portable running as Administrator), a non-elevated process cannot send messages to a higher privilege process.

Also, the script executes with no context, just like a hotkey. Meaning there's no action object available in the script, since it's not being started from an action.

These scripts will be run even is StrokesPlus.net is not active (disabled); as long as S+.net is running (and a script engine is available), it will execute the script.

Here's is example C# code that has all of the code necessary to send the message:

Code:
public void SendScript(string script)
{
	IntPtr hWnd = FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, "StrokesPlus.net Gesture Surface");
	byte[] sarr = System.Text.Encoding.Unicode.GetBytes(script);
	int len = sarr.Length;
	COPYDATASTRUCT cds;
	cds.dwData = (IntPtr)100; //100 (hex 0x64) instructs S+ that you're sending a script
	cds.lpData = script; //String is assumed to be Unicode, not ANSI
	cds.cbData = len + 1;
	SendMessage(hWnd, WM_COPYDATA, IntPtr.Zero, ref cds);
}
public const int WM_COPYDATA = 0x4A;
public struct COPYDATASTRUCT
{
	public IntPtr dwData;
	public int cbData;
	[System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.LPWStr)]
	public string lpData;
}
[System.Runtime.InteropServices.DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Unicode, SetLastError = false)]
internal static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam, ref COPYDATASTRUCT lParam);



Then you can just call:
Code:
SendScript("sp.MessageBox('Hi from WM_COPYDATA!', 'WM_COPYDATA');");

Edited by user Tuesday, June 18, 2019 12:06:20 AM(UTC)  | Reason: Not specified

thanks 2 users thanked Rob for this useful post.
plunt on 6/17/2019(UTC), johnwang on 5/1/2020(UTC)
Rob  
#2 Posted : Monday, June 17, 2019 8:27:59 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Here's an example C# project which sends a script to StrokesPlus.net for execution.

https://www.strokesplus.net/files/SendMessage.zip

SendMessage\bin\Debug\SendMessage.exe is already in the download as well, so you don't need to build to try it out.

NOTE: If StrokesPlus.net is running elevated (installer version or portable running as Administrator), a non-elevated process cannot send messages to a higher privilege process.

You'll need to either run Visual Studio as Administrator, or build and right-click the SendMessage.exe and Run as Administrator or nothing will happen.

Edited by user Monday, June 17, 2019 10:51:58 PM(UTC)  | Reason: Not specified

plunt  
#3 Posted : Monday, June 17, 2019 10:51:48 PM(UTC)
plunt

Rank: Member

Reputation:

Groups: Approved
Joined: 6/17/2019(UTC)
Posts: 3

Thanks: 1 times
When i try to send a message with a old x32 ansi app
Code:
SendCopyData("StrokesPlus.net Gesture Surface", 0x64, "sp.MessageBox('Hi from WM_COPYDATA!', 'WM_COPYDATA');")

i get this error:
Quote:
Script execution failed.
SyntaxError: Invalid or unexpected token
at Script Document:1:7 -> ??????????????????????????;

UserPostedImage
if it is due to unicode problems is it possible to modify StrokesPlus to accept also ansi?

Edited by user Monday, June 17, 2019 10:53:02 PM(UTC)  | Reason: Not specified

Rob  
#4 Posted : Monday, June 17, 2019 11:02:59 PM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 1,349
United States
Location: Tampa, FL

Thanks: 28 times
Was thanked: 416 time(s) in 354 post(s)
Go to the download page https://www.strokesplus.net/Downloads

Scroll down to Previous Versions, enter 0.3.1.4 and download the installer or portable (whichever you used).

Then for WParam, 0 == Unicode, 1 == ANSI

Try it and see if it works.
plunt  
#5 Posted : Monday, June 17, 2019 11:31:59 PM(UTC)
plunt

Rank: Member

Reputation:

Groups: Approved
Joined: 6/17/2019(UTC)
Posts: 3

Thanks: 1 times
It work fine now!
ty :-)
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.