two-way listview communication between two scripts. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
lsh
Posts: 10
Joined: 14 Sep 2017, 07:02

two-way listview communication between two scripts.

20 Oct 2017, 00:19

Error on the performance of test.ahk : An error of CONTINUABLE EXCEPTION_ACCESS_VIOLATION is seen, how can I do if I make a list view messahe is seen without any problem?

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
FileEncoding UTF-8
gui,add,listview,x5 y12 r35 w400 grid  NoSortHdr vVLvInfo hwndHLvInfo,time|txt
gui,Show, x300 y200 w410 h650,workgroup
fd1=%A_ScriptDir%\test2.ahk
fd2=%A_ScriptDir%\test3.ahk
FileDelete,%fd2%
FileRead,SText,%fd1%
EText:="HLvInfo=" HLvInfo . "`n" . SText
FileAppend,%EText%,%fd2%
Run,%fd2%
return

GuiExit:
EXIT:
GuiClose:
gui, destroy 
ExitApp
return

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
FileEncoding UTF-8
sendmsg:="ListView_library sendtest"
LVM_Insert(HLvInfo,1,1,0,,A_Hour . ":" . A_min . ":" . A_Sec,sendmsg)
ExitApp

LVM_Insert(hLV, row=0, col=1, options=0, f*) {
	col := col ? col-1 : 0
	row := row ? row-1 : DllCall("SendMessage", "uint", hLV, "uint", 4100, "uint", 0, "uint", 0)
	VarSetCapacity(lvItem, A_PtrSize * 6, 0)
	NumPut(9      , lvItem, A_PtrSize * 0 "uint")   ; mask
	NumPut(row    , lvItem, A_PtrSize * 1, "int") 	; iItem
	NumPut(options, lvItem, A_PtrSize * 3, "uint")  ; state
	NumPut(1      , lvItem, A_PtrSize * 4, "uint")  ; stateMask
	DllCall("SendMessage", "uint", hLV, "uint", 4103, "uint", 0, "uint", &lvItem) ; LVM_INSERTITEM
	For index,field in f
		{
		NumPut(col + A_Index - 1, lvItem, A_PtrSize * 2, "int") ; iSubItem
		NumPut(&field           , lvItem, A_PtrSize * 5, "ptr") ; pszText
		DllCall("SendMessage", "uint", hLV, "uint", A_IsUnicode ? 4172 : 4171, "uint", 0, "ptr", &lvItem) ; LVM_SETITEMW
		}
	}
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: two-way listview communication between two scripts.  Topic is solved

20 Oct 2017, 15:40

Code: Select all

#NoEnv
#SingleInstance Force
#Persistent
FileEncoding UTF-8
sendmsg:="ListView_library sendtest"
LVM_Insert(HLvInfo,1,1,0,,A_Hour . ":" . A_min . ":" . A_Sec,sendmsg)
ExitApp

LVM_Insert(hLV, row=0, col=1, options=0, f*) {
	static MEM_RELEASE:=32768, MEM_DECOMMIT:=16384, MEM_COMMIT:=4096, MEM_RESERVE:=8192, PAGE_EXECUTE_READWRITE:=64
		,_LVITEM := "
		(
		  UINT   mask;
		  int    iItem;
		  int    iSubItem;
		  UINT   state;
		  UINT   stateMask;
		  LPTSTR pszText;
		  int    cchTextMax;
		  int    iImage;
		  LPARAM lParam;
		  int    iIndent;
		  int    iGroupId;
		  UINT   cColumns;
		  UINT  *puColumns;
		  int    *piColFmt;
		  int    iGroup;
		)"
	col := col ? col-1 : 0
	row := row ? row-1 : SendMessage_(hLV, 4100, 0, 0)
	DllCall("GetWindowThreadProcessId", "PTR", hLV, "UInt*", PID)
	if !hProc:=DllCall("OpenProcess", "UInt", PROCESS_ALL_ACCESS:=2035711, "UInt", 0, "UInt", PID){
		MsgBox %A_ThisFunc% could not open Process
		Return
	}
	len:=0
	for k,v in f
		if ((len:=StrLen(v)+1)>max)
			max:=len
	If !pMem:=DllCall("VirtualAllocEx", "PTR", hProc, "PTR", 0, "PTR", Max*(A_IsUnicode ? 2 : 1), "Uint", MEM_COMMIT | MEM_RESERVE, "UInt", PAGE_EXECUTE_READWRITE){
		MsgBox %A_ThisFunc% could not allocate memory for text, size: %max%
		Return
	}
	If !pStruct:=DllCall("VirtualAllocEx", "PTR", hProc, "PTR", 0, "PTR", sizeof(_LVItem), "UInt", MEM_COMMIT | MEM_RESERVE, "Uint", PAGE_EXECUTE_READWRITE){
		MsgBox %A_ThisFunc% could not allocate memory for structure.
		Return
	}
	lvItem:=Struct(_LVITEM,{mask:1,iItem:row,state:options,stateMask:1}),lvItem.pszText[""]:=pMem
	if !DllCall("WriteProcessMemory", "PTR", hProc, "PTR", pStruct, "PTR", lvItem[] ,"PTR", sizeof(_LVITEM), "PTR", 0){
		MsgBox %A_ThisFunc% could not write structure
		Return
	}
	DllCall("SendMessage","PTR",hLV, "Uint", A_IsUnicode ? 4173 : 4103,"PTR", 0, "PTR", pStruct) ; LVM_INSERTITEM
	lvItem.mask:=9
	If !DllCall("WriteProcessMemory","PTR", hProc, "PTR", pStruct, "PTR", lvItem[] ,"PTR", sizeof(_LVITEM), "PTR", 0){
		MsgBox %A_ThisFunc% could not write structure
		Return
	}
	For index,field in f
	{
		lvItem.iSubItem:=col+A_Index-1
		If !DllCall("WriteProcessMemory", "PTR", hProc, "PTR", pStruct, "PTR", lvItem[] ,"PTR", sizeof(_LVITEM), "PTR", 0) || !DllCall("WriteProcessMemory", "PTR", hProc, "PTR", pMem, "PTR", &field, "PTR", StrLen(field)*(A_IsUnicode?2:1)+1, "PTR", 0){
			MsgBox %A_ThisFunc% could not write structure
			Return
		}
		DllCall("SendMessage","PTR",hLV, "Uint", A_IsUnicode ? 4172 : 4102, "PTR", 0, "PTR", pStruct) ; LVM_SETITEMW
	}
	DllCall("VirtualFreeEx", "PTR", hProc, "PTR", pMem, "PTR", Max*(A_IsUnicode ? 2 : 1), "UInt", MEM_DECOMMIT | MEM_RELEASE)
	,DllCall("VirtualFreeEx", "PTR", hProc, "PTR", pStruct, "PTR", sizeof(_LVItem), "UInt", MEM_DECOMMIT | MEM_RELEASE)
	,DllCall("CloseHandle", "PTR", hProc)
}

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: NinjoOnline and 303 guests