News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

PostMessage Control

Started by bomz, July 02, 2011, 12:53:56 PM

Previous topic - Next topic

dedndave

http://msdn.microsoft.com/en-us/library/ms644944%28v=vs.85%29.aspx

QuoteIf you send a message in the range below WM_USER to the asynchronous message functions
(PostMessage, SendNotifyMessage, and SendMessageCallback), its message parameters cannot
include pointers. Otherwise, the operation will fail. The functions will return before the receiving
thread has had a chance to process the message and the sender will free the memory before it is used.

if the pointer points to global data, i suppose you can get away with it,
as long as the data isn't modified before it's processed


bomz

Is it possible to THREAD have it is own PROC inside?

qWord

Quote from: bomz on July 10, 2011, 08:16:06 PM
Is it possible to THREAD have it is own PROC inside?
You mean the window procedure with PROC? If so:
Windows are associated with the thread they are created from.  The WndProc is allways executed in the same thread as CreateWindowsEx().
FPU in a trice: SmplMath
It's that simple!

bomz

invoke SetWindowLong,hWnd,GWL_WNDPROC,add MyProc
mov OldWndProc,eax


I mean - MyProc inside Thread proc

bomz

MyThread proc lParametre:DWORD

........................
invoke ExitThread,0
MyWnd proc hWnd:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
.....................
MyWnd endp
MyThread endp


OR

MyThread proc lParametre:DWORD

......................
invoke ExitThread,0
MyWnd:
pop hWnd
pop uMsg
pop wParam
pop lParam
......................
ret

MyThread endp

qWord

You can't change the thread - the code is still executed in cotext of the thread that creates the window.
FPU in a trice: SmplMath
It's that simple!

dedndave

if you call a function from the thread procedure, it executes under that thread
in other words, you can have functions that are shared between threads
if you write the function carefully, you can call it from more than one thread at a time
mainly, the data items that are modified by the function should be seperated
this is often done by using local variables
each thread that calls the function will have a different stack frame

bomz

Quoteif you write the function carefully
in this concrete situation it's impossible to use the same function

because Wnd function execute not only my message which I know to that window was send, it must resend other's native messages and the same function can't know where send this messages

dedndave

 :bg
        .XCREF
        .NOLIST
        INCLUDE \masm32\include\masm32rt.inc
        .LIST

;****************************************************************

Thrd    PROTO
Func    PROTO :DWORD

;****************************************************************

        .CODE

_main   PROC

        xor     edi,edi
        INVOKE  CreateThread,edi,edi,Thrd,500,edi,edi
        INVOKE  CreateThread,edi,edi,Thrd,400,edi,edi
        INVOKE  CreateThread,edi,edi,Thrd,600,edi,edi
        INVOKE  CreateThread,edi,edi,Thrd,100,edi,edi
        INVOKE  CreateThread,edi,edi,Thrd,300,edi,edi
        INVOKE  CreateThread,edi,edi,Thrd,200,edi,edi
        inkey   " "
        exit

_main   ENDP

;****************************************************************

Thrd    PROC

        INVOKE  Func,[esp+4]
        INVOKE  ExitThread,0

Thrd    ENDP

;****************************************************************

Func    PROC    uses ebx Val:DWORD

        mov     ebx,Val
        INVOKE  Sleep,ebx
        print   ustr$(ebx),32
        ret

Func    ENDP

;****************************************************************

        END     _main

bomz



restrict mount of thread's with some number?

dedndave

you can have something like 1,000 threads, but that isn't very efficient
it depends on the OS, amount of memory, etc
use the number of threads that you need
that program was just a demo

bomz

I think about this algorithm it's so complicate and tangled

dedndave

that is usually a sign that you are doing it wrong   :bg
if it isn't simple - make it simple
i wish i could better understand what you are trying to do
maybe if you write it in Russian, i can use google translate to try and understand