Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

[ARCHIVED THREAD] SciTE4AutoHotkey v2 Stable - Released.


  • This topic is locked This topic is locked
154 replies to this topic
not-logged-in-fincs
  • Guests
  • Last active:
  • Joined: --

FYI, when I try to perform a web install I get an error message:

Can't download the file!
Make sure your Internet connection is active then
try to install the program again.

I took it's advice and tried again, rebooted, redownloaded install app, but still no go. :) Not sure what's up as there's nothing special about my PC's setup. It's Windows XP with one network connection and nothing else seems to have trouble. The web install worked fine on my Vista laptop.

I downloaded the data file independently and then ran an offline install and that worked so I'm good to go, but I thought I'd let you know.

Thanks for your efforts. Nicely done!


Weird... The web install works correctly on my system... I'll try to fix that, don't worry :D

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

So, maybe an interface implemented in LUA? Or a custom SciTE version?

As far as I can tell, OnMarginClick() in Lua doesn't provide any way to determine which margin was clicked, or at which line. :? The only alternative I can think of for standard SciTE is to use:
[*:31xyb6eg]mouse hotkeys to detect click;
[*:31xyb6eg]SCI_GETMARGINWIDTHN to determine which margin was clicked, if any; and
[*:31xyb6eg]SCI_POSITIONFROMPOINT and SCI_LINEFROMPOSITION to determine which line was clicked.On the other hand, SCN_MARGINCLICK provides modifier key-state, position of the start of the line and margin number. A "custom SciTE version" could allow this (and other notifications!) to be hooked, or could add parameters to the lua OnMarginClick().

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

So, maybe an interface implemented in LUA? Or a custom SciTE version?

As far as I can tell, OnMarginClick() in Lua doesn't provide any way to determine which margin was clicked, or at which line. :? The only alternative I can think of for standard SciTE is to use:
[*:3ua6zpfl]mouse hotkeys to detect click;
[*:3ua6zpfl]SCI_GETMARGINWIDTHN to determine which margin was clicked, if any; and
[*:3ua6zpfl]SCI_POSITIONFROMPOINT and SCI_LINEFROMPOSITION to determine which line was clicked.On the other hand, SCN_MARGINCLICK provides modifier key-state, position of the start of the line and margin number. A "custom SciTE version" could allow this (and other notifications!) to be hooked, or could add parameters to the lua OnMarginClick().

I would vote for the "custom SciTE" option. Then I have to figure out how to implement a new parameter in the Extension module... :roll:
Let's see how other functions do it (OnChar) and just implement it then...

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007
Ok, I've succesfully implemented two new parameters in the OnMarginClick message: position and margin! So I'm now going
to program a LUA extension DLL so I can send the messages to an AHK program that will implement the DBGp support
(I'm waiting for you to create the AutoHotkey_L debugging functions,
what language are they going to be in? AutoHotkey or C++? I would better
have AutoHotkey functions than C++ functions :D).

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

what language are they going to be in? AutoHotkey or C++?

AutoHotkey.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

what language are they going to be in? AutoHotkey or C++?

AutoHotkey.

Great! I'm now fighting with the compiler (MinGW) to link the Lua library (lua51.a) to the LUA expansion module (a .c file) to create the DLL,
but the compiler refuses to find the missing functions in the .a file :(
gcc -O -shared -mwindows -o module.dll lua51.a main.c
EDIT: Nevermind, found the solution :D
EDIT2: The test MsgBox dll works great! Now to make the actual DLL!

kdoske
  • Members
  • 138 posts
  • Last active: Nov 06 2012 01:58 AM
  • Joined: 17 Dec 2008
No disrespect to all the other hard work put out there for all the other AHK editors but this is one is fantastic.

first editor I have used that feels like a real editor. Just wanted to say thanks for your efforts.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

No disrespect to all the other hard work put out there for all the other AHK editors but this is one is fantastic.

first editor I have used that feels like a real editor. Just wanted to say thanks for your efforts.

Thank you for your comments :D:oops:

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007
I just got the message pumper working.
Here is the code, if you want to look at it (main.c):
// SciTE4AutoHotkey v2 LUA message pumper
// Build with: gcc -shared -o module.dll -I..\lualib\src main.c scite.la
// You've got to have a LUA distribution at ..\lualib (creates the src folder)
// for this to work.
// Also copy the scite.* files from http://luaforge.net/frs/download.php/3293/scite-debug.zip (scite.la, scite.def and scite.lib)

#include <windows.h>
#include "lauxlib.h"
#define DllExport __declspec(dllexport)
#define RET_OK 1
#define RET_FAIL 0
#define MAX_TITLE 255
#define SNDMSG_DELAY 8000

#ifndef PROCESS_VM_OPERATION
#define PROCESS_VM_OPERATION 0x0008
#endif
#ifndef PROCESS_VM_READ
#define PROCESS_VM_READ 0x0010
#endif
#ifndef PROCESS_VM_WRITE
#define PROCESS_VM_WRITE 0x0020
#endif
#ifndef MEM_COMMIT
#define MEM_COMMIT 0x1000
#endif
#ifndef PAGE_READWRITE
#define PAGE_READWRITE 4
#endif
#ifndef MEM_RELEASE
#define MEM_RELEASE 0x8000
#endif

HWND cWindow = 0, tWindow = 0;
char* cWinTitle;

// Private callback function to enumerate the windows.
BOOL CALLBACK _lib_winsearchproc(HWND hWnd, LPARAM lParam){
	char wTitle[MAX_TITLE+1];
	// Get window title
	GetWindowText(hWnd, wTitle, MAX_TITLE);
	if(!strncmp(wTitle, cWinTitle, lParam)){
		// Window found.
		cWindow = hWnd;
		return 0; // Cancel the enumeration
	}
	return 1; // Continue enumerating the windows
}

// localizewin(wintitle) -- Localizes the window with the specified window title to
//  further send messages to it. True = sucess, false = failure.
int lib_localizewin(lua_State* L){
	// set the global variables
	cWinTitle = (char*) luaL_checkstring(L, 1);
	tWindow = cWindow, cWindow = 0;

	// look for the window
	EnumWindows((WNDENUMPROC)_lib_winsearchproc, strlen(cWinTitle));
	if(!cWindow){ // no window found?
		// just restore the old window and return.
		cWindow = tWindow;
		lua_pushboolean(L, RET_FAIL);
		return 1;
	}
	lua_pushboolean(L, RET_OK);
	return 1;
}

// pumpmsg(msg, wparam, lparam) -- Sends a message to the current window.
//  Timeout of 8 seconds. It returns the value that the window returns.
int lib_pumpmsg(lua_State* L){
	int iMsg = luaL_checkint(L, 1);
	int wParam = luaL_checkint(L, 2);
	int lParam = luaL_checkint(L, 3);
	if(!IsWindow(cWindow))
		return luaL_error(L, "Invalid window handle.");
	int result;
	if(!SendMessageTimeout(cWindow, (UINT)iMsg, (WPARAM)wParam, (LPARAM)lParam, SMTO_ABORTIFHUNG, SNDMSG_DELAY, (PDWORD_PTR) &result)){
		return luaL_error(L, "Failed at SendMessage'ing the window!");
	}
	lua_pushnumber(L, result);
	return 1;
}

// pumpmsg(msg, wparam, lparam) -- Sends a message with lparam as string to the current window.
//  Timeout of 8 seconds. It returns the value that the window returns.
int lib_pumpmsgstr(lua_State* L){
	int iMsg = luaL_checkint(L, 1);
	int wParam = luaL_checkint(L, 2);
	const char* lParam = luaL_checkstring(L, 3);
	int lParamSize = strlen(lParam);

	if(!IsWindow(cWindow))
		return luaL_error(L, "Invalid window handle.");

	// Inject the string at the process.
	DWORD pID;
	GetWindowThreadProcessId(cWindow, &pID);
	HANDLE hProcess = OpenProcess(PROCESS_VM_OPERATION | PROCESS_VM_READ | PROCESS_VM_WRITE, 0, pID);
	if(!hProcess)
		return luaL_error(L, "Couldn't open the memory of the window!");
	void* rlParam = VirtualAllocEx(hProcess, 0, lParamSize, MEM_COMMIT, PAGE_READWRITE);
	if(!rlParam)
		return luaL_error(L, "Couldn't allocate the memory at the window!");
	if(!WriteProcessMemory(hProcess, rlParam, lParam, lParamSize, NULL))
		return luaL_error(L, "Couldn't inject the string parameter at the window!");

	// Send the message to the window.
	int result;
	if(!SendMessageTimeout(cWindow, (UINT)iMsg, (WPARAM)wParam, (LPARAM)rlParam, SMTO_ABORTIFHUNG, SNDMSG_DELAY, (PDWORD_PTR) &result)){
		return luaL_error(L, "Failed at SendMessage'ing the window!");
	}

	// Free the memory used by the string
	if(!VirtualFreeEx(hProcess, rlParam, 0, MEM_RELEASE))
		return luaL_error(L, "Failed to free the memory at the window!");
	if(!CloseHandle(hProcess))
		return luaL_error(L, "Couldn't close the process handle!");

	lua_pushnumber(L, result);
	return 1;
}

int DllExport libinit(lua_State* L){
	// do the following for each function you want to add to the LUA engine
	lua_register(L, "localizewin", lib_localizewin);
	lua_register(L, "pumpmsg", lib_pumpmsg);
	lua_register(L, "pumpmsgstr", lib_pumpmsgstr);
	return 0;
}
Now I'm patiently waiting for Lexikos to release his functions... :D

EDIT: Post #200! WOOT!!

DeWild1
  • Members
  • 369 posts
  • Last active: Feb 28 2014 08:15 PM
  • Joined: 30 Apr 2006
#1 YOU ROCK....

#2 I got it too on one of my servers.. I will PM instructions on how to log in via Remote Desktop if you want to see it and test. (its my VOIP server so please do not reboot unless it is after 10pm PST.

FYI, when I try to perform a web install I get an error message:

Can't download the file!
Make sure your Internet connection is active then
try to install the program again.

I took it's advice and tried again, rebooted, redownloaded install app, but still no go. :) Not sure what's up as there's nothing special about my PC's setup. It's Windows XP with one network connection and nothing else seems to have trouble. The web install worked fine on my Vista laptop.

I downloaded the data file independently and then ran an offline install and that worked so I'm good to go, but I thought I'd let you know.

Thanks for your efforts. Nicely done!

8)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
Is it safe to use SendMessageTimeout - i.e. does the window still eventually process the message if it times out? If it times out and SciTE frees the memory, it obviously won't be valid when the window processes the message... Actually, I think it may time out while the window is processing the message. You may confirm with something like:
OnMessage(..., "Timeout")
...
Timeout() {
    DllCall("Sleep", "int", 10000)
}


fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

Is it safe to use SendMessageTimeout - i.e. does the window still eventually process the message if it times out? If it times out and SciTE frees the memory, it obviously won't be valid when the window processes the message... Actually, I think it may time out while the window is processing the message. You may confirm with something like:

OnMessage(..., "Timeout")
...
Timeout() {
    DllCall("Sleep", "int", 10000)
}

I haven't really tested the timeout but what I can say is that the memory allocated by
pumpmsgstr() is not freed if SendMessageTimeout() fails (timeout). And,
to ensure reliability I've decided to set the timeout to 1 minute (to be
realistic, no message handler is gonna take 1 minute to process a message unless it's an ├╝ber slow PC :lol:).
If it does, the most probable thing is that the window is hung and that
situation is already handled by the function call (ABORTIFHUNG).
Anyway, how are those DBGp interface functions going?
And I forgot to say: as this DLL uses some calls that are Windows 2000+ only,
the DBGp debugging feature will only be available for those systems :)
Anyway, as AutoHotkey_L is compiled with VC++ 2008 Express, it is
Windows 2000+ too :p

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I haven't really tested the timeout but what I can say is that the memory allocated by
pumpmsgstr() is not freed if SendMessageTimeout() fails (timeout).

Ah, so you're happy with memory leaks in that case?

to ensure reliability I've decided to set the timeout to 1 minute

How does that ensure reliability? I suppose it would be more reliable to NOT time out; i.e. use SendMessage instead of SendMessageTimeout. If you want to avoid sending a message to a "hung" window, you may call IsHungAppWindow before-hand.

Anyway, how are those DBGp interface functions going?

Slowly, partly because I intend to support multiple asynchronous connections. One major problem with XDebugClient is that the user interface freezes while the script is running; i.e. it sends a command like "run" and does not update the UI until it receives a response (i.e. a breakpoint is hit or the script exits). Ideally the debugger client will send a command, and be notified when a response is received and for which script.

fincs
  • Moderators
  • 1662 posts
  • Last active:
  • Joined: 05 May 2007

I haven't really tested the timeout but what I can say is that the memory allocated by
pumpmsgstr() is not freed if SendMessageTimeout() fails (timeout).

Ah, so you're happy with memory leaks in that case?

to ensure reliability I've decided to set the timeout to 1 minute

How does that ensure reliability? I suppose it would be more reliable to NOT time out; i.e. use SendMessage instead of SendMessageTimeout. If you want to avoid sending a message to a "hung" window, you may call IsHungAppWindow before-hand.

Then show me how to detect errors on the SendMessage routine :)
I chose the SendMessageTimeout() function because it returns the
error code instead of the value that the window returns (it puts it in an output parameter).
Anyway, if I do a bunch of checks before I think it won't be necessary :)

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
What errors are there to detect? You shouldn't be passing it an invalid window handle; if in doubt, use IsWindow. (Edit: I see you already do.)