Jump to content
Sign in to follow this  
mLipok

GuiRichEdit.au3 - questions about: $tagCHARFORMAT and $tagCHARFORMAT2

Recommended Posts

mLipok

using GuiRichEdit.au3  I'm learning a little bit about DllCall and Structures.

By the way, I noticed some inconsistencies in the definition: 

$tagCHARFORMAT 

http://msdn.microsoft.com/en-us/library/windows/desktop/bb787881(v=vs.85).aspx

 

and 

$tagCHARFORMAT2

http://msdn.microsoft.com/en-us/library/windows/desktop/bb787883(v=vs.85).aspx

 

QUESTION 1: In this case, Is the mismatch between the

UDF: crCharColor
and

MSDN: crTextColor

may affect the operation of the script, which uses the structure.

QUESTION 2: In this case: how it can be done addiction, structure definitions $tagCHARFORMAT2 , depending on the controls version .

#if (_RICHEDIT_VER >= 0x0500)
  union {
    DWORD dwReserved;
    DWORD dwCookie;
  };
#else
  DWORD    dwReserved;
#endif
#if (_RICHEDIT_VER >= 0x0800)
  BYTE     bUnderlineColor;
#endif

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
LarsJ

Answer 1: If you by mismatch means that the names are different (crCharColor in AutoIt structure and crTextColor in C/C++ structure), then it doesn't matter, because the names are not part of the structure.

The names are only used to be able to reference the data fields in an easy way. In C/C++ you set and get the values of the data fields with dot notation (e.g. MyStruct.crTextColor). In AutoIt you use DllStructSetData and DllStructGetData.

When the code in the DLL is executed, the data fields of the structure are referenced directly by memory addresses.

If you by mismatch means that the crCharColor field in the AutoIt structure is defined as an int and the crTextColor field in the C/C++ structure is defined as a COLORREF = dword, then it doesn't matter either, because both data types allocates four bytes.

As long as you fill these four bytes with a proper RGB color value, the code in the DLL will work.

Answer 2: Note that the fields dwReserved/dwCookie in C/C++ and dwReserved in AutoIt in the first codebox, and bUnderlineColor in C/C++ and bReserved1 in AutoIt in the second codebox, are not used in the AutoIt UDF. If you want to use these fields, you have to implement the code yourself.

In C/C++ a union is a way to reference the same data field in the structure in different ways. The union in the codebox is allocating a single dword (not two dwords). In C/C++ you can refer to this data field in two ways: MyStruct.dwReserved and MyStruct.dwCookie. But it's the same data field.

(If you have written C/C++ code for the version before 0x0500, you can recompile the code for version 0x0500, without the need to replace all the dwReserved names with dwCookie. If you add new C/C++ code for version 0x0500, you can use the name dwCookie, which seems to be better than dwReserved.)

This means that the structure in the codebox is exactly the same before and after version 0x0500. In both cases a single dword is allocated.

In AutoIt you don't have to distinguish between versions before and after version 0x0500 for this field. In both cases you refer to the field with the name dwReserved. Note again, that dwReserved is not used in the AutoIt UDF.

If you have Rich Edit controls with _RICHEDIT_VER < 0x0800 (I don't know which Dll version 0x0800 matches), and the last field in the structure (bUnderlineColor in C/C++ and bReserved1 in AutoIt) is an issue, you can simply remove this field from the structure definition. Since bReserved1 is not used in the AutoIt UDF, the code will still work.

For Rich Edit controls where _RICHEDIT_VER >= 0x0800 you need bReserved1. Even if the field is not used. The size of the structure is stored in the first field: cbSize. If bReserved1 is missing, the value of this field will be one byte too small. This will cause an error.

Your structure definition for Rich Edit controls before and after 0x0800 should look like this:

Global $tagCHARFORMAT2 = $tagCHARFORMAT & ";word wWeight;short sSpacing;INT crBackColor;" & _
"dword lcid;dword dwReserved;short sStyle;word wKerning;byte bUnderlineType;byte bAnimation;byte bRevAuthor"
If $RICHEDIT_VER >= 0x0800 Then $tagCHARFORMAT2 &= ";byte bReserved1"
Since bReserved1 is not used in the AutoIt UDF, the code will work in both cases.
  • Like 1

Share this post


Link to post
Share on other sites
mLipok

Many thanks for such a wide lecture.
He was very informative.

btw.

If you have Rich Edit controls with _RICHEDIT_VER < 0x0800 (I don't know which Dll version 0x0800 matches)

 

here and here I find some usefull information:

 

This is defined as a Widows 8 feature (_RICHEDIT_VER >= 0x0800).

 

IFsU4.png


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

Share this post


Link to post
Share on other sites
LarsJ

So the last field in $tagCHARFORMAT2 structure (bUnderlineColor/bReserved1) is only working on Windows 8. But do you have any examples where the last field is causing issues on XP, Vista or Win 7?

I think that $tagCHARFORMAT and $tagCHARFORMAT2 structures as defined in GuiRichEdit.au3 are working on all Windows versions. May be a few of the data fields are not working on older Windows versions. And may be a few of the data fields are not implemented in the UDF. But the two structures seems to be properly defined.

Share this post


Link to post
Share on other sites
mLipok

I think that $tagCHARFORMAT and $tagCHARFORMAT2 structures as defined in GuiRichEdit.au3 are working on all Windows versions. May be a few of the data fields are not working on older Windows versions. And may be a few of the data fields are not implemented in the UDF. But the two structures seems to be properly defined.

 

I agree with you.

In the course of studying the MSDN documentation I was wondering what's new in the new Winodws systems.

I'll be on this issue a little work.

I do not have constant access to Windows 8, so I wonder if will be sufficient Win2012 Essential (I'll check it later)

For now, this week I will not have time to do it (today I took a few other tasks), but the EDIT case issue is on my list to check.

Even more so, in principle, this will be my first serious approach to the definition of structur in AutoIt.

Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2018-03-17

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  

×