Sign in to follow this  
Followers 0
Alek

TCP Chat

35 posts in this topic

#1 ·  Posted (edited)

this has bin totaly rewriten.

UPDATE:

Server:

-Cleaned up a bit

-Username is no longer case sensitive

-Admins now get [A] in front of their names.

-The DB view updates every time something changes (it only updates the changes ;) )

-Users may only create usernames that only contains a-Z and numbers.

-switched _Stringencrypt with RazerM's RC4 Encryption, its faster, not if its more or less secure.

-Works with the newest version of Autoit (3.2.12.1)

-Uses SQLite instead of INI as database.

-Server Control panel with a DB editor.

-Logs everything that enters and leaves the server (does not log IP)

Client:

-Works with newest version of Autoit

BUGS:

-the _SQLite_Close function gives a error every now and then.

TODO:

-Dynamic DB Viewer, not sure how to do that yet.

-Optimize, always fun to do :)

-Clean up, just make the script look nice and readable.

Made it into a Zip with all you need:

Chat.zip

Test server:

-Ip: 82.116.83.6

-Port: 31758

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

I think i have found a big bugg in youre program.

When i writh the other clients cant see the text i writh, but on the server logs it stands.

otherwise it is really good! i had some trubbel with that some times after exit, the Status. Online still =1

but it´s only some times.

I´ll like the Chat really Much And the Best was [bad Word] Thats really good.

sorry for my bad English. Please Repair the script.

Thanks at advance/ LokErik


The first error is one step closer to the perfect program.

Share this post


Link to post
Share on other sites

Very Brilliant.

~Smith

Share this post


Link to post
Share on other sites

I'm also having the same problem.. server logs what i type, but other users can not see what it typed

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I'm also having the same problem.. server logs what i type, but other users can not see what it typed

wow, i havnt seen this script in a while ^_^ maybe il start working on it again :)

btw, fixed the problem i think, was that it had case "msg", it should be case else if i remeberd correctly

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

Thanks!

Now it works perfect, and i have looked deeper in the code and find some other nice things. like start the server on other ports ^_^ .

I have only own litle question left. The log, when some writh and i look in the log i cant see if they write at the moment. Then i need to close the log and open it again, it whould be great to have a Txt read program like Notpad with Auto update Like every 5 sec.

otherwise it is the greatest Chat over TCP i ever Seen.

: If you don´t have anny other to do i´ll have some idea what you can add. like when you Write: : ) then it become a :) . Than maby hard i don´t knew.

Thanks Anyway, Good Work. :)


The first error is one step closer to the perfect program.

Share this post


Link to post
Share on other sites

Thanks!

Now it works perfect, and i have looked deeper in the code and find some other nice things. like start the server on other ports ^_^ .

I have only own litle question left. The log, when some writh and i look in the log i cant see if they write at the moment. Then i need to close the log and open it again, it whould be great to have a Txt read program like Notpad with Auto update Like every 5 sec.

otherwise it is the greatest Chat over TCP i ever Seen.

: If you don´t have anny other to do i´ll have some idea what you can add. like when you Write: : ) then it become a :) . Than maby hard i don´t knew.

Thanks Anyway, Good Work. :)

well, you could create a console.

GUICreate("Autoit Chat console",600,300)
$Edit1 = GUICtrlCreateEdit("",5,5,590,290, $ES_WANTRETURN+$WS_VSCROLL+$ES_READONLY+$ES_MULTILINE)
GUISetState()oÝ÷ Ù©Ý©¶¥¢îËb¢vuÖ­jÚ-ç(Ê%y«­¢+ÙÕ¹}1½ ÀÌØíÍ}1½¤(¥±]É¥Ñ ÀÌØíÍ}1½¥±°ÀÌØíÍ}1½µÀì
I1¤(%U%
ÑɱMÑÑ ÀÌØí¥ÐıU%
ÑɱI ÀÌØí¥ÐĤµÀìÀÌØíÍ}1½µÀì
I1¤)¹Õ¹ìôôÐí}1½

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

Looks cool :)

I'm working on my LAN chat app that is currently serverless. It searches your network for other clients on the came channel as you, then connects you to them.

For some reason autoit crashes when I use it... still a few bugs to work out but for the most part its a fully functional chat room for your local lan.

Share this post


Link to post
Share on other sites

Looks cool :)

I'm working on my LAN chat app that is currently serverless. It searches your network for other clients on the came channel as you, then connects you to them.

For some reason autoit crashes when I use it... still a few bugs to work out but for the most part its a fully functional chat room for your local lan.

A few questions...

How does it search the network? Does it try to connect to a few IPs, or does it has a list of computers? If so, Where does it take the list from?

Is there a "main" chat room where you can send messages to all users, or is it really IP based, where you can send messages to just 1 person.

Also, is it really server-less, or is the server role switched between online computers?

Share this post


Link to post
Share on other sites

It is completely server-less, and supports as many people that are on your LAN.

It uses UDP packets to find other clients on your network, once it finds them it connects to them via TCP and exchanges username details then you are ready to chat with that person.

Each client is completely independent from the others. If one client disconnects, the chat network still stands as it was, except messages will no longer be sent to the client who disconnected and it will alert all other clients that someone has been disconnected and remove their username from the list.

There are no "hubs" or servers at all, and it takes only seconds to find clients to connect to.

Share this post


Link to post
Share on other sites

this has bin totaly Rewriten ^_^

the old script was very old :) and i thought it whould be easyer to rewrite the whole thing.

fixed and added alot of stuff.


[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

You should make it completely encrypted, and do a unique key exchange for each client.

Have a master key (That the server and every client has), then make it connect using its master key as an encryption key, then negotiate a private unique to the server/client pair.

Just thought it might be fun, since you already do stuff with encryption.

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

You should make it completely encrypted, and do a unique key exchange for each client.

Have a master key (That the server and every client has), then make it connect using its master key as an encryption key, then negotiate a private unique to the server/client pair.

Just thought it might be fun, since you already do stuff with encryption.

i added your idea (i think) it also creates a new key for the user every 15sec.

not sure how well it will work, i think if the client sends a message at the right moment it could get messy.

Edited by Alek

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

i added your idea (i think) it also creates a new key for the user every 15sec.

not sure how well it will work, i think if the client sends a message at the right moment it could get messy.

Make each message start with a special identifier character to fix this problem.

Remember this key, and the previous key. If the decrypted string does not start with the identifier character, use the previous key to decrypt it.

Share this post


Link to post
Share on other sites

where do you get richedit.au3 from?

i think there are several on the forums.

Also i'd like to see some encryption add as well..

so ppl cant sniff your conversation.

thanks for the effort that went into this!

Share this post


Link to post
Share on other sites

where do you get richedit.au3 from?

i think there are several on the forums.

Also i'd like to see some encryption add as well..

so ppl cant sniff your conversation.

thanks for the effort that went into this!

i think its almost encrypted to the maximum with _stringencrypt

to get it more secure i whould need to use some other more complex form of encrypting.

i think it whould be very hard for people to sniff your conversation when the encryption key changes to something random every 15sec.

you could change the random key lenght to something like 20 or 30 and make it change key every 5 sec to make it more secure.

i whouldent recoment going lower then 5sec

richedit.au3:

#include-once
#include <dllcallback.au3>
Opt("MustDeclareVars", 1)

;Global Const $WM_USER = 0x0400
Global Const $EM_STREAMIN = 0x400+73
Global Const $EM_STREAMOUT = 0x400+74
Global Const $SF_RTF = 2
Global $fSet
Global $sRTFClassName, $pEditStreamCallback, $dll, $sGetRtf, $sSetRtf 

Global $EDITSTREAM = DllStructCreate("DWORD pdwCookie;DWORD dwError;PTR pfnCallback")
$pEditStreamCallback = _DllCallBack("_EditStreamCallback", "ptr;ptr;long;ptr")
DllStructSetData($EDITSTREAM, "pfnCallback", $pEditStreamCallback)

If FileExists(@SystemDir & "\Msftedit.dll") Then
    $dll = DllOpen("MSFTEDIT.DLL")
    $sRTFClassName = "RichEdit50W"
    ;$dll = DllOpen("RICHED20.DLL")
    ;$sRTFClassName = "RichEdit20A"
Else
    ;MSFTEDIT.DLL
    $dll = DllOpen("RICHED20.DLL")
    $sRTFClassName = "RichEdit20A"
EndIf

;events mask
Global Const $ENM_CHANGE = 0x1
Global Const $ENM_CORRECTTEXT = 0x400000
Global Const $ENM_DRAGDROPDONE = 0x10
Global Const $ENM_DROPFILES = 0x100000
Global Const $ENM_IMECHANGE = 0x800000
Global Const $ENM_KEYEVENTS = 0x10000
Global Const $ENM_LINK = 0x4000000
Global Const $ENM_MOUSEEVENTS = 0x20000
Global Const $ENM_OBJECTPOSITIONS = 0x2000000
Global Const $ENM_PROTECTED = 0x200000
Global Const $ENM_REQUESTRESIZE = 0x40000
Global Const $ENM_SCROLL = 0x4
Global Const $ENM_SCROLLEVENTS = 0x8
Global Const $ENM_SELCHANGE = 0x80000
Global Const $ENM_UPDATE = 0x2
Global Const $EM_AUTOURLDETECT = $WM_USER + 91
Global Const $EM_FINDTEXT = $WM_USER + 56

;Global Const $EM_GETLINE = 0xC4
;global Const $EM_GETSEL = 0xB0
Global Const $EM_EXLIMITTEXT = $WM_USER+53
Global Const $EM_GETSELTEXT = $WM_USER + 62
Global Const $EM_GETTEXTEX = $WM_USER + 94
Global Const $EM_GETTEXTLENGTHEX = $WM_USER + 95
Global Const $EM_GETTEXTMODE = $WM_USER + 90
Global Const $EM_GETTEXTRANGE = $WM_USER + 75
Global Const $EM_GETSCROLLPOS = $WM_USER + 221
Global Const $EM_HIDESELECTION = ($WM_USER + 63)
Global Const $EM_SETPASSWORDCHAR = 0xCC
Global Const $EM_SETFONTSIZE = $WM_USER + 223
Global Const $EM_SETBKGNDCOLOR = ($WM_USER + 67)
Global Const $EM_GETCHARFORMAT = 1082
Global Const $EM_SETCHARFORMAT = 1092
global Const $EM_FINDWORDBREAK = $WM_USER + 76
Global Const $EM_REQUESTRESIZE = ($WM_USER + 65)
Global Const $EM_EXGETSEL = $WM_USER+52
Global Const $EM_SETPARAFORMAT = $WM_USER+71
Global Const $EM_GETPARAFORMAT = $WM_USER+61

Global Const $EN_LINK = 0x70b
Global Const $EN_MSGFILTER = 0x700
Global Const $EN_PROTECTED = 0x704
Global Const $EN_SELCHANGE = 0x702

Global Const $SCF_DEFAULT = 0x0
Global Const $SCF_SELECTION = 0x01
Global Const $SCF_WORD = 0x0002

Global Const $SFF_SELECTION = 0x8000

;constants for the CHARFORMAT2
Global Const $CFM_BOLD = 0x00000001
Global Const $CFM_ITALIC = 0x00000002
Global Const $CFM_UNDERLINE = 0x00000004
Global Const $CFM_STRIKEOUT = 0x00000008
Global Const $CFM_PROTECTED = 0x00000010
Global Const $CFM_DISABLED = 0x2000
Global Const $CFM_LINK = 0x00000020 ;/ * Exchange hyperlink extension * /
Global Const $CFM_SIZE = 0x80000000
Global Const $CFM_COLOR = 0x40000000
Global Const $CFM_FACE = 0x20000000
Global Const $CFM_OFFSET = 0x10000000
Global Const $CFM_RichEdit_SET = 0x08000000
Global Const $CFM_WEIGHT = 0x00400000
Global Const $CFM_BACKCOLOR = 0x04000000
Global Const $CFM_SPACING = 0x200000
Global Const $CFM_UNDERLINETYPE = 0x800000
Global Const $CFM_STYLE = 0x80000
Global Const $CFM_REVISED = 0x4000

; CHARFORMAT effects */
Global Const $CFE_BOLD = 0x0001
Global Const $CFE_ITALIC = 0x0002
Global Const $CFE_UNDERLINE = 0x0004
Global Const $CFE_STRIKEOUT = 0x0008
Global Const $CFE_PROTECTED = 0x0010
Global Const $CFE_DISABLED = $CFM_DISABLED
Global Const $CFE_LINK = 0x0020
Global Const $CFE_AUTOCOLOR = 0x40000000
Global Const $CFE_REVISED = $CFM_REVISED

Global Const $EM_SETEVENTMASK = $WM_USER + 69
;
Global Const $CFU_UNDERLINEDOUBLE = 3
Global Const $CFU_UNDERLINEWORD = 2

Global Const $PFA_LEFT = 0x1
Global Const $PFA_RIGHT = 0x2
Global Const $PFA_CENTER = 0x3
Global Const $PFA_JUSTIFY = 4

Global Const $PFE_TABLE = 0x4000

Global Const $PFM_NUMBERING = 0x20
Global Const $PFM_ALIGNMENT = 0x8
Global Const $PFM_SPACEBEFORE = 0x40
Global Const $PFM_NUMBERINGSTYLE = 0x2000
Global Const $PFM_NUMBERINGSTART = 0x8000
Global Const $PFM_BORDER = 0x800
Global Const $PFM_RIGHTINDENT = 0x2
Global Const $PFM_STARTINDENT = 0x1
Global Const $PFM_OFFSET = 0x4
Global Const $PFM_LINESPACING = 0x100
Global Const $PFM_SPACEAFTER = 0x80
Global Const $PFM_NUMBERINGTAB = 0x4000
Global Const $PFM_TABLE = 0x40000000

Global Const $PFN_BULLET = 0x1

global Const $WB_CLASSIFY = 3
global Const $WB_ISDELIMITER = 2
global Const $WB_LEFT = 0
global Const $WB_LEFTBREAK = 6
global Const $WB_MOVEWORDLEFT = 4
global Const $WB_MOVEWORDNEXT = 5
global Const $WB_MOVEWORDPREV = 4
global Const $WB_MOVEWORDRIGHT = 5
global Const $WB_NEXTBREAK = 7
global Const $WB_PREVBREAK = 6
global Const $WB_RIGHT = 1
global Const $WB_RIGHTBREAK = 7

Global Const $WM_LBUTTONDOWN = 0x201
Global Const $WM_RBUTTONDOWN = 0x204
Global Const $WM_LBUTTONDBLCLK = 0x203
Global Const $WM_MOUSEMOVE = 0x200

Global Const $GT_DEFAULT = 0
Global Const $GT_SELECTION = 2

Global Const $tagCHARFORMAT2 = "uint;int;dword;long;long;dword;byte;byte;char[32];short;short;long;long;long;short;short;byte;byte;byte;byte"
;                                                                                   10    11    12     13  14   15    16    17   18   19   20
;           "cbSize, dwMask, dwEffects, yHeight, yOffset, crTextColor, bCharSet, bPitchAndFamily, szFaceName, wWeight, sSpacing, crBackColor, " & _
;           "lcid, dwReserved, sStyle, wKerning, bUnderlineType, bAnimation, bRevAuthor, bReserved1" (84)

Global Const $tagPARAFORMAT = "uint;uint;short;short;int;int;int;short;short;int[32]"
;~ UINT cbSize;
;~ DWORD dwMask;
;~ WORD wNumbering;
;~ WORD wReserved;
;~ LONG dxStartIndent;
;~ LONG dxRightIndent;
;~ LONG dxOffset;
;~ WORD wAlignment;
;~ SHORT cTabCount;
;~ LONG rgxTabs[MAX_TAB_STOPS];

;Global Const $tagPARAFORMAT2 = "uint;uint;short;short;int;int;int;short;short;int[32];long;short;ushort;ulong;ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort;ushort"
Global Const $tagPARAFORMAT2 = "uint;uint;short;short;int;int;int;short;short;int[32];int;int;int;ushort;byte;byte;short;short;short;short;short;short;short;short"
;                                1    2    3      4    5   6   7    8     9     10    11  12  13    14    15   16   17    18    19    20    21    22     23    24  
;~ UINT cbSize;
;~ DWORD dwMask;
;~ WORD  wNumbering;
;~ WORD  wEffects;
;~ LONG  dxStartIndent;
;~ LONG  dxRightIndent;
;~ LONG  dxOffset;
;~ WORD  wAlignment;
;~ SHORT cTabCount;
;~ LONG  rgxTabs[MAX_TAB_STOPS];
;~ LONG  dySpaceBefore;
;~ LONG  dySpaceAfter;
;~ LONG  dyLineSpacing;
;~ SHORT sStyle;
;~ BYTE  bLineSpacingRule;
;~ BYTE  bOutlineLevel;
;~ WORD  wShadingWeight;
;~ WORD  wShadingStyle;
;~ WORD  wNumberingStart;
;~ WORD  wNumberingStyle;
;~ WORD  wNumberingTab;
;~ WORD  wBorderSpace;
;~ WORD  wBorderWidth;
;~ WORD  wBorders;

Global $tagTEXTEX = "dword;dword;uint;char;int"
;                   "cbSize, flags, codepage, lpDefaultChar, lpUsedDefChar"
Global $tagCHARRANGE = "long;long"
;                       "cpMin, cpMax"
Global $tagFINDTEXT = "ptr;str"
;                   "CHARRANGE, lpstrText"      
;Global $tagLOGFONT = "long;long;long;long;long;byte;byte;byte;byte;byte;byte;byte;byte;char[32]"
;                   "lfHeight, lfWidth, lfEscapement, lfOrientation, lfWeight, lfItalic, lfUnderline, lfStrikeOut, lfCharset, " &_ 
;                   "lfOutPrecision, lfClipPrecision, lfQuality, lfPitchAndFamily, lfFaceName" & _



Global $tagENLINK = $tagNMHDR & ";uint msg;int wParam;int lParam;" & $tagCHARRANGE

Global $tagEN_MSGFILTER = $tagNMHDR & ";uint msg;int wParam;int lParam;"

Global $tagENPROTECTED = $tagNMHDR & ";uint msg;int wParam;int lParam;" & $tagCHARRANGE

Global $tagSELCHANGE = $tagNMHDR & ";" & $tagCHARRANGE & ";long seltyp;"

Global $tcharformat = DllStructCreate($tagCHARFORMAT2)
DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
Global $tparaformat = DllStructCreate($tagPARAFORMAT2)
DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))



#cs===================================================================================================
 (*) ==> Functions that are not needed, because there are the same /similar functions in
 3.2.10 (GuiEdit.au3)!!!
 
 _GuiCtrl_RichEdit_Create
 _RichEdit_AddText(*)
 _RichEdit_BkColor 
 _RichEdit_GetFontName
 _RichEdit_GetFontSize
 _RichEdit_GetLineCount
 _RichEdit_GetBold
 _RichEdit_GetItalic 
 _RichEdit_GetUnderline
 _RichEdit_GetStrikeOut
 _RichEdit_GetFontColor
 _RichEdit_GetBkColor
 _RichEdit_GetFormat
 _RichEdit_GetSelection(*)         
 _RichEdit_GetText(*)
 _RichEdit_GetSelText
 _RichEdit_IncreaseFontSize
 _RichEdit_LimitText(*)
 _RichEdit_SetAlignment
 _RichEdit_SetFontName
 _RichEdit_SetFontSize
 _RichEdit_SetBold
 _RichEdit_SetItalic
 _RichEdit_SetLineSpacing
 _RichEdit_SetLink
 _RichEdit_SetOffSet
 _RichEdit_SetProtected
 _RichEdit_SetUnderline
 _RichEdit_SetStrikeOut
 _RichEdit_SetFontColor
 _RichEdit_SetBkColor
 _RichEdit_SetEventMask
 _RichEdit_SetNumbering
 _RichEdit_SetReadOnly(*)
 _RichEdit_SetSel(*)
 _RichEdit_ToggleBold
 _RichEdit_ToggleItalic
 _RichEdit_ToggleUnderline
 _RichEdit_ToggleStrikeOut
 _RichEdit_Undo(*)
#ce===================================================================================================

;=====================================================================================================
; _GuiCtrl_RichEdit_Create
; _GuiCtrl_RichEdit_CreateInput
;=====================================================================================================

Func _GuiCtrl_RichEdit_Create($hWnd, $x, $y, $width, $height, $dwStyle = -1, $dwExStyle = -1)
    If $dwStyle = -1 Then $dwStyle = BitOR($WS_CHILD, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_VSCROLL, $WS_TABSTOP, $WS_VISIBLE, $ES_MULTILINE)
    If $dwExStyle = -1 Then $dwExStyle = $WS_EX_CLIENTEDGE
    Return _WinAPI_CreateWindowEx($dwExStyle, $sRTFClassName, "", $dwStyle, $x, $y, $width, $height, $hWnd)
EndFunc

Func _GuiCtrl_RichEdit_CreateInput($hWnd, $x, $y, $width, $height, $dwStyle = -1, $dwExStyle = -1)
    If $dwStyle = -1 Then $dwStyle = BitOR($WS_CHILD, $ES_WANTRETURN, $ES_NOHIDESEL, $WS_VISIBLE)
    If $dwExStyle = -1 Then $dwExStyle = $WS_EX_CLIENTEDGE
    Return _WinAPI_CreateWindowEx($dwExStyle, $sRTFClassName, "", $dwStyle, $x, $y, $width, $height, $hWnd)
EndFunc



; ====================================================================================================
; Description ..: Appends some text to the control
; Parameters ...: $hWnd         - Handle to the control
;                 $iText        - Text to append
;                 $i_udone      - if True, can be undone        
; Return values : none
; Author .......: grham
; Notes ........: appended to a selection; if no selection, at the caret 
; ====================================================================================================
Func _RichEdit_AddText($hWnd, $iText, $i_undone = True)
    Local $Buffer = DllStructCreate("char[" & StringLen($iText)+1 & "]")
    DllStructSetData($Buffer, 1, $iText)
    _SendMessage($hWnd, $EM_REPLACESEL, $i_undone, DllStructGetPtr($Buffer))
    $Buffer = 0
EndFunc   ;==>_RichEdit_AddText

; ====================================================================================================
; Description ..: Sets a background color of a richedit control
; Parameters ...: $hWnd         - Handle to the control
;                 $iColor       - Color to set
; Return values : none
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_BkColor($hWnd, $iColor)
    _SendMessage($hWnd, $EM_SETBKGNDCOLOR, 0, $iColor)
EndFunc ;==> _RichEdit_BkColor

; ====================================================================================================
; Description ..: _RichEdit_GetFontName
; Parameters ...: $hWnd         - Handle to the control
; Return values : Font name
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetFontName($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return DllStructGetData($tcharformat, 9)
EndFunc ;==>_RichEdit_GetFontName

; ====================================================================================================
; Description ..: _RichEdit_GetFontSize
; Parameters ...: $hWnd         - Handle to the control
; Return values : Font size
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetFontSize($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return DllStructGetData($tcharformat, 4)/20
EndFunc ;==>_RichEdit_GetFontSize

; ====================================================================================================
; Description ..: Get the Line Count for the Control
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns the line count if successful
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_GetLineCount($hWnd)
    Return _SendMessage($hWnd, $EM_GETLINECOUNT, 0, 0)
EndFunc   ;==>_RichEdit_GetLineCount

; ====================================================================================================
; Description ..: _RichEdit_GetBold
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns True or False
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetBold($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return BitAND(DllStructGetData($tcharformat, 3), $CFE_BOLD)/ 1
EndFunc   ;==>_RichEdit_GetBold

; ====================================================================================================
; Description ..: _RichEdit_GetItalic
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns True or False
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetItalic($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
     _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return BitAND(DllStructGetData($tcharformat, 3), $CFE_ITALIC)/ 2
EndFunc   ;==>_RichEdit_GetItalic

; ====================================================================================================
; Description ..: _RichEdit_GetUnderline
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns True or False
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetUnderline($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
     _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return BitAND(DllStructGetData($tcharformat, 3), $CFE_Underline)/4
EndFunc   ;==>_RichEdit_GetUnderline

; ====================================================================================================
; Description ..: _RichEdit_GetStrikeOut
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns True or False
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetStrikeOut($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
     _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return BitAND(DllStructGetData($tcharformat, 3), $CFE_STRIKEOUT)/8
EndFunc   ;==>_RichEdit_GetStrikeOut

; ====================================================================================================
; Description ..: _RichEdit_GetFontColor
; Parameters ...: $hWnd         - Handle to the control
; Return values : Font color (Hex)
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetFontColor($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
     _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return 0 & "x" & StringTrimLeft(Hex(DllStructGetData($tcharformat, 6)), 2)
EndFunc   ;==>_RichEdit_GetFontColor

; ====================================================================================================
; Description ..: _RichEdit_GetBkColor
; Parameters ...: $hWnd         - Handle to the control
; Return values : Background color (Hex)
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetBkColor($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    Return 0 & "x" & StringTrimLeft(Hex(DllStructGetData($tcharformat, 12)), 2)
EndFunc   ;==>_RichEdit_GetBkColor

; ====================================================================================================
; Description ..: _RichEdit_GetFormat
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns an Array with font format
;                           index 0: bold-italic-underline-strikeout
;                                 1: fontcolor          
;                                 2: backgroundcolor                
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetFormat($hWnd)
    Local $Array[3]
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
     _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    $Array[0] = BitAND(DllStructGetData($tcharformat, 3), $CFE_BOLD)/1 & _
                BitAND(DllStructGetData($tcharformat, 3), $CFE_ITALIC)/2 & _
                BitAND(DllStructGetData($tcharformat, 3), $CFE_Underline)/4 & _
                BitAND(DllStructGetData($tcharformat, 3), $CFE_STRIKEOUT)/8
    $Array[1] = 0 & "x" & StringTrimLeft(Hex(DllStructGetData($tcharformat, 6)), 2)
    $Array[2] = 0 & "x" & StringTrimLeft(Hex(DllStructGetData($tcharformat, 12)), 2)
    Return $Array
EndFunc   ;==>_RichEdit_getformat

; ====================================================================================================
; Description ..: _RichEdit_GetSelection
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns the beginning and the ending position of the selection
; Author .......: 
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetSelection($hWnd)
    Local $tcharrange = DllStructCreate($tagCHARRANGE), $Array[2]
    _SendMessage ($hWnd, $EM_EXGETSEL, 0, DllStructGetPtr($tcharrange))
    $Array[0] = DllStructGetData($tcharrange, 1)
    $Array[1] = DllStructGetData($tcharrange, 2)
    Return $Array
EndFunc ;==>_RichEdit_GetSelection

; ====================================================================================================
; Description ..: _RichEdit_GetText
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns a text form a RTC as plain text
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetText($hWnd)
    Local $textex = DllStructCreate($tagTEXTEX)
    Local $Buffer = DllStructCreate("wchar[" & _SendMessage($hWnd, $WM_GETTEXTLENGTH, 0, 0)+1 & "]")
    ;DllStructSetData($textex, 1, DllStructGetSize($Buffer))
    DllStructSetData($textex, 2, $GT_DEFAULT)
    DllStructSetData($textex, 3, 1200)
    DllStructSetData($textex, 4, 0)
    DllStructSetData($textex, 5, 0)
    _SendMessage ($hWnd, $EM_GETTEXTEX, DllStructGetPtr($textex), DllStructGetPtr($Buffer));
    Return DllStructGetData($Buffer, 1)
EndFunc ;==>_RichEdit_GetText

; ====================================================================================================
; Description ..: _RichEdit_GetSelText
; Parameters ...: $hWnd         - Handle to the control
; Return values : Returns a portion of a text selected
; Author .......: grham
; Notes ........: 
; ====================================================================================================
Func _RichEdit_GetSelText($hWnd)
    Local $Sel = _RichEdit_GetSelection($hWnd)
    Local $buffer = DllStructCreate("wchar[" & ($Sel[1]-$Sel[0])+1 & "]")
    DllCall("user32.dll", "int", "SendMessage", "hwnd", $hWnd, "int", $EM_GETSELTEXT, "int", 0, "ptr", DllStructGetPtr($buffer))
    Return DllStructGetData($buffer, 1)
EndFunc ;==>_RichEdit_GetSelText

; ====================================================================================================
; Description ..: Increase or decrease the font size
; Parameters ...: $hWnd         - Handle to the control
;                 $hDelta       - Value of incrementation, Negative ==> decrementation
; Return values : Returns True if successful, or False otherwise
; Author .......: 
; Notes ........: Apllied to the the end of text
; ====================================================================================================
Func _RichEdit_IncreaseFontSize($hWnd, $hDelta = 1)                                     
    Local $textlength = _SendMessage ($hWnd, $WM_GETTEXTLENGTH, 0, 0)
    _RichEdit_SetSel($hWnd, $textlength, $textlength, 1)
    Return _SendMessage ($hWnd, $EM_SETFONTSIZE, $hDelta, 0)
EndFunc   ;==>_RichEdit_IncreaseFontSize

; ====================================================================================================
; Description ..: Limit the control to N chararacters
; Parameters ...: $hWnd         - Handle to the control
;                 $hLimitTo     - Number of characters
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Notes ........: Set 0 to disable the limit
; ====================================================================================================
Func _RichEdit_LimitText($hWnd, $hLimitTo)
    Return _SendMessage($hWnd, $EM_LIMITTEXT, $hLimitTo, 0)
EndFunc   ;==>_RichEdit_LimitText

; ====================================================================================================
; Description ..: Paragraph alignment.
; Parameters ...: $hWnd         - Handle to the control
;                 $iAlignment   Values: 
;                               1 or $PFA_LEFT      Paragraphs are aligned with the left margin.
;                               2 or $PFA_RIGHT     Paragraphs are aligned with the right margin.
;                               3 or $PFA_CENTER    Paragraphs are centered.
;                               4 or $PFA_JUSTIFY   Paragraphs are justified. This value is 
;                                                   +included for compatibility with TOM interfaces; 
;                                                   +rich edit controls earlier than Rich Edit 3.0 
;                                                   +display the text aligned with the left margin.
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetAlignment($hWnd, $iAlignment)     ; 1 ==> Left, 2 ==> Right, 3 ==> Center, 4 ==> Justify 
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, $PFM_ALIGNMENT)
    DllStructSetData($tparaformat, 8, $iAlignment)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc

; ====================================================================================================
; Description ..: Select the Font Name
; Parameters ...: $hWnd         - Handle to the control
;                 $hFontName    - Name of the Font
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Modified .....: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetFontName($hWnd, $hFontName, $iSelec = True)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_FACE)
    DllStructSetData($tcharformat, 9, $hFontName)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetFontName

; ====================================================================================================
; Description ..: _RichEdit_SetFontSize
; Parameters ...: $hWnd        - Handle to the control
;                 $iSize       - Size of the Font
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Modified .....: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetFontSize($hWnd, $iSize , $iSelec = True)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_SIZE)
    DllStructSetData($tcharformat, 4, $iSize*20)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc ;==>_RichEdit_SetFontSize

; ====================================================================================================
; Description ..: Toggle the Bold effect
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Modified ....:  grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetBold($hWnd, $iStyle = True, $iSelec = True, $iHL = True)
    If $iStyle Then $iStyle = $CFE_BOLD
    If $iHL Then $iHL = $CFE_LINK
    DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_BOLD)
    DllStructSetData($tcharformat, 3, $iStyle)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetBold

; ====================================================================================================
; Description ..: Toggle the Italic effect
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Modified ....:  grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetItalic($hWnd, $iStyle = True, $iSelec = True)
    If $iStyle Then $iStyle = $CFE_ITALIC
    DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_ITALIC)
    DllStructSetData($tcharformat, 3, $iStyle)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetItalic

; ====================================================================================================
; Description ..: Type of line spacing.
; Parameters ...: $hWnd         - Handle to the control
;                 $iNum         Values: 
;                               0                   Single spacing.
;                               1                   One-and-a-half spacing.
;                               2                   Double spacing.
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetLineSpacing($hWnd, $iNum, $iTwips = 0)    ; 0 => 1, 1 => 1+1/2; 2 => 2
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, BitOr($PFM_LINESPACING, $PFM_SPACEAFTER))
    If $iTwips <> 0 Then DllStructSetData($tparaformat, 13, $iTwips*20)
    DllStructSetData($tparaformat, 15, $iNum)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc ;==> _RichEdit_SetLineSpacing

; ====================================================================================================
; Description ..: Toggle the Underline effect
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetLink($hWnd, $iStyle = True, $iSelec = True)
    If $iStyle Then $iStyle = $CFE_LINK
    DllStructSetData($tcharformat, 2, $CFM_LINK)
    DllStructSetData($tcharformat, 3, $iStyle)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetLink

; ====================================================================================================
; Description ..: Indentation of the second and subsequent lines, 
;                 +relative to the indentation of the first line, in twips.
; Parameters ...: $hWnd         - Handle to the control
;                 $iOffset - (here: twips/100)
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetOffSet($hWnd, $iOffset)
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, $PFM_OFFSET)
    DllStructSetData($tparaformat, 7, $iOffset*100)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc

; ====================================================================================================
; Description ..: Characters are protected; 
;                 +an attempt to modify them will cause an EN_PROTECTED notification message.
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================

Func _RichEdit_SetProtected($hWnd, $iStyle = True, $iSelec = True)      
    If $iStyle Then $iStyle = $CFE_PROTECTED
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tcharformat, 2, $CFM_PROTECTED)
    DllStructSetData($tcharformat, 3, $iStyle)
    _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc ;==> _RichEdit_SetProtected

; ====================================================================================================
; Description ..: Characters are marked as revised.
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetRevised($hWnd, $iStyle = True, $iSelec = True)        
    If $iStyle Then $iStyle = $CFE_REVISED
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tcharformat, 2, $CFM_REVISED)
    DllStructSetData($tcharformat, 3, $iStyle)
    _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc ;==> _RichEdit_SetProtected

; ====================================================================================================
; Description ..: Toggle the Underline effect
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetUnderline($hWnd, $iStyle = True, $iSelec = True)
    If $iStyle Then $iStyle = $CFE_UNDERLINE
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_UNDERLINE)
    DllStructSetData($tcharformat, 3, $iStyle)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetUnderline

; ====================================================================================================
; Description ..: Toggle the Strike Out effect
; Parameters ...: $hWnd         - Handle to the control
;                 $iStyle       - True = Set; False = Unset
;                 $iSelec       - Modify entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Rewritten ....: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetStrikeOut($hWnd, $iStyle = True, $iSelec = True)
    If $iStyle Then $iStyle = $CFE_STRIKEOUT
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_STRIKEOUT)
    DllStructSetData($tcharformat, 3, $iStyle)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc

; ====================================================================================================
; Description ..: Select the text color
; Parameters ...: $hWnd         - Handle to the control
;                 $hColor       - Color value
;                 $iSelect      - Color entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Rewritten ....: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetFontColor($hWnd, $hColor, $iSelec = True)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_COLOR)
    DllStructSetData($tcharformat, 6, $hColor)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetColor

; ====================================================================================================
; Description ..: Select the Background text color                                      
; Parameters ...: $hWnd         - Handle to the control
;                 $hColor       - Color value
;                 $iSelec       - Color entire text or selection (default)
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Rewritten ....: grham (works)
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetBkColor($hWnd, $hColor, $iSelec = True)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_BACKCOLOR)
    DllStructSetData($tcharformat, 12, $hColor)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetBkColor

; ====================================================================================================
; Description ..: The EM_SETEVENTMASK message sets the event mask for a rich edit control.
;           The event mask specifies which notification messages the control sends to its parent window
; Parameters ...: $hWnd         - Handle to the control
;                 $hMin         - Character Number start
;                 $hMax         - Character Number stop
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetEventMask($hWnd, $hFunction)
    Return _SendMessage ($hWnd, $EM_SETEVENTMASK, 0, $hFunction)
EndFunc   ;==>_RichEdit_SetEventMask

; ====================================================================================================
; Description ..: Sets paragraph numbering and numbering type
; Parameters ...: $hWnd         - Handle to the control
;                 $iChar        - Characters used for numbering:
;                               0                   No numbering
;                               1 or $PFN_BULLET    Inserts a bullet
;                               2                   Arabic numbres (1,2,3 ...)
;                               3                   Lowercase tetters
;                               4                   Uppercase letters
;                               5                   Lowercase roman numerals (i,ii,iii...)
;                               6                   Uppercase roman numerals (I, II, ...)
;                               7                   Uses a sequence of characters beginning with 
;                                                   +the Unicode character specified by 
;                                                   +the wNumberingStart member
;                 $iFormat      - Numbering style used with numbered paragraphs
;                               0                   Follows the number with a right parenthesis.
;                               0x100               Encloses the number in parentheses. 
;                               0x200               Follows the number with a period.
;                               0x300               Displays only the number.
;                               0x400               Continues a numbered list without 
;                                                   +applying the next number or bullet. 
;                               0x8000              Starts a new number with wNumberingStart.
;                 $iStart       - Starting number or Unicode value used for numbered paragraphs.
;                 $iTab         - Minimum space between a paragraph number and the paragraph text, in twips.
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetNumbering($hWnd, $iChar = 0, $iFormat = 0x200, $iStart = 1, $iTab = 300)  
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, BitOr($PFM_NUMBERING, $PFM_NUMBERINGSTART, $PFM_NUMBERINGSTYLE, $PFM_NUMBERINGTAB))
    DllStructSetData($tparaformat, 3, $iChar)
    DllStructSetData($tparaformat, 19, $iStart)
    DllStructSetData($tparaformat, 20, $iFormat)
    DllStructSetData($tparaformat, 21, $iTab)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc ;==> _RichEdit_SetNumbering

; ====================================================================================================
; Description ..: Set the control in ReadOnly Mode
; Parameters ...: $hWnd         - Handle to the control
;                 $hBool        - True = Enabled, False = Disabled
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetReadOnly($hWnd, $hBool = True)
    Return _SendMessage ($hWnd, $EM_SETREADONLY, $hBool, 0)
EndFunc   ;==>_RichEdit_SetReadOnly

; ====================================================================================================
; Description ..: Select some text
; Parameters ...: $hWnd         - Handle to the control
;                 $hMin         - Character Number start
;                 $hMax         - Character Number stop
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetSel($hWnd, $hMin, $hMax, $HideSel = 0)
    _SendMessage ($hWnd, $EM_SETSEL, $hMin, $hMax)
    _SendMessage($hWnd, $EM_HIDESELECTION, $HideSel)
EndFunc   ;==>_RichEdit_SetSel

; ====================================================================================================
; Description ..: Size of the spacing below the paragraph, in twips.
; Parameters ...: $hWnd         - Handle to the control
;                 $iNum         - The value must be greater than or equal to zero. (here: twips/100)
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetSpaceAfter($hWnd, $iNum)
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, $PFM_SPACEAFTER)
    DllStructSetData($tparaformat, 12, $iNum*100)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc ;==> _RichEdit_SetSpaceAfter

; ====================================================================================================
; Description ..: Size of the spacing above the paragraph, in twips.
; Parameters ...: $hWnd         - Handle to the control
;                 $iNum         - The value must be greater than or equal to zero. (here: twips/100)
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetSpaceBefore($hWnd, $iNum)
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, $PFM_SPACEBEFORE)
    DllStructSetData($tparaformat, 11, $iNum*100)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc ;==>_RichEdit_SetSpaceBefore

; ====================================================================================================
; Description ..: Indentation of the paragraph's first line, in twips.
; Parameters ...: $hWnd         - Handle to the control
;                 $iStartIndent - (here: twips/100)
; Return values : None
; Author .......: grham
; Notes ........:
; ====================================================================================================
Func _RichEdit_SetStartIndent($hWnd, $iStartIndent)
    ;DllStructSetData($tparaformat, 1, DllStructGetSize($tparaformat))
    DllStructSetData($tparaformat, 2, $PFM_STARTINDENT)
    DllStructSetData($tparaformat, 5, $iStartIndent*100)
    _SendMessage($hWnd, $EM_SETPARAFORMAT, 0, DllStructGetPtr($tparaformat))
EndFunc ;==> _RichEdit_SetStartIndent

; ====================================================================================================
; Description ..: _RichEdit_ToggleBold
; Parameters ...: $hWnd         - Handle to the control
; Return values : none
; Author .......: 
; Notes ........: 
; ====================================================================================================
Func _RichEdit_ToggleBold($hWnd)
    _RichEdit_SetBold($hWnd, Not _RichEdit_GetBold($hWnd))
EndFunc ;==>_RichEdit_ToggleBold

; ====================================================================================================
; Description ..: _RichEdit_ToggleItalic
; Parameters ...: $hWnd         - Handle to the control
; Return values : none
; Author .......: 
; Notes ........: 
; ====================================================================================================
Func _RichEdit_ToggleItalic($hWnd)
    _RichEdit_SetItalic($hWnd, Not _RichEdit_GetItalic($hWnd))
EndFunc ;==>_RichEdit_ToggleItalic

; ====================================================================================================
; Description ..: _RichEdit_ToggleUnderline
; Parameters ...: $hWnd         - Handle to the control
; Return values : none
; Author .......: 
; Notes ........: 
; ====================================================================================================
Func _RichEdit_ToggleUnderline($hWnd)
    _RichEdit_SetUnderline($hWnd, Not _RichEdit_GetUnderline($hWnd))
EndFunc ;==>_RichEdit_ToggleUnderline

; ====================================================================================================
; Description ..: _RichEdit_ToggleStrikeOut
; Parameters ...: $hWnd         - Handle to the control
; Return values : none
; Author .......: 
; Notes ........: 
; ====================================================================================================
Func _RichEdit_ToggleStrikeOut($hWnd)
    _RichEdit_SetStrikeOut($hWnd, Not _RichEdit_GetStrikeOut($hWnd))
EndFunc ;==>_RichEdit_ToggleStrikeOut

; ====================================================================================================
; Description ..: Undo
; Parameters ...: $hWnd         - Handle to the control
;                 $hMin         - Character Number start
;                 $hMax         - Character Number stop
; Return values : True on success, otherwise False
; Author .......: Yoan Roblet (Arcker)
; Notes ........:
; ====================================================================================================
Func _RichEdit_Undo($hWnd)
    Return _SendMessage ($hWnd, $EM_UNDO, 0, 0)
EndFunc   ;==>_RichEdit_Undo

;=============================================================================================================
;   for experiments only    
;=============================================================================================================

Func _RichEdit_SetUnderlineDouble($hWnd, $iStyle = True, $iSelec = True)        ; doesn't show!!!
    If $iStyle Then $iStyle = $CFU_UNDERLINEDOUBLE
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    DllStructSetData($tcharformat, 2, $CFM_UNDERLINETYPE)
    DllStructSetData($tcharformat, 17, $iStyle)
    Return _SendMessage($hWnd, $EM_SETCHARFORMAT, $iSelec, DllStructGetPtr($tcharformat))
EndFunc   ;==>_RichEdit_SetUnderline

Func _ReadStruct($hWnd)
    ;DllStructSetData($tcharformat, 1, DllStructGetSize($tcharformat))
    _SendMessage ($hWnd, $EM_GETCHARFORMAT, $SCF_SELECTION, DllStructGetPtr($tcharformat))
    For $x = 1 To 20
        ConsoleWrite("Index " & $x & ": " & DllStructGetData($tcharformat, $x) & @CRLF)
    Next    
EndFunc 

Opt("MustDeclareVars", 0)

dllcallback.au3:

#include-once
Opt("MustDeclareVars", 1)
#cs
    CallTips:
    _DllCallBack($sFunction, [$sParameters, [$nOptions]]) Registers a Callback function, Returns a pointer (DllCallBack.au3)
    _DllCallBack_Free($pStub) Unregister Callback function and free memory (DllCallBack.au3)
#ce

; Adjustable values
Global Const $gi_DllCallBack_uiMsg = 0x7FFF ; WM_USER + 0x7BFF
Global Const $gi_DllCallBack_MaxStubs = 64

; Constants for $nOptions
Global Const $_DllCallBack_StdCall = 0
Global Const $_DllCallBack_Cdecl = 1
Global Const $_DllCallBack_Sync = 2
Global Const $_DllCallBack_Subclass = 4
Global Const $_DllCallBack_Struct = 8
Global Const $_DllCallBack_Debug = 1024

; Internaly used
Global Const $gs_DllCallBack_typedef_CriticalSection = "PTR DebugInfo;LONG LockCount;LONG RecursionCount;PTR OwningThread;PTR LockSemaphore;DWORD SpinCount"
Global $gp_DllCallBack_SendMessage = 0
Global $gh_DllCallBack_hUser32 = 0
Global $gi_DllCallBack_StubCount = 0
Global $gp_DllCallBack_EnterCriticalSection = 0
Global $gp_DllCallBack_LeaveCriticalSection = 0
Global $gp_DllCallBack_CallWindowProc = 0
Global $gh_DllCallBack_hWnd = GUICreate("au3_Callback")
Global $gf_DllCallBack_fMsgRegistred = GUIRegisterMsg($gi_DllCallBack_uiMsg, "__DllCallBack_MsgHandler")
Global $ga_DllCallBack_sParameters[$gi_DllCallBack_MaxStubs + 1]
Global $ga_DllCallBack_nParameters[$gi_DllCallBack_MaxStubs + 1]
Global $ga_DllCallBack_sFunctions[$gi_DllCallBack_MaxStubs + 1]
Global $ga_DllCallBack_hGlobals[$gi_DllCallBack_MaxStubs + 1]
Global $ga_DllCallBack_vCriticalSections[$gi_DllCallBack_MaxStubs + 1]
Global $ga_DllCallBack_nOptions[$gi_DllCallBack_MaxStubs + 1]

;===============================================================================
;
; Function Name:    _DllCallBack
; Description:      Registers a callback function and creates a stub which handles incoming calls.
; Parameter(s):     $sFunction - Name of callback function
;                   $sParameters - DllStruct like parameter definition (only 32 and 64bit datatypes supported)
;                   $nOptions, Optional - Can be one or more (add them together) of the folowing constants:
;                       $_DllCallBack_StdCall (0)  - Use 'stdcall' calling method (Default)
;                       $_DllCallBack_Cdecl (1)    - Use 'cdecl' calling method
;                       $_DllCallBack_Sync (2)     - Enable Critical Section (see Remarks)
;                       $_DllCallBack_Subclass (4) - Enable Subclassing (see Remarks)
;                       $_DllCallBack_Struct (8)   - Pass the struct to the handler function (see Remarks)
;                       $_DllCallBack_Debug (1024) - Enable breakpoint (requires a JIT debugger)
; Requirement(s):
; Return Value(s):  Pointer to created stub or NULL on error
; @error Value(s):  1 = Error allocating memory
;                   2 = Error Loading User32.dll or Kernel32.dll
;                   3 = Failed to get the address of SendMessage, EnterCriticalSection, LeaveCriticalSection or CallWindowProc
;                   4 = Too many callbacks
;                   5 = GUIRegisterMsg() Failed
;                   6 = $sParameters Fromat wrong
;                   7 = Error calling InitializeCriticalSection
;
; Author(s):        Florian Fida
; Remarks:          The number of coexistent callback stubs is limited to 64.
;                   Windows message WM_USER + 0x7BFF is used by this function.
;
;                   If Subclassing is enabled the callback function must not call 'CallWindowProc' itself.
;                   If the Function processes the message it should return NULL if not is has to return a Pointer
;                   to the previous 'WindowProc' Function.
;
;                   Critical sections allow better synchronisation, if a multithreaded library calls
;                   the callback function, enable this option.
;
;                   Passing the struct requires the callback function to accept one parameter which is the
;                   Struct defined in $sParameters. This allows the modification of the stack.
;
;===============================================================================
;
Func _DllCallBack($sFunction, $sParameters = "", Const $nOptions = 0)
    Local $pSendMessage, $hGlobal, $hUser32, $vStub, $i, $vCriticalSection, $pCallWindowProc
    Local $nParameters, $vParameters, $wParam = -1, $nParameters_struct = -1, $hKernel32
    Local $sStub, $dwStubSize
    If BitAND($_DllCallBack_Debug, $nOptions) Then $sStub = "90909090CC" ; INT3
    If Not $gf_DllCallBack_fMsgRegistred Then Return SetError(5, 0, 0)
    If $sParameters = "" Or $sParameters = Default Then
        $nParameters = 0
    Else
        $vParameters = DllStructCreate($sParameters)
        If @error Then Return SetError(6, 0, 0)
        $nParameters = DllStructGetSize($vParameters) / 4
        If $nParameters <> Int($nParameters) Or @error Then Return SetError(6, 0, 0)
        For $i = 1 To 256
            DllStructGetData($vParameters, $i)
            If @error Then
                $nParameters_struct = $i - 1
                ExitLoop
            EndIf
        Next
        If $nParameters_struct < 0 Then SetError(6, 0, 0)
    EndIf
    For $i = 0 To $gi_DllCallBack_MaxStubs
        If Not $ga_DllCallBack_hGlobals[$i] Then
            $wParam = $i
            ExitLoop
        EndIf
    Next
    If $wParam = -1 Then Return SetError(4, 0, 0)
    If $gh_DllCallBack_hUser32 = 0 Then
        $hUser32 = DllCall("kernel32.dll", "ptr", "LoadLibrary", "str", "user32.dll")
        If @error Then Return SetError(2, 0, 0)
        If $hUser32[0] = 0 Then Return SetError(2, 0, 0)
        $gh_DllCallBack_hUser32 = $hUser32[0]
        $pSendMessage = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "SendMessage")
        If @error Then Return SetError(3, 0, 0)
        If $pSendMessage[0] = 0 Then
            If @Unicode Then
                $pSendMessage = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "SendMessageW")
                If @error Then Return SetError(3, 0, 0)
            Else
                $pSendMessage = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "SendMessageA")
                If @error Then Return SetError(3, 0, 0)
            EndIf
        EndIf
        If $pSendMessage[0] = 0 Then Return SetError(3, 0, 0)
        $gp_DllCallBack_SendMessage = $pSendMessage[0]
        $pCallWindowProc = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "CallWindowProc")
        If @error Then Return SetError(3, 0, 0)
        If $pCallWindowProc[0] = 0 Then
            If @Unicode Then
                $pCallWindowProc = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "CallWindowProcW")
                If @error Then Return SetError(3, 0, 0)
            Else
                $pCallWindowProc = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $gh_DllCallBack_hUser32, "str", "CallWindowProcA")
                If @error Then Return SetError(3, 0, 0)
            EndIf
        EndIf
        If $pCallWindowProc[0] = 0 Then Return SetError(3, 0, 0)
        $gp_DllCallBack_CallWindowProc = $pCallWindowProc[0]
    EndIf
    If Not BitAND($_DllCallBack_Sync, $nOptions) Then ; Critical section disabled
        $vCriticalSection = -1
    Else ; Critical section enabled
        If $gp_DllCallBack_EnterCriticalSection = 0 Or $gp_DllCallBack_LeaveCriticalSection = 0 Then
            ; we assume kernel32.dll is allways loaded
            $hKernel32 = DllCall("kernel32.dll", "ptr", "GetModuleHandle", "str", "kernel32.dll")
            If @error Then Return SetError(2, 0, 0)
            If $hKernel32[0] = 0 Then Return SetError(2, 0, 0)
            $gp_DllCallBack_EnterCriticalSection = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hKernel32[0], "str", "EnterCriticalSection")
            If @error Then Return SetError(3, 0, 0)
            $gp_DllCallBack_EnterCriticalSection = $gp_DllCallBack_EnterCriticalSection[0]
            If $gp_DllCallBack_EnterCriticalSection = 0 Then Return SetError(3, 0, 0)
            $gp_DllCallBack_LeaveCriticalSection = DllCall("kernel32.dll", "ptr", "GetProcAddress", "ptr", $hKernel32[0], "str", "LeaveCriticalSection")
            If @error Then Return SetError(3, 0, 0)
            $gp_DllCallBack_LeaveCriticalSection = $gp_DllCallBack_LeaveCriticalSection[0]
            If $gp_DllCallBack_LeaveCriticalSection = 0 Then Return SetError(3, 0, 0)
        EndIf
        $vCriticalSection = DllStructCreate($gs_DllCallBack_typedef_CriticalSection)
        DllCall("kernel32.dll", "none", "InitializeCriticalSection", "ptr", DllStructGetPtr($vCriticalSection))
        If @error Then Return SetError(7, 0, 0)
    EndIf

    If @error Then Return SetError(7, 0, 0)
    #cs
        Options: Critical section, Breakpoint, stdcall - 2 parameters
        
        $ ==>    > CC               INT3                                     ; Breakpoint (for debugging only)
        $+1      > 68 30859B00      PUSH 9B8530                              ; Push LPCRITICAL_SECTION
        $+6      > B8 0510917C      MOV EAX,ntdll.RtlEnterCriticalSection    ; Set address for EnterCriticalSection
        $+B      > FFD0             CALL EAX                                 ; Call EnterCriticalSection
        $+D      > 8D4424 04        LEA EAX,DWORD PTR SS:[ESP+4]             ; Load Pointer to parameters on stack to EAX
        $+11     > 50               PUSH EAX                                 ; Push lParam - Stack Pointer
        $+12     > 68 00000000      PUSH 0                                   ; Push wParam - internal reference to au3 function
        $+17     > 68 FF7F0000      PUSH 7FFF                                ; Push uiMsg - internal identifier for callback
        $+1C     > 68 26063000      PUSH 300626                              ; Push hWnd - Autoit's Callback window
        $+21     > B8 AEE2D177      MOV EAX,USER32.SendMessageA              ; Set address for SendMessage
        $+26     > FFD0             CALL EAX                                 ; Call Sendmessage
        $+28     > 50               PUSH EAX                                 ; Preserve Return value of Callback Function
        $+29     > 68 30859B00      PUSH 9B8530                              ; Push LPCRITICAL_SECTION
        $+2E     > B8 ED10917C      MOV EAX,ntdll.RtlLeaveCriticalSection    ; Set address for LeaveCriticalSection
        $+33     > FFD0             CALL EAX                                 ; Call LeaveCriticalSection
        $+35     > 58               POP EAX                                  ; Restore Return value of Callback Function
        $+36     > C2 0800          RETN 8                                   ; Adjust stack for stdcall and return
        
        
        Options: Default, stdcall - 2 parameters
        
        $ ==>    > 8D4424 04        LEA EAX,DWORD PTR SS:[ESP+4]             ; Load Pointer to parameters on stack to EAX
        $+4      > 50               PUSH EAX                                 ; Push lParam - Stack Pointer
        $+5      > 68 00000000      PUSH 0                                   ; Push wParam - internal reference to au3 function
        $+A      > 68 FF7F0000      PUSH 7FFF                                ; Push uiMsg - internal identifier for callback
        $+F      > 68 C6041700      PUSH 1704C6                              ; Push hWnd - Autoit's Callback window
        $+14     > B8 AEE2D177      MOV EAX,USER32.SendMessageA              ; Set address for SendMessage
        $+19     > FFD0             CALL EAX                                 ; Call Sendmessage
        $+1B     > C2 0800          RETN 8                                   ; Adjust stack for stdcall and return
        
        
        nOptions: Subclassing, stdcall - 4 parameters
        
        $ ==>    > 8D4424 04        LEA EAX,DWORD PTR SS:[ESP+4]             ; Load Pointer to parameters on stack to EAX
        $+4      > 50               PUSH EAX                                 ; Push lParam - Stack Pointer
        $+5      > 68 00000000      PUSH 0                                   ; Push wParam - internal reference to au3 function
        $+A      > 68 FF7F0000      PUSH 7FFF                                ; Push uiMsg - internal identifier for callback
        $+F      > 68 34063100      PUSH 310634                              ; Push hWnd - Autoit's Callback window
        $+14     > B8 62B7D177      MOV EAX,USER32.SendMessageW              ; Set address for SendMessage
        $+19     > FFD0             CALL EAX                                 ; Call Sendmessage
        $+1B     > 83F8 00          CMP EAX,0                                ; Compare EAX and NULL
        $+1E     > 74 1C            JE SHORT <$+3C>                          ; If equal (EAX == NULL) jump down to $+3C (return)
        $+20     > 8B5424 10        MOV EDX,DWORD PTR SS:[ESP+10]            ; Copy lParam from stack to EDX
        $+24     > 52               PUSH EDX                                 ; Push lParam
        $+25     > 8B5424 10        MOV EDX,DWORD PTR SS:[ESP+10]            ; Copy wParam from stack to EDX
        $+29     > 52               PUSH EDX                                 ; Push wParam
        $+2A     > 8B5424 10        MOV EDX,DWORD PTR SS:[ESP+10]            ; Copy uiMsg from stack to EDX
        $+2E     > 52               PUSH EDX                                 ; Push uiMsg
        $+2F     > 8B5424 10        MOV EDX,DWORD PTR SS:[ESP+10]            ; Copy hWnd from stack to EDX
        $+33     > 52               PUSH EDX                                 ; Push hWnd - Subclassed Window
        $+34     > 50               PUSH EAX                                 ; Push lpPrevWndFunc (Returned by SendMessage/Callback Func)
        $+35     > B8 19C0D177      MOV EAX,USER32.CallWindowProcW           ; Set address for CallWindowProc
        $+3A     > FFD0             CALL EAX                                 ; Call CallWindowProc
        $+3C     > C2 1000          RETN 10                                  ; Adjust stack and return
    #ce
    ; Note: EAX ECX EDX can be freely modified
    If BitAND($_DllCallBack_Sync, $nOptions) Then ; Critical section
        $sStub &= "68" & __DllCallBack_Endian(DllStructGetPtr($vCriticalSection))
        $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_EnterCriticalSection)
        $sStub &= "FFD0" ; call EnterCriticalSection
    EndIf
    $sStub &= "8D442404" ; load stack poiner into eax
    $sStub &= "50" ; push eax - lparam
    $sStub &= "68" & __DllCallBack_Endian($wParam, "uint")
    $sStub &= "68" & __DllCallBack_Endian($gi_DllCallBack_uiMsg, "uint")
    $sStub &= "68" & __DllCallBack_Endian($gh_DllCallBack_hWnd, "hwnd")
    $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_SendMessage)
    $sStub &= "FFD0" ; call SendMessage
    If BitAND($_DllCallBack_Sync, $nOptions) Then ; Critical section
        $sStub &= "50" ; push eax - to preserve return value of callback function
        $sStub &= "68" & __DllCallBack_Endian(DllStructGetPtr($vCriticalSection))
        $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_LeaveCriticalSection)
        $sStub &= "FFD0" ; call LeaveCriticalSection
        $sStub &= "58" ; pop eax - Retstore return value
    EndIf
    If BitAND($_DllCallBack_Subclass, $nOptions) Then ; Subclassing
        $sStub &= "83F800"; cmp eax,0
        $sStub &= "74" & "1C"; je 0x1c - if eax == 0 jump down 0x1c opcodes (to return)
        $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - lparam
        $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - wparam
        $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - msg
        $sStub &= "8B5424" & "10" & "52"; mov edx,dword ptr ss:esp+10; push edx - hwnd
        $sStub &= "50"; push eax - lpPrevWndFunc
        $sStub &= "B8" & __DllCallBack_Endian($gp_DllCallBack_CallWindowProc) ; Set eax to CallWindowProc
        $sStub &= "FFD0"; call eax
    EndIf
    If BitAND($_DllCallBack_Cdecl, $nOptions) Then
        $sStub &= "C3" ; return near 'cdecl'
    Else
        $sStub &= "C2" & __DllCallBack_Endian($nParameters * 4, "ushort", 2) ; Return near 'stdcall'
    EndIf
    $dwStubSize = StringLen($sStub) / 2
    $hGlobal = DllCall("kernel32.dll", "ptr", "GlobalAlloc", "uint", 0, "dword", $dwStubSize)
    If @error Then Return SetError(1, 0, 0)
    If $hGlobal[0] = 0 Then Return SetError(1, 0, 0)
    $hGlobal = $hGlobal[0]
    $vStub = DllStructCreate("ubyte[" & $dwStubSize & "]", $hGlobal)
    DllStructSetData($vStub, 1, Binary("0x" & $sStub))
    $gi_DllCallBack_StubCount += 1
    $ga_DllCallBack_hGlobals[$wParam] = $hGlobal
    $ga_DllCallBack_sFunctions[$wParam] = $sFunction
    $ga_DllCallBack_sParameters[$wParam] = $sParameters
    $ga_DllCallBack_nParameters[$wParam] = $nParameters_struct
    $ga_DllCallBack_vCriticalSections[$wParam] = $vCriticalSection
    $ga_DllCallBack_nOptions[$wParam] = $nOptions
    Return $hGlobal
EndFunc   ;==>_DllCallBack


;===============================================================================
;
; Function Name:    _DllCallBack_Free
; Description:      Frees memory from global heap allocated by _DllCallBackAlloc
; Parameter(s):     $hStub - Pointer to stub
; Requirement(s):
; Return Value(s):  On Success: True
;                   On Failure: False
; @error Value(s):  1 - Error freeing memory or Invalid handle
;                   2 - Error freeing User32.dll
; Author(s):        Florian Fida
;
;===============================================================================
;
Func _DllCallBack_Free(ByRef $hStub)
    Local $aTmp, $i, $fFound = False
    If $hStub > 0 Then
        $aTmp = DllCall("kernel32.dll", "ptr", "GlobalFree", "ptr", $hStub)
        If @error Then Return SetError(1, 0, False)
        If $aTmp[0] = $hStub Then Return SetError(1, 0, False)
        If $aTmp[0] = 0 Then
            For $i = 0 To $gi_DllCallBack_MaxStubs
                If $ga_DllCallBack_hGlobals[$i] = $hStub Then
                    If $ga_DllCallBack_vCriticalSections[$i] > 0 Then DllCall("kernel32.dll", "none", "DeleteCriticalSection", "ptr", DllStructGetPtr($ga_DllCallBack_vCriticalSections[$i]))
                    $ga_DllCallBack_hGlobals[$i] = 0
                    $ga_DllCallBack_sParameters[$i] = 0
                    $ga_DllCallBack_nParameters[$i] = 0
                    $ga_DllCallBack_sFunctions[$i] = 0
                    $ga_DllCallBack_vCriticalSections[$i] = 0
                    $fFound = True
                    ExitLoop
                EndIf
            Next
            If $fFound = False Then Return SetError(1, 0, False)
            $hStub = 0
            $gi_DllCallBack_StubCount -= 1
            If $gi_DllCallBack_StubCount < 1 Then
                $gi_DllCallBack_StubCount = 0
                $aTmp = DllCall("kernel32.dll", "int", "FreeLibrary", "ptr", $gh_DllCallBack_hUser32)
                If @error Then Return SetError(2, 0, False)
                If $aTmp[0] = 0 Then Return SetError(2, 0, False)
                $gh_DllCallBack_hUser32 = 0
            EndIf
            Return True
        EndIf
        Return False
    EndIf
    Return True
EndFunc   ;==>_DllCallBack_Free

; Internals
Func __DllCallBack_MsgHandler($hWnd_Callback, $uiMsg, $wParam, $lParam)
    Local $vParameters, $i
    If $ga_DllCallBack_nParameters[$wParam] > 0 Then
        $vParameters = DllStructCreate($ga_DllCallBack_sParameters[$wParam], $lParam)
        If BitAND($ga_DllCallBack_nOptions[$wParam], $_DllCallBack_Struct) Then
            Local $aCallArgs[2] = ["CallArgArray", $vParameters]
        Else
            Local $aCallArgs[$ga_DllCallBack_nParameters[$wParam] + 1]
            $aCallArgs[0] = "CallArgArray"
            For $i = 1 To $ga_DllCallBack_nParameters[$wParam]
                $aCallArgs[$i] = DllStructGetData($vParameters, $i)
            Next
        EndIf
        Return Call($ga_DllCallBack_sFunctions[$wParam], $aCallArgs)
    EndIf
    Return Call($ga_DllCallBack_sFunctions[$wParam])
EndFunc   ;==>__DllCallBack_MsgHandler
Func __DllCallBack_Endian($n, $s = "ptr", $bytes = 4) ; Return $bytes bytes from $n as Little Endian Hex String, threat as $s
    Local $a = DllStructCreate($s), $b = DllStructCreate("ubyte[" & $bytes & "]", DllStructGetPtr($a))
    DllStructSetData($a, 1, $n)
    Return StringTrimLeft(DllStructGetData($b, 1), 2)
EndFunc   ;==>__DllCallBack_Endian
Opt("MustDeclareVars", 0)

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

What does this do in the server _AddUser()

;Declear a $var to check if not the server is full.
    Local $Temp = 0

Is it me, or isn't this used locally?

P.S. You've inspired me to keep working on my own server-client programs. Thanks :) I am spying here and there on ur code :P


My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Share this post


Link to post
Share on other sites

What does this do in the server _AddUser()

;Declear a $var to check if not the server is full.
    Local $Temp = 0

Is it me, or isn't this used locally?

P.S. You've inspired me to keep working on my own server-client programs. Thanks :) I am spying here and there on ur code :P

it was to check if there was room for the user in the server and send a message back if it was full but i havent started working on that yet :blink:

[font="Impact"]Never fear, I is here.[/font]

Share this post


Link to post
Share on other sites

Thanks for posting richedit..

everything looks good.. but registering users doesnt seem to work..i looked at the code and

dont seem to be able to find the problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0