__DLL.NewCallback & CreateThread

General discussion forum for Ams Plugin Maker
Post Reply
User avatar
Shrek
Registered User
Posts: 49
Joined: Mon Aug 12, 2013 10:10 pm

__DLL.NewCallback & CreateThread

Post by Shrek »

With this would that be the sort of pointer needed for the lParam of LVM_SORTITEMS?

http://msdn.microsoft.com/en-us/library ... 85%29.aspx

Also can we use this for the CreateThread function and if so would the lpStartAddress function be running without blocking the Lua thread or would it block it?

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
User avatar
Serkan
Developer
Developer
Posts: 214
Joined: Thu Jul 04, 2013 8:44 pm
Location: Windows.h
Contact:

Post by Serkan »

Shrek wrote:With this would that be the sort of pointer needed for the lParam of LVM_SORTITEMS?

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
yes , you can make it something like below (UN-TESTED)

Code: Select all

LVM_SORTITEMS = 4144
User32 = __DLL.LoadLibrary("user32.dll", "stdcall");
if(User32) then
	ListView_SortItems 	= __DLL.GetFunction(User32,_int, "SendMessageA",_long,_long,_long,_callback);
end
-- callback function
function CompareFunc(lParam1,lParam2,lParamSort)
	-- compare lParam1,lParam2 here
	return 0;
end

function ListViewSortItems(hWnd)
	local cbCompareFunc = __DLL.NewCallback(User32,_int,"CompareFunc",_long,_long,_long);
	ListView_SortItems(hWnd,LVM_SORTITEMS,0,cbCompareFunc);
end
Shrek wrote:
Also can we use this for the CreateThread function and if so would the lpStartAddress function be running without blocking the Lua thread or would it block it?

http://msdn.microsoft.com/en-us/library ... 85%29.aspx
unfortunately not so , this will lead an app crash or a similar effect
because , a thread means a new execution stack in same memory space and threads can not share/access data of other threads directly

this is a long story to explain but multi-threading support is in todo list of APM
User avatar
Shrek
Registered User
Posts: 49
Joined: Mon Aug 12, 2013 10:10 pm

Post by Shrek »

Thanks for that, sorting a ListView was a high priority for me and the thread was a bonus but at least the bonus is on its way :D
Post Reply