SendMessage invalid parameters

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

SendMessage invalid parameters

12 Feb 2018, 09:56

Hi,

I try to implement new methods to the RichEdit Class by just me.
I've succeeded for some but don't succeed with EM_GETTABLEPARMS and EM_INSERTTABLE (used to get a table's parameters or Insert a new table)
Both messages returns -2147024809 which i believe is E_INVALIDARG.

If someone could try to explain why this returns an error that would be fantastic ! :P
(I've asked just me but I guess this is quite a standard issue so anyone could help)
I've put every documentation in the code below.


I've tried to do everything according to documentation and even a post of a guy on MSDN said was working.
I've tried some variations but couldn't make it work, always the same ErrorLevel

You can try the following code with the sample contained in the Class from just me
https://github.com/AHK-just-me/Class_Ri ... master.zip

Code: Select all

RN_GetorSetTableParams:
EM_GETTABLEPARMS := 0x400 + 265
EM_INSERTTABLE := 0x400 + 232
; EM_SETTABLEPARMS := 0x400 + 307
;*****************************
; EM_GETTABLEPARMS := 0x509
; Returns S_OK if successful
; https://msdn.microsoft.com/en-us/library/windows/desktop/Hh768371(v=vs.85).aspx
; A pointer to a TABLEROWPARMS structure.
; A pointer to a TABLECELLPARMS structure.
; Retrieves the table parameters for a table row and the cell parameters for the specified number of cells.
;*****************************
; "E_INVALIDARG" SAYS:
; The wParam or lParam is NULL or points to an invalid structure. The cbRow member of the TABLEROWPARMS structure must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure. The cbCell member of the TABLEROWPARMS structure must equal sizeof(TABLECELLPARMS). 
;*****************************
;*****************************
;CONVERSION SCHEME USED
;MSDN=AHK=BYTES
;*****************************
; LONG=INT=4
; WORD=UShort=2
; DWORD=Uint=4
; SHORT=Short=2
; COLORREF=UInt=4
; BYTE=UChar=1
;*****************************
VarSetCapacity(TABLEROWPARMS,4+3*4+6*4+4+2,0)
;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {
  ; BYTE  cbRow;
  ; BYTE  cbCell;
  ; BYTE  cCell;
  ; BYTE  cRow;
  ; LONG  dxCellMargin;
  ; LONG  dxIndent;
  ; LONG  dyHeight;
  ; DWORD nAlignment:3;
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
	;ARE WE SUPPOSED TO INIT MEMBERS TO THE MENTIONED VALUE ?
	; NumPut(3,TABLECELLPARMS,4+3*4,"Uint")
	; NumPut(1,TABLECELLPARMS,4+3*4+4,"Uint")
	; NumPut(1,TABLECELLPARMS,4+3*4+4*2,"Uint")
	; NumPut(1,TABLECELLPARMS,4+3*4+4*3,"Uint")
	; NumPut(1,TABLECELLPARMS,4+3*4+4*4,"Uint")
	; NumPut(1,TABLECELLPARMS,4+3*4+4*5,"Uint")
  ; LONG  cpStartRow;
  ; BYTE  bTableLevel;
  ; BYTE  iCell;
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {
  ; LONG     dxWidth;
  ; WORD     nVertAlign:2;
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
	;ARE WE SUPPOSED TO INIT MEMBERS TO THE MENTIONED VALUE ?
	 ; NumPut(2,TABLECELLPARMS,4,"UShort")
	 ; NumPut(1,TABLECELLPARMS,4+2,"UShort")
	 ; NumPut(1,TABLECELLPARMS,4+2*2,"UShort")
	 ; NumPut(1,TABLECELLPARMS,4+2*3,"UShort")
	 ; NumPut(1,TABLECELLPARMS,4+2*4,"UShort")
	 ; NumPut(1,TABLECELLPARMS,4+2*5,"UShort")
  ; WORD     wShading;
  ; SHORT    dxBrdrLeft;
  ; SHORT    dyBrdrTop;
  ; SHORT    dxBrdrRight;
  ; SHORT    dyBrdrBottom;
  ; COLORREF crBrdrLeft;
  ; COLORREF crBrdrTop;
  ; COLORREF crBrdrRight;
  ; COLORREF crBrdrBottom;
  ; COLORREF crBackPat;
  ; COLORREF crForePat;
; } TABLECELLPARMS;
; }

;*****************************
; Try EM_INSERTTABLE based on "David Kinder" comment in MSDN
; https://blogs.msdn.microsoft.com/murrays/2008/09/15/richedits-nested-table-facility/
;*****************************
;put -1 in cpStartRow to start at selection (added by me)
NumPut(-1,TABLEROWPARMS,4+3*4+6*4,"INT")
;----
;cCell 
NumPut(3,TABLEROWPARMS,2,"UChar")
;cRow
NumPut(2,TABLEROWPARMS,3,"UChar")
;dxCellMargin 
NumPut(50,TABLEROWPARMS,4,"Int")
;dyHeight 
NumPut(400,TABLEROWPARMS,4+4*2,"Int")
;nAlignment
NumPut(1,TABLEROWPARMS,4+4*3,"UInt")
;fIdentCells 
NumPut(1,TABLEROWPARMS,4+4*3+4*5,"UInt")
;dxWidth 
NumPut(1000,TABLECELLPARMS,0,"Int")
;dxBrdrLeft 
NumPut(1,TABLECELLPARMS,4+2*7,"Short")
;dyBrdrTop 
NumPut(1,TABLECELLPARMS,4+2*7+2*1,"Short")
;dxBrdrRight 
NumPut(1,TABLECELLPARMS,4+2*7+2*2,"Short")
;dyBrdrBottom 
NumPut(1,TABLECELLPARMS,4+2*7+2*3,"Short")
;crBackPat 
NumPut(0xffffff,TABLECELLPARMS,4+2*7+2*4+4*4,"UInt")
;crForePat 
NumPut(0x000000,TABLECELLPARMS,4+2*7+2*4+4*5,"UInt")
SendMessage, %EM_INSERTTABLE% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel

;*****************************
; Try EM_GETTABLEPARMS based on standard docs
;*****************************
;put -1 in cpStartRow to start at selection
NumPut(-1,TABLEROWPARMS,4+3*4+6*4,"INT")
; set cbRow 
;Should we check version of richedit (if 4.1), how?
NumPut((4+3*4+6*4+4+2)-2*4,TABLEROWPARMS,0,"UChar")
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(4+7*2+4*2+6*4,TABLEROWPARMS,1,"UChar")
; set bTableLevel? (see NOTE above) tried it but no changes
; NumPut(1,TABLEROWPARMS,4+3*4+6*4+4+1,"UChar")

SendMessage, %EM_GETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
; SHOWS 2147024809 WHICH I BELIEVE IS E_INVALIDARG
msgbox % "ccell " NumGet(TABLEROWPARMS,2,"UChar")
msgbox % "crow " NumGet(TABLEROWPARMS,3,"UChar")
return
Many thanks !
Last edited by DigiDon on 13 Feb 2018, 05:42, edited 2 times in total.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SendMessage invalid parameters

12 Feb 2018, 11:21

Code: Select all

	DWORD	nAlignment:3;	// Row alignment (like PARAFORMAT::bAlignment, \trql, trqr, \trqc)
	DWORD	fRTL:1; 		// Display cells in RTL order (\rtlrow)
	DWORD	fKeep:1;		// Keep row together (\trkeep}
	DWORD	fKeepFollow:1;	// Keep row on same page as following row (\trkeepfollow)
	DWORD	fWrap:1;		// Wrap text to right/left (depending on bAlignment)
nAlignment:3: The 3 represents the number of bits used in the DWORD to store the value. So

Code: Select all

nAlignment:3;	-> bits 0 - 2
fKeep:1;		-> bit 3
fKeepFollow:1;	-> bit 4
fWrap:1;		-> bit 5
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

12 Feb 2018, 13:07

OK thanks just me I didn't know.

Unfortunately I went again through the offsets and it still does not work... :(

Code: Select all

RN_GetorSetTableParams:
EM_GETTABLEPARMS := 0x400 + 265
EM_INSERTTABLE := 0x400 + 232
; EM_SETTABLEPARMS := 0x400 + 307
;*****************************
; EM_GETTABLEPARMS := 0x509
; Returns S_OK if successful
; https://msdn.microsoft.com/en-us/library/windows/desktop/Hh768371(v=vs.85).aspx
; A pointer to a TABLEROWPARMS structure.
; A pointer to a TABLECELLPARMS structure.
; Retrieves the table parameters for a table row and the cell parameters for the specified number of cells.
;*****************************
; "E_INVALIDARG" SAYS:
; The wParam or lParam is NULL or points to an invalid structure. The cbRow member of the TABLEROWPARMS structure must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure. The cbCell member of the TABLEROWPARMS structure must equal sizeof(TABLECELLPARMS). 
;*****************************
;*****************************
;CONVERSION SCHEME USED
;MSDN=AHK=BYTES
;*****************************
; LONG=INT=4
; WORD=UShort=2
; DWORD=Uint=4
; SHORT=Short=2
; COLORREF=UInt=4
; BYTE=UChar=1
;*****************************
; VarSetCapacity(TABLEROWPARMS,4+3*4+6*4+4+2,0)
VarSetCapacity(TABLEROWPARMS,4+3*4+3+5*1+4+2,0)

; set cbRow 
;Should we check version of richedit (if 4.1), how?
NumPut((4+3*4+3+5*1+4+1*2)-2*4,TABLEROWPARMS,0,"UChar")
;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {
  ; BYTE  cbRow;
  ; BYTE  cbCell;
  ; BYTE  cCell;
  ; BYTE  cRow;
  ; LONG  dxCellMargin;
  ; LONG  dxIndent;
  ; LONG  dyHeight;
  ; DWORD nAlignment:3;
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
  ; LONG  cpStartRow;
  ; BYTE  bTableLevel;
  ; BYTE  iCell;
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
; VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
VarSetCapacity(TABLECELLPARMS,4+2+1*5+2+4*2+6*4,0)
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(4+2+1*5+2+4*2+6*4,TABLEROWPARMS,1,"UChar")
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {
  ; LONG     dxWidth;
  ; WORD     nVertAlign:2;
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;
  ; SHORT    dxBrdrLeft;
  ; SHORT    dyBrdrTop;
  ; SHORT    dxBrdrRight;
  ; SHORT    dyBrdrBottom;
  ; COLORREF crBrdrLeft;
  ; COLORREF crBrdrTop;
  ; COLORREF crBrdrRight;
  ; COLORREF crBrdrBottom;
  ; COLORREF crBackPat;
  ; COLORREF crForePat;
; } TABLECELLPARMS;
; }

;*****************************
; Try EM_INSERTTABLE based on "David Kinder" comment in MSDN
; https://blogs.msdn.microsoft.com/murrays/2008/09/15/richedits-nested-table-facility/
;*****************************
;put -1 in cpStartRow to start at selection (added by me)
; NumPut(-1,TABLEROWPARMS,4+3*4+6*4,"INT")
NumPut(-1,TABLEROWPARMS,4+3*4+3+5*1,"INT")
;----
;TABLEROWPARMS
;cCell 
NumPut(3,TABLEROWPARMS,2,"UChar")
;cRow
NumPut(2,TABLEROWPARMS,3,"UChar")
;dxCellMargin 
NumPut(50,TABLEROWPARMS,4,"Int")
;dyHeight 
NumPut(400,TABLEROWPARMS,4+4*2,"Int")
;nAlignment
NumPut(1,TABLEROWPARMS,4+4*3,"UInt")
;fIdentCells 
NumPut(1,TABLEROWPARMS,4+4-3+3+4*1,"UInt")
;TABLECELLPARMS
;dxWidth
NumPut(1000,TABLECELLPARMS,0,"Int")
;dxBrdrLeft 
NumPut(1,TABLECELLPARMS,4+2+1*5+2,"Short")
;dyBrdrTop 
NumPut(1,TABLECELLPARMS,4+2+1*5+2+2*1,"Short")
;dxBrdrRight 
NumPut(1,TABLECELLPARMS,4+2+1*5+2+2*2,"Short")
;dyBrdrBottom 
NumPut(1,TABLECELLPARMS,4+2+1*5+2+2*3,"Short")
;crBackPat 
NumPut(0xffffff,TABLECELLPARMS,4+2+1*5+2+2*4+4*4,"UInt")
;crForePat 
NumPut(0x000000,TABLECELLPARMS,4+2+1*5+2+2*4+4*5,"UInt")

SendMessage, %EM_INSERTTABLE% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel

;*****************************
; Try EM_GETTABLEPARMS based on standard docs
;*****************************
;put -1 in cpStartRow to start at selection
NumPut(-1,TABLEROWPARMS,4+3*4+3+5*1,"INT")

; set bTableLevel? (see NOTE above) tried it but no changes
; NumPut(1,TABLEROWPARMS,4+3*4+3+5*1+4,"UChar")

SendMessage, %EM_GETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
; SHOWS 2147024809 WHICH I BELIEVE IS E_INVALIDARG
msgbox % "ccell " NumGet(TABLEROWPARMS,2,"UChar")
msgbox % "crow " NumGet(TABLEROWPARMS,3,"UChar")
return
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SendMessage invalid parameters

13 Feb 2018, 03:58

Hi DigiDon,

Code: Select all

  DWORD nAlignment:3;
  DWORD fRTL:1;
  DWORD fKeep:1;
  DWORD fKeepFollow:1;
  DWORD fWrap:1;
  DWORD fIdentCells:1;
All values are stored in the bits of one DWORD. If the sequence would require more than 32 bits, a second DWORD would be reserved.

nAlignment ist stored in bits 0 thru 2 and can be PFA_CENTER (1), PFA_LEFT (2), or PFA_RIGHT (3).

All other values are boolean. If you want to set them use something like

Code: Select all

fRTL := 8 ; 1 >> 3 (bit 3)
fKeep := 16 ; 1 >> 4 (bit 4)
fKeepFollow := 32 ; 1 >> 5  (bit 5)
fWrap := 64 ; 1 >> 6 (bit 6)
fIdentCells := 128 ; 1 >> 7 (bit 7)
Then calculate the whole value and store it in the corresponding DWORD (&TABLEROWPARMS + 16) at once.

Code: Select all

typedef struct _tableRowParms {     Size     Length
  BYTE  cbRow;                      1        1
  BYTE  cbCell;                     1        2
  BYTE  cCell;                      1        3
  BYTE  cRow;                       1        4
  LONG  dxCellMargin;               4        8
  LONG  dxIndent;                   4        12
  LONG  dyHeight;                   4        16
  DWORD nAlignment:3;               4        20
  DWORD fRTL:1;
  DWORD fKeep:1;
  DWORD fKeepFollow:1;
  DWORD fWrap:1;
  DWORD fIdentCells:1;
  LONG  cpStartRow;                 4        24    not defined for RichEdit 4.1
  BYTE  bTableLevel;                1        25    not defined for RichEdit 4.1
  BYTE  iCell;                      1        26    not defined for RichEdit 4.1
  4 bytes alignment                 2        28    not needed for RichEdit 4.1
} TABLEROWPARMS;
[b]EM_GETTABLEPARMS[/b] wrote:E_INVALIDARG

The wParam or lParam is NULL or points to an invalid structure. The cbRow member of the TABLEROWPARMS structure must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure. The cbCell member of the TABLEROWPARMS structure must equal sizeof(TABLECELLPARMS). The query character position must be at a table row delimiter.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

13 Feb 2018, 10:53

Thanks I think I'm gonna learn something great ;) because I'm not familiar at all with bytes/bits and structures.

Unfortunately it seems that I'm still not understanding something!
Even just the GETTABLEPARMS returns INVALIDARGS again
Where am I wrong again? :roll:

Many thanks!

Code: Select all

RN_GetTableParams:
EM_GETTABLEPARMS := 0x400 + 265
;*****************************
; EM_GETTABLEPARMS := 0x509
; Returns S_OK if successful
; https://msdn.microsoft.com/en-us/library/windows/desktop/Hh768371(v=vs.85).aspx
; A pointer to a TABLEROWPARMS structure.
; A pointer to a TABLECELLPARMS structure.
; Retrieves the table parameters for a table row and the cell parameters for the specified number of cells.
;*****************************
; "E_INVALIDARG" SAYS:
; The wParam or lParam is NULL or points to an invalid structure. The cbRow member of the TABLEROWPARMS structure must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure. The cbCell member of the TABLEROWPARMS structure must equal sizeof(TABLECELLPARMS). 
;*****************************
;CONVERSION SCHEME USED
;MSDN=AHK=BYTES
;*****************************
; LONG=INT=4
; WORD=UShort=2
; DWORD=Uint=4
; SHORT=Short=2
; COLORREF=UInt=4
; BYTE=UChar=1
;*****************************
; VarSetCapacity(TABLEROWPARMS,4+3*4+6*4+4+2,0)
VarSetCapacity(TABLEROWPARMS,28,0)
; set cbRow 
;Should we check version of richedit (if 4.1), how?
NumPut((28)-2*4,TABLEROWPARMS,0,"UChar")
;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {     Size     Length
  ; BYTE  cbRow;                      1        1
  ; BYTE  cbCell;                     1        2
  ; BYTE  cCell;                      1        3
  ; BYTE  cRow;                       1        4
  ; LONG  dxCellMargin;               4        8
  ; LONG  dxIndent;                   4        12
  ; LONG  dyHeight;                   4        16
  ; DWORD nAlignment:3;               4        20
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
  ; LONG  cpStartRow;                 4        24    not defined for RichEdit 4.1
  ; BYTE  bTableLevel;                1        25    not defined for RichEdit 4.1
  ; BYTE  iCell;                      1        26    not defined for RichEdit 4.1
  ; 4 bytes alignment                 2        28    not needed for RichEdit 4.1
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
; VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
VarSetCapacity(TABLECELLPARMS,44,0)
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(44,TABLEROWPARMS,1,"UChar")
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {     Size     Length
  ; LONG     dxWidth;                  4        4
  ; WORD     nVertAlign:2;             4        8
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;                 4        12
  ; SHORT    dxBrdrLeft;               2        14
  ; SHORT    dyBrdrTop;                2        16
  ; SHORT    dxBrdrRight;              2        18
  ; SHORT    dyBrdrBottom;             2        20
  ; COLORREF crBrdrLeft;               4        24
  ; COLORREF crBrdrTop;                4        28
  ; COLORREF crBrdrRight;              4        32
  ; COLORREF crBrdrBottom;             4        36
  ; COLORREF crBackPat;                4        40
  ; COLORREF crForePat;                4        44
; } TABLECELLPARMS;
; }
;*****************************
; Try EM_GETTABLEPARMS based on standard docs
;*****************************
;put -1 in cpStartRow to start at selection
NumPut(-1,TABLEROWPARMS,20,"INT")

; set bTableLevel? (see NOTE above) tried it but no changes
; NumPut(1,TABLEROWPARMS,4+3*4+3+5*1+4,"UChar")

SendMessage, %EM_GETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
; SHOWS 2147024809 WHICH I BELIEVE IS E_INVALIDARG
msgbox % "ccell " NumGet(TABLEROWPARMS,2,"UChar")
msgbox % "crow " NumGet(TABLEROWPARMS,3,"UChar")
return
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

13 Feb 2018, 10:56

For the values inside the same DWORD I think I understood most but I'm not sure how to integrate the nAlignement.
I tried this:

Code: Select all

;TRIED SEVERAL COMBINATIONS
; nAlignment:= 0x0003 ;(bit 1)
; nAlignment:= 1>>1 ;(bit 1)
nAlignment:= 1 ;(bit 1)
fIdentCells := 128 ; 1 >> 7 (bit 7)
;SHOULD IT BE LIKE THIS
TABLEROWPARMS_DWORD:=nAlignment+fIdentCells
; msgbox TABLEROWPARMS_DWORD %TABLEROWPARMS_DWORD%
NumPut(TABLEROWPARMS_DWORD,TABLECELLPARMS,16,"UShort")
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

13 Feb 2018, 11:03

And same problem with EM_INSERTTABLE, just to check

Code: Select all

RN_InsertTableMS:
EM_INSERTTABLE := 0x400 + 232
; EM_SETTABLEPARMS := 0x400 + 307
;*****************************
; EM_INSERTTABLE message
; Returns S_OK if the table is inserted, or an error code if not.
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768373(v=vs.85).aspx
; A pointer to a TABLEROWPARMS structure.
; A pointer to a TABLECELLPARMS structure.
; Inserts one or more identical table rows with empty cells.
;*****************************
;*****************************
;CONVERSION SCHEME USED
;MSDN=AHK=BYTES
;*****************************
; LONG=INT=4
; WORD=UShort=2
; DWORD=Uint=4
; SHORT=Short=2
; COLORREF=UInt=4
; BYTE=UChar=1
;*****************************
; VarSetCapacity(TABLEROWPARMS,4+3*4+6*4+4+2,0)
VarSetCapacity(TABLEROWPARMS,28,0)

; set cbRow 
;Should we check version of richedit (if 4.1), how?
NumPut((28)-2*4,TABLEROWPARMS,0,"UChar")
;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {     Size     Length
  ; BYTE  cbRow;                      1        1
  ; BYTE  cbCell;                     1        2
  ; BYTE  cCell;                      1        3
  ; BYTE  cRow;                       1        4
  ; LONG  dxCellMargin;               4        8
  ; LONG  dxIndent;                   4        12
  ; LONG  dyHeight;                   4        16
  ; DWORD nAlignment:3;               4        20
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
  ; LONG  cpStartRow;                 4        24    not defined for RichEdit 4.1
  ; BYTE  bTableLevel;                1        25    not defined for RichEdit 4.1
  ; BYTE  iCell;                      1        26    not defined for RichEdit 4.1
  ; 4 bytes alignment                 2        28    not needed for RichEdit 4.1
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
; VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
VarSetCapacity(TABLECELLPARMS,44,0)
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(44,TABLEROWPARMS,1,"UChar")
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {     Size     Length
  ; LONG     dxWidth;                  4        4
  ; WORD     nVertAlign:2;             4        8
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;                 4        12
  ; SHORT    dxBrdrLeft;               2        14
  ; SHORT    dyBrdrTop;                2        16
  ; SHORT    dxBrdrRight;              2        18
  ; SHORT    dyBrdrBottom;             2        20
  ; COLORREF crBrdrLeft;               4        24
  ; COLORREF crBrdrTop;                4        28
  ; COLORREF crBrdrRight;              4        32
  ; COLORREF crBrdrBottom;             4        36
  ; COLORREF crBackPat;                4        40
  ; COLORREF crForePat;                4        44
; } TABLECELLPARMS;
; }

;*****************************
; Try EM_INSERTTABLE based on "David Kinder" comment in MSDN
; https://blogs.msdn.microsoft.com/murrays/2008/09/15/richedits-nested-table-facility/
;*****************************
;put -1 in cpStartRow to start at selection (added by me)
NumPut(-1,TABLEROWPARMS,20,"INT")
;----
;TABLEROWPARMS
;cCell 
NumPut(3,TABLEROWPARMS,2,"UChar")
;cRow
NumPut(2,TABLEROWPARMS,3,"UChar")
;dxCellMargin 
NumPut(50,TABLEROWPARMS,4,"Int")
;dyHeight 
NumPut(400,TABLEROWPARMS,12,"Int")

;TRIED SEVERAL COMBINATIONS
; nAlignment:= 0x0003 ;(bit 1)
; nAlignment:= 1>>1 ;(bit 1)
nAlignment:= 1 ;(bit 1)
fIdentCells := 128 ; 1 >> 7 (bit 7)
;SHOULD IT BE LIKE THIS
TABLEROWPARMS_DWORD:=nAlignment+fIdentCells
; msgbox TABLEROWPARMS_DWORD %TABLEROWPARMS_DWORD%
NumPut(TABLEROWPARMS_DWORD,TABLECELLPARMS,16,"UShort")
;TABLECELLPARMS
;dxWidth
NumPut(1000,TABLECELLPARMS,0,"Int")
;dxBrdrLeft 
NumPut(1,TABLECELLPARMS,12,"Short")
;dyBrdrTop 
NumPut(1,TABLECELLPARMS,14,"Short")
;dxBrdrRight 
NumPut(1,TABLECELLPARMS,16,"Short")
;dyBrdrBottom 
NumPut(1,TABLECELLPARMS,18,"Short")
;crBackPat 
NumPut(0xffffff,TABLECELLPARMS,36,"UInt")
;crForePat 
NumPut(0x000000,TABLECELLPARMS,40,"UInt")

SendMessage, %EM_INSERTTABLE% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
return
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SendMessage invalid parameters

13 Feb 2018, 12:13

Code: Select all

nAlignment := 1 ; row alignment - 1 = PFA_CENTER, 2 = PFA_LEFT, 3 = PFA_RIGHT
fRTL := 0 ; display cells in right-to-left order - 0 = false, 8 = true
fKeep := 0 ; keep rows together - 0 = false, 16 = true
fKeepFollow := 0 ; keep the row on the same page as the following row - 0 = false, 32 = true
fWrap := 0 ; wrap text to the right or left, depending on bAlignment - 0 = false, 64 = true
fIdentCells := 128 ; lparam points at single struct valid for all cells - 0 = false, 128 = true
TABLEROWPARMS_DWORD := nAlignment + fRTL + fKeep + fKeepFollow + fWrap + fIdentCells
NumPut(TABLEROWPARMS_DWORD, TABLEROWPARMS, 16, "UInt") ; must be TABLEROWPARMS
But
[b]EM_GETTABLEPARMS[/b] wrote:The cbRow member of the TABLEROWPARMS structure must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure. The cbCell member of the TABLEROWPARMS structure must equal sizeof(TABLECELLPARMS).

This message gets the table parameters for the row at the character position specified by the cpStartRow member of the TABLEROWPARMS structure, and the number of cells specified by the cCells member of the TABLECELLPARMS structure.

The character position specified by the cpStartRow member of the TABLEROWPARMS structure should be at the start of the table row, or at the end delimiter of the table row. If cpStartRow is set to –1, the character position is given by the current selection. In this case, position the selection at the end of the row (between the cell mark and the end delimiter of the table row), or select the row.
If I understand this right, for EM_GETTABLEPARMS you might need to fill only the cbRow, cbCell, and cpStartRow members of TABLEROWPARMS. Additonally, you have to specify the number of cells in the cCells member of TABLEROWPARMS. If this value is greater than 1, the pointer passed in lParam must point to an appropriate array of TABLECELLPARMS structures.

Code: Select all

; typedef struct _tableCellParms {     Size     Length
  ; LONG     dxWidth;                  4        4
  ; WORD     nVertAlign:2;             2        6
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;                 2        8
  ; SHORT    dxBrdrLeft;               2        10
  ; SHORT    dyBrdrTop;                2        12
  ; SHORT    dxBrdrRight;              2        14
  ; SHORT    dyBrdrBottom;             2        16
  ; COLORREF crBrdrLeft;               4        20
  ; COLORREF crBrdrTop;                4        24
  ; COLORREF crBrdrRight;              4        28
  ; COLORREF crBrdrBottom;             4        32
  ; COLORREF crBackPat;                4        36
  ; COLORREF crForePat;                4        40
; } TABLECELLPARMS;
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

13 Feb 2018, 12:55

Thanks just me, sorry about the stupid mistakes I guess I got tired...

Good news I managed to make them work.

However it's not very clear why.
It seems I needed to use the capacity of RichEdit >4.1 even though I'm on Win7 so I have to investigate.

Also RN_GetTableParams seems to only work when you position after the end of the row, not inside a cell which is weird cause I don't know how to use it in real case scenario (user is in a cell).

EM_INSERTTABLE works but if I select text it says Invalid Args... Oo
Not what the documentation says (replace selection)

Annoying...

And apparently EM_SETTABLEPARMS is even worst. I saw this hread :
http://www.vbforums.com/showthread.php? ... ct-to-Type
Boy are the EM_GETTABLEPARMS and EM_SETTABLEPARMS messages poorly documented or what.

I've gotten a bit closer - I think I'm able to call EM_GETTABLEPARMS by moving the selection to the end of a table row, but EM_SETTABLEPARMS doesn't seem to work no matter what I try. It either returns E_INVALIDARGS (even though the arguments now seem correct), or it shrink every table cell down to 0 pixels wide.
Here is my code:

Code: Select all

RN_GetTableParams:
EM_GETTABLEPARMS := 0x400 + 265
;*****************************
; EM_GETTABLEPARMS := 0x509
; Returns S_OK if successful
; https://msdn.microsoft.com/en-us/library/windows/desktop/Hh768371(v=vs.85).aspx
; A pointer to a TABLEROWPARMS structure.
; A pointer to a TABLECELLPARMS structure.
; Retrieves the table parameters for a table row and the cell parameters for the specified number of cells.
;*****************************
; "E_INVALIDARG" SAYS:
; The wParam or lParam is NULL or points to an invalid structure. The cbRow member of the TABLEROWPARMS structure must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure. The cbCell member of the TABLEROWPARMS structure must equal sizeof(TABLECELLPARMS). 
;*****************************
;CONVERSION SCHEME USED
;MSDN=AHK=BYTES
;*****************************
; LONG=INT=4
; WORD=UShort=2
; DWORD=Uint=4
; SHORT=Short=2
; COLORREF=UInt=4
; BYTE=UChar=1
;*****************************
; VarSetCapacity(TABLEROWPARMS,4+3*4+6*4+4+2,0)
; VarSetCapacity(TABLEROWPARMS,20,0)
VarSetCapacity(TABLEROWPARMS,28,0)
; set cbRow 
;Should we check version of richedit (if 4.1), how? (-2*4)
; NumPut(20,TABLEROWPARMS,0,"UChar")
NumPut(28,TABLEROWPARMS,0,"UChar")
;put -1 in cpStartRow to start at selection
NumPut(-1,TABLEROWPARMS,20,"INT")
;put 1 in cCell to check only one cell
NumPut(1,TABLEROWPARMS,2,"UChar")
;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {     Size     Length
  ; BYTE  cbRow;                      1        1
  ; BYTE  cbCell;                     1        2
  ; BYTE  cCell;                      1        3
  ; BYTE  cRow;                       1        4
  ; LONG  dxCellMargin;               4        8
  ; LONG  dxIndent;                   4        12
  ; LONG  dyHeight;                   4        16
  ; DWORD nAlignment:3;               4        20
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
  ; LONG  cpStartRow;                 4        24    not defined for RichEdit 4.1
  ; BYTE  bTableLevel;                1        25    not defined for RichEdit 4.1
  ; BYTE  iCell;                      1        26    not defined for RichEdit 4.1
  ; 4 bytes alignment                 2        28    not needed for RichEdit 4.1
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
; VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
VarSetCapacity(TABLECELLPARMS,40,0)
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(40,TABLEROWPARMS,1,"UChar")
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {     Size     Length
  ; LONG     dxWidth;                  4        4
  ; WORD     nVertAlign:2;             2        6
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;                 2        8
  ; SHORT    dxBrdrLeft;               2        10
  ; SHORT    dyBrdrTop;                2        12
  ; SHORT    dxBrdrRight;              2        14
  ; SHORT    dyBrdrBottom;             2        16
  ; COLORREF crBrdrLeft;               4        20
  ; COLORREF crBrdrTop;                4        24
  ; COLORREF crBrdrRight;              4        28
  ; COLORREF crBrdrBottom;             4        32
  ; COLORREF crBackPat;                4        36
  ; COLORREF crForePat;                4        40
; } TABLECELLPARMS;
; }
;*****************************
; Try EM_GETTABLEPARMS based on standard docs
;*****************************

; set bTableLevel? (see NOTE above) tried it but no changes
; NumPut(1,TABLEROWPARMS,24,"UChar")

SendMessage, %EM_GETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
; SHOWS 2147024809 WHICH I BELIEVE IS E_INVALIDARG
msgbox % "ccell " NumGet(TABLEROWPARMS,2,"UChar")
msgbox % "crow " NumGet(TABLEROWPARMS,3,"UChar")
return

RN_InsertTableMS:
EM_INSERTTABLE := 0x400 + 232
; EM_SETTABLEPARMS := 0x400 + 307
;*****************************
; EM_INSERTTABLE message
; Returns S_OK if the table is inserted, or an error code if not.
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768373(v=vs.85).aspx
; A pointer to a TABLEROWPARMS structure.
; A pointer to a TABLECELLPARMS structure.
; Inserts one or more identical table rows with empty cells.
;*****************************
;*****************************
;CONVERSION SCHEME USED
;MSDN=AHK=BYTES
;*****************************
; LONG=INT=4
; WORD=UShort=2
; DWORD=Uint=4
; SHORT=Short=2
; COLORREF=UInt=4
; BYTE=UChar=1
;*****************************
; VarSetCapacity(TABLEROWPARMS,4+3*4+6*4+4+2,0)
; VarSetCapacity(TABLEROWPARMS,20,0)
VarSetCapacity(TABLEROWPARMS,28,0)

; set cbRow 
;Should we check version of richedit (if 4.1), how?
; NumPut((28)-2*4,TABLEROWPARMS,0,"UChar")
; NumPut(20,TABLEROWPARMS,0,"UChar")
NumPut(28,TABLEROWPARMS,0,"UChar")
;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {     Size     Length
  ; BYTE  cbRow;                      1        1
  ; BYTE  cbCell;                     1        2
  ; BYTE  cCell;                      1        3
  ; BYTE  cRow;                       1        4
  ; LONG  dxCellMargin;               4        8
  ; LONG  dxIndent;                   4        12
  ; LONG  dyHeight;                   4        16
  ; DWORD nAlignment:3;               4        20
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
  ; LONG  cpStartRow;                 4        24    not defined for RichEdit 4.1
  ; BYTE  bTableLevel;                1        25    not defined for RichEdit 4.1
  ; BYTE  iCell;                      1        26    not defined for RichEdit 4.1
  ; 4 bytes alignment                 2        28    not needed for RichEdit 4.1
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
; VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
VarSetCapacity(TABLECELLPARMS,40,0)
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(40,TABLEROWPARMS,1,"UChar")
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {     Size     Length
  ; LONG     dxWidth;                  4        4
  ; WORD     nVertAlign:2;             2        6
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;                 2        8
  ; SHORT    dxBrdrLeft;               2        10
  ; SHORT    dyBrdrTop;                2        12
  ; SHORT    dxBrdrRight;              2        14
  ; SHORT    dyBrdrBottom;             2        16
  ; COLORREF crBrdrLeft;               4        20
  ; COLORREF crBrdrTop;                4        24
  ; COLORREF crBrdrRight;              4        28
  ; COLORREF crBrdrBottom;             4        32
  ; COLORREF crBackPat;                4        36
  ; COLORREF crForePat;                4        40
; } TABLECELLPARMS;
; }

;*****************************
; Try EM_INSERTTABLE based on "David Kinder" comment in MSDN
; https://blogs.msdn.microsoft.com/murrays/2008/09/15/richedits-nested-table-facility/
;*****************************
;put -1 in cpStartRow to start at selection (added by me)
NumPut(-1,TABLEROWPARMS,20,"INT")
;----
;TABLEROWPARMS
;cCell 
NumPut(3,TABLEROWPARMS,2,"UChar")
;cRow
NumPut(2,TABLEROWPARMS,3,"UChar")
;dxCellMargin 
NumPut(50,TABLEROWPARMS,4,"Int")
;dyHeight 
NumPut(400,TABLEROWPARMS,12,"Int")
;Put the DWORD
nAlignment:= 1 ;(bit 1)
fIdentCells := 128 ; 1 >> 7 (bit 7)
TABLEROWPARMS_DWORD:=nAlignment+fIdentCells
NumPut(TABLEROWPARMS_DWORD,TABLEROWPARMS,16,"UShort")
;----
;TABLECELLPARMS
;dxWidth
NumPut(1000,TABLECELLPARMS,0,"Int")
;dxBrdrLeft 
NumPut(1,TABLECELLPARMS,8,"Short")
;dyBrdrTop 
NumPut(1,TABLECELLPARMS,10,"Short")
;dxBrdrRight 
NumPut(1,TABLECELLPARMS,12,"Short")
;dyBrdrBottom 
NumPut(1,TABLECELLPARMS,14,"Short")
;crBackPat 
NumPut(0xffffff,TABLECELLPARMS,32,"UInt")
;crForePat 
NumPut(0x000000,TABLECELLPARMS,36,"UInt")

SendMessage, %EM_INSERTTABLE% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
return
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SendMessage invalid parameters

14 Feb 2018, 04:35

You can run the following to get the RichEdit version. It returns 10.0 on Win 10. I think that RichEdit 4.1 would be 5.41:

Code: Select all

MsgBox, 0, RE Version, % RE_GetVersion()

RE_GetVersion() {
   VarSetCapacity(DLLVERSIONINFO, 20, 0)
   NumPut(20, DLLVERSIONINFO, "UInt")
   If !DllCall("msftedit.dll\DllGetVersion", "Ptr", &DLLVERSIONINFO, "UInt") ; S_OK
      Return NumGet(DLLVERSIONINFO, 4, "UInt") . "." . NumGet(DLLVERSIONINFO, 8, "Int")
   Return 0
}
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

14 Feb 2018, 07:30

It says 41.21 which I assume means 4.121?
EDIT: I have seen this on a website
msftedit.dll 5.41.21.2510 Rich Text Edit Control, v4.1
So I huess this is where the 41.21 comes from.
Strange then that the structure size has to be different from documented
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

14 Feb 2018, 14:48

What a deception ! :(

I've finally tried EM_SETTABLEPARMS, as the original goal was to see if I could simply add a column (so in MS jargon a cell for each row).
How foul I was !

I thought we were close because even if a bit weird the EM_INSERTTABLE and EM_GETTABLEPARMS were both working.
And the EM_SETTABLEPARMS is using the same structures!

But no it seems I conclude the same as the topic I quoted, this EM_SETTABLEPARMS seems incomprehensive!
It RETURNS ALWAYS 0 (so all good ! :o ) even if we didn't define anything in the structure. Which is at the opposite of documentation and the other two messages (where a single byte less/more and INVALIDARGS!) :crazy:

Here was my try, Im' very disappointed by this lack of documentation: there are no implementation in any language I could find on Google :shock: ...

Code: Select all

RN_SetTableParams:
EM_SETTABLEPARMS := 0x400 + 307
; EM_SETTABLEPARMS := 0x533
; This message changes the parameters of the number of rows specified by the cRow member of the TABLEROWPARMS structure, if the table has that many consecutive rows. If cRow is less than 0, the message iterates until the end of the table. If the new cell count differs from the current cell count by +1 or –1, it inserts or deletes the cell at the index specified by the iCell member of TABLEROWPARMS. The starting table row is identified by a character position. This position is specified by cpStartRow members with values that are greater than or equal to zero. The position should be inside the table row, but not inside a nested table, unless you want to change that table’s parameters. If the cpStartRow member is –1, the character position is given by the current selection. For this, position the selection anywhere inside the table row, or select the row with the active end of the selection at the end of the table row.
; TABLEROWPARMS
; The insertion point must be at the start of a table or inside a table row, and the number of cells can only change by one.
; cRow=-1 (<0 to loop through all)
; cCell : should be +1 or -1
; cpStartRow : The starting table row identified by a character position ; -1 for current pos ; Pos anywhere inside the row
; iCell is the index to insert/delete the cell
VarSetCapacity(TABLEROWPARMS,28,0)
;WILL ALREADY SAY ALL GOOD .... 
; SendMessage, %EM_SETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
; msgbox % "ErrorLevel " ErrorLevel

; set cbRow 
;Should we check version of richedit (if 4.1), how? (-2*4)
; NumPut(20,TABLEROWPARMS,0,"UChar")
NumPut(28,TABLEROWPARMS,0,"UChar")
;put -1 in cpStartRow to start at selection
NumPut(-1,TABLEROWPARMS,20,"INT")
;put 3+1 in cCell to add a cell
NumPut(4,TABLEROWPARMS,2,"UChar")
; cRow=-1 (<0 to loop through all)
; Tried also 2 for example as well but nothing happened
; NumPut(-1,TABLEROWPARMS,3,"UChar")
NumPut(2,TABLEROWPARMS,3,"UChar")
; try iCell=1 to insert at cell 1/ tried 2, 3
NumPut(1,TABLEROWPARMS,25,"UChar")

;*****************************
; TABLEROWPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768761(v=vs.85).aspx
; typedef struct _tableRowParms {     Size     Length
  ; BYTE  cbRow;                      1        1
  ; BYTE  cbCell;                     1        2
  ; BYTE  cCell;                      1        3
  ; BYTE  cRow;                       1        4
  ; LONG  dxCellMargin;               4        8
  ; LONG  dxIndent;                   4        12
  ; LONG  dyHeight;                   4        16
  ; DWORD nAlignment:3;               4        20
  ; DWORD fRTL:1;
  ; DWORD fKeep:1;
  ; DWORD fKeepFollow:1;
  ; DWORD fWrap:1;
  ; DWORD fIdentCells:1;
  ; LONG  cpStartRow;                 4        24    not defined for RichEdit 4.1
  ; BYTE  bTableLevel;                1        25    not defined for RichEdit 4.1
  ; BYTE  iCell;                      1        26    not defined for RichEdit 4.1
  ; 4 bytes alignment                 2        28    not needed for RichEdit 4.1
; } TABLEROWPARMS;
;NOTE:
; bTableLevel
; The table nesting level (EM_GETTABLEPARMS only).
; *****************************
; VarSetCapacity(TABLECELLPARMS,4+7*2+4*2+6*4,0)
VarSetCapacity(TABLECELLPARMS,40,0)
; SendMessage, %EM_SETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
; msgbox % "ErrorLevel " ErrorLevel
;Should we check version of richedit (if >4.1), how?
; NumPut((4+3*4+6*4+4+2),TABLEROWPARMS,0,"UChar")
; set cbCell 
NumPut(40,TABLEROWPARMS,1,"UChar")
SendMessage, %EM_SETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
;*****************************
; TABLECELLPARMS structure
; https://msdn.microsoft.com/en-us/library/windows/desktop/hh768760(v=vs.85).aspx
; typedef struct _tableCellParms {     Size     Length
  ; LONG     dxWidth;                  4        4
  ; WORD     nVertAlign:2;             2        6
  ; WORD     fMergeTop:1;
  ; WORD     fMergePrev:1;
  ; WORD     fVertical:1;
  ; WORD     fMergeStart:1;
  ; WORD     fMergeCont:1;
  ; WORD     wShading;                 2        8
  ; SHORT    dxBrdrLeft;               2        10
  ; SHORT    dyBrdrTop;                2        12
  ; SHORT    dxBrdrRight;              2        14
  ; SHORT    dyBrdrBottom;             2        16
  ; COLORREF crBrdrLeft;               4        20
  ; COLORREF crBrdrTop;                4        24
  ; COLORREF crBrdrRight;              4        28
  ; COLORREF crBrdrBottom;             4        32
  ; COLORREF crBackPat;                4        36
  ; COLORREF crForePat;                4        40
; } TABLECELLPARMS;
; }
;*****************************
; Tried to define the same value as EM_INSERTTABLEPARMS in case it was needed
;*****************************
;dxCellMargin 
NumPut(50,TABLEROWPARMS,4,"Int")
;dyHeight 
NumPut(400,TABLEROWPARMS,12,"Int")
;Put the DWORD
nAlignment:= 1 ;(bit 1)
fIdentCells := 128 ; 1 >> 7 (bit 7)
TABLEROWPARMS_DWORD:=nAlignment+fIdentCells
NumPut(TABLEROWPARMS_DWORD,TABLEROWPARMS,16,"UShort")
;----
;TABLECELLPARMS
;dxWidth
NumPut(1000,TABLECELLPARMS,0,"Int")
;dxBrdrLeft 
NumPut(1,TABLECELLPARMS,8,"Short")
;dyBrdrTop 
NumPut(1,TABLECELLPARMS,10,"Short")
;dxBrdrRight 
NumPut(1,TABLECELLPARMS,12,"Short")
;dyBrdrBottom 
NumPut(1,TABLECELLPARMS,14,"Short")
;crBackPat 
NumPut(0xffffff,TABLECELLPARMS,32,"UInt")
;crForePat 
NumPut(0x000000,TABLECELLPARMS,36,"UInt")
; set bTableLevel? (see NOTE above) tried it but no changes
NumPut(1,TABLEROWPARMS,24,"UChar")
SendMessage, %EM_SETTABLEPARMS% , &TABLEROWPARMS, &TABLECELLPARMS,, % "ahk_id " RE2.HWND
msgbox % "ErrorLevel " ErrorLevel
return
But thanks just me for your time, I've learned! ;)
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

14 Feb 2018, 14:53

One of my thought is that it might not be implemented in 4.1 but ... it would be very weird...
Can you confirm the results on win10?
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SendMessage invalid parameters

15 Feb 2018, 04:36

EM_SETTABLEPARMS wrote:E_INVALIDARG
The cbRow member must equal sizeof(TABLEROWPARMS) or sizeof(TABLEROWPARMS) – 2*sizeof(long). The latter value is the size of the RichEdit 4.1 TABLEROWPARMS structure.

Remarks

This message changes the parameters of the number of rows specified by the cRow member of the TABLEROWPARMS structure, if the table has that many consecutive rows. If cRow is less than 0, the message iterates until the end of the table. If the new cell count differs from the current cell count by +1 or –1, it inserts or deletes the cell at the index specified by the iCell member of TABLEROWPARMS.
In conjunction with the definition posted on RichEdit’s Nested Table Facility that might mean that cpStartRow, bTableLevel, and iCell are not defined for / considered by RichEdit 4.1.
just me
Posts: 9453
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: SendMessage invalid parameters

20 Feb 2018, 10:47

Hi DigiDon,

I made some tests on Win 10 and searched the internet for documentation and code examples. From what I read I got the following impressions:
  • The first 'official' upgrade since RichEdit 4.1 (Win XP) has been shipped with Win 8. In the meantime some versions of MS Office had 'special versions' of a RichEdit, but I couldn't find out whether they replaced the 'official' Msftedit.dll file in System32.
  • With Win 8 Microsoft added the documentation for the EM_GETTABLEPARMS and EM_INSERTTABLE message, which had been implemented for RichEdit 4.1 already. But seemingly they added a new message EM_SETTABLEPARMS.
From my tests:
  • EM_INSERTTABLE is working on Win 10. But it doesn't replace a selection, too. Error: E_FAIL (0x80004005).
  • EM_GETTABLEPARMS is working on Win 10. If the character position specified by cpStartRow is wrong, the function returns E_FAIL (0x80004005). Inspired by this code written by teadrinker I tried to use the TOM interfaces to work around the position restrictions. Finally I got the following function which allows the insertion point to be everywhere within a table row on Win 10:

    Code: Select all

    ; ================================================================================================================================
    ; Retrieves the table and the cell parameters for a table row.
    ; Parameters:
    ;     hRE            -  handle to a RichEdit control
    ;     TABLEROWPARMS  -  variable to store the table row parameters
    ;     TABLECELLPARMS -  variable to store the cell paramaters
    ; Return Values:
    ;     On success:    The number of cells found in the row.
    ;     On failure:    False, ErrorLevel contains the error code.
    ; MSDN:
    ;     EM_GETTABLEPARMS = 0x0509 (0x0400 + 265) -> msdn.microsoft.com/en-us/library/windows/desktop/hh768371(v=vs.85).aspx
    ;     Text Object Model (TOM) -> msdn.microsoft.com/en-us/library/windows/desktop/bb787607(v=vs.85).aspx
    ; Remarks:
    ;     The function uses the start of the current selection to determine the table row.
    ; Credits:
    ;     Thanks to teadrinker for providing some TOM basics -> autohotkey.com/boards/viewtopic.php?p=176774#p176774
    ; ================================================================================================================================
    GetTableParms(hRE, ByRef TABLEROWPARMS, ByRef TABLECELLPARMS) {
       Static IID_ITextDocument := "{8CC497C0-A1DF-11CE-8098-00AA0047BE5D}"
            , MAX_TABLE_CELLS := 63  ; maximum number of cells in a table row
            , SizeOfTCP := 40        ; size of TABLECELLPARMS
            , SizeOfTRP := 28        ; size of TABLEROWPARMS (20 for RichEdit 4.1 ???)
       DllCall("SendMessage", "Ptr", hRE, "UInt", 0x043C, "Ptr", 0, "PtrP", IRichEditOle) ; EM_GETOLEINTERFACE
       Doc := ComObject(9, ComObjQuery(IRichEditOle, IID_ITextDocument), 1) ; ITextDocument
       ObjRelease(IRichEditOle)
       Sel := Doc.Selection ; ITextSelection
       Rng := Doc.Range(Sel.Start, Sel.Start) ; ITextRange
       Rng.Expand(10) ; tomRow = 10 (table row)
       cpStartRow := Rng.Start ; Rng.End does not work in every case
       VarSetCapacity(TABLEROWPARMS, SizeOfTRP, 0)
       VarSetCapacity(TABLECELLPARMS, SizeOfTCP, 0)
       VarSetCapacity(LOCALCELLPARMS, SizeOfTCP * MAX_TABLE_CELLS, 0)
       NumPut(SizeOfTRP, TABLEROWPARMS, 0, "UChar")
       NumPut(SizeOfTCP, TABLEROWPARMS, 1, "UChar")
       NumPut(MAX_TABLE_CELLS, TABLEROWPARMS, 2, "UChar")
       NumPut(cpStartRow, TABLEROWPARMS, 20, "INT")
       If (HR := DllCall("SendMessage", "Ptr", hRE, "UInt", 0x0509, "Ptr", &TABLEROWPARMS, "Ptr", &LOCALCELLPARMS, "UInt")) {
          MsgBox, 16, %A_ThisFunc%, % Format("Error = {:08X}", HR)
          VarSetCapacity(LOCALCELLPARMS, 0)
          Return !(ErrorLevel := HR)
       }
       cCell := NumGet(TABLEROWPARMS, 2, "UChar") ; number of cells in the current row
       Length := SizeOfTCP * cCell                ; length of the TABLECELLPARMS array
       VarSetCapacity(TABLECELLPARMS, Length, 0)
       DllCall("RtlMoveMemory", "Ptr", &TABLECELLPARMS, "Ptr", &LOCALCELLPARMS, "Ptr", Length)
       VarSetCapacity(LOCALCELLPARMS, 0)
       Return cCell
    }
    If you want to rewrite the RichEdit code, you should consider to use the TOM interfaces.
  • EM_SETTABLEPARMS is working on Win 10. But it's rather complicated to set-up the parameters. If you don't specify the fIdentCells flag, which will cause the cell parameters specified in the first TABLECELLPARMS structure to be used for all cells, you have to specify one appropriate TABLECELLPARMS structure for each existing cell.
DigiDon
Posts: 178
Joined: 19 May 2014, 04:55
Contact:

Re: SendMessage invalid parameters

20 Feb 2018, 13:55

Alright thanks for the tests just me !

But as you said if it's not working on previous versions of windows I guess I'll abandon the idea.

The goal here was to be able to add/delete columns in a table.
I really can't understand why they did not provide a way to do it...

I guess there could be complicated workarounds to detect and modify the rtf code directly but I really think this will be too complex.
EverFastAccess : Take Notes on anything the Fast way: Attach notes, Set reminders & Speed up research in 1 gesture - AHK topic
AHK Dynamic Obfuscator L - Protect your AHK code by Obfuscation - AHK topic
QuickModules for Outlook : Sort Outlook emails very quickly to multiple folders - AHK topic
Coding takes lots of time and efforts. If I have helped you or if you enjoy one of my free projects, please consider a small donation :thumbup:
Sorry I am working hard at the moment at a new job and can't commit on delays of answers & updates

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 316 guests