Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
command parsing is garbled
#1
Hi,

Send command arguments if they contain double-byte characters, garbled characters appear when received

Thanks in advance for any advice and help
david

Macro Send_command
Code:
Copy      Help
str p="C:\Users\Administrator\Desktop\地球村 ABC.txt"

str s=
;地球村 你好abcde世界ab
;大家好 ab你好 abc

int h = win("" "QM_Editor")
SendMessage(h WM_SETTEXT 3 F"Q ^ M ^Receive_command^ C {p} 123 {s}")

Function Receive_command
Code:
Copy      Help
;Parse the command line
ARRAY(str) a
ExeParseCommandLine(_command a)

for _i 0 a.len
,_s.formata("%s[]" a[_i].trim)
_s.trim

mes a.len

mes _s

mes _unicode
#2
change this line
Code:
Copy      Help
SendMessage(h WM_SETTEXT 3 F"Q ^ M ^Receive_command^ C {p} 123 {s}")
to
Code:
Copy      Help
SendMessageW(h WM_SETTEXT 3 @F"Q ^ M ^Receive_command^ C {p} 123 {s}")
#3
@Kevin

Problem solved, thanks for your help,   @Symbol is like a magic

The received parameters are cut into multiple lines at the spaces, is there any good way to keep them as they are?

e.g:

C:\Users\Administrator\Desktop\地球村 ABC.txt

地球村 你好abcde世界ab
大家好 ab你好 abc

QM3 code Generate  exe, which runs a lot faster, but passing multi-line parameters is a bit troublesome.  Huh
#4
enclose the lines in quotes
Code:
Copy      Help
str p="''C:\Users\Administrator\Desktop\地球村 ABC.txt''"

str s=
;"地球村 你好abcde世界ab"
;"大家好 ab你好 abc"

SendMessageW(_hwndqm WM_SETTEXT 3 @F"Q ^ M ^Receive_command^ C {p} 123 {s}")
#5
In the QM3 code, I want to send the same message to the function(Receive_command) of QM2 to achieve the Same effect, is it possible?  Smile
#6
C# code:
// script ""
string macro = "func";
int arg1 = 5;
string arg2 = "text ą";
wnd qm = wnd.findFast(cn: "QM_Editor"); if (qm.Is0) return;
qm.Send(0xC, 2, $"Q ` M `{macro}` A(~~) {arg1}~~{arg2}");

In QM:
Function func
Code:
Copy      Help
function i str's
out F"{i} {s}"
#7
@Gintaras 

Thanks for your help, 

It worked well, which was useful and connected QM2 and QM3

Can QM2 send Parameter message to QM3's functions and run it in a similar way? Wink

I feel that QM2 is more convenient and practical than QM3 in many cases
#8
QM3 editor supports only command line. The speed is ~100 ms if fast CPU.

If need a faster way, in QM3 create a script that runs all the time and somehow listens for QM2. For example with TCP it's easy to send and receive data. Speed: less than 1 ms if no script started, 4-16 ms if started.

TCP example.
In QM2 you need class TcpSocket. Import folder TcpSocket from https://www.quickmacros.com/forum/showth...p?tid=2852
Macro TCP to QM3
Code:
Copy      Help
#compile "__TcpSocket"
TcpSocket x.ClientConnect("127.0.0.1" 51885)
str s

x.Send("request ą")
x.Receive(s 10000)
out F"response: {s}"

x.Send("request ą")
x.Receive(s 10000)
out F"response: {s}"

In QM3 create this script and run. To run at startup, add it to Options -> General -> Run scripts...
C# code:
// script "TCP triggers.cs"
using System.Net;
using System.Net.Sockets;

TcpListener server = null;
try {
server = new TcpListener(IPEndPoint.Parse("127.0.0.1:51885"));
server.Start();
var b = new byte[100_000];
for (; ; ) {
var client = server.AcceptTcpClient();
var stream = client.GetStream();
int n;
while ((n = stream.Read(b, 0, b.Length)) != 0) {
var s = Encoding.UTF8.GetString(b, 0, n);
print.it(s);

//here add code to parse s and run a script or thread/task or execute any short/fast code. The QM2 script will wait and receive res. Examples:

//script.run(@"\Script15.cs", "arg1", "arg2"); //run async
//script.runWait(out var res, @"\Script15.cs"); //run sync and get its script.writeResult text
//run.thread(() => { print.it("thread"); });
//Task.Run(() => { print.it("thread"); });

var res = "result č";
stream.Write(Encoding.UTF8.GetBytes(res));
}
client.Close();
}
}
finally {
server.Stop();
}

This is raw code, need to test better and make easier to use.
#9
@Gintaras 
Thank you for sharing, 
A bit complicated, I collect first, there is free time to test


Forum Jump:


Users browsing this thread: 1 Guest(s)