• Welcome to PlanetSquires Forums.
 

CWindow RC 13

Started by José Roca, July 15, 2016, 01:07:45 AM

Previous topic - Next topic

José Roca

We are very close to the first official version.

Some changes that may affect to your code:

All the classes share the same namespace name, "Afx", so remove the Afx.CwindowClass, etc., that we have been using, an use only

USING Afx

The CBSTR.inc file has been renamed as CWSTR.inc.

All the procedures that did return a CBSTR have been modified to return the faster CWSTR.

CBSTR strings and CWSTR strings work very well together: you can assign a CBSTR to a CWSTR, and viceversa, as well as concatenate them with the + or & operators, append with the += or &= operators, also combining them with FB strings, wstrings and literals. Most FB operators and string functions, like MID, TRIM, etc., work with them. Notable exceptions are LEFT, RIGHT and VAL, that don't generate intermediate temporary strings and don't call the operators of the classes. They can still be used if you use double indirection (**).

You can use VARPTR or @ to pass the CWSTR or CBSTR variable to a function that expects to be passed by reference, but use the right one: CWSTR for out WSTRING parameters and CBSTR for out BSTR parameters. The equivalent to STRPTR is *cbs and *cws, although you can also use STRPTR(**cbs) and STRPTR(**cbs), but it is more compilcated. A double * dereferences the string data, e.g. **cbs, **cws.

A very useful feature is that both data types are dynamic. Therefore you don't have to specify its size in advance, unlike ZSTRING and WSTRING. No more problems to write functions that return an unicode string.

I also have adapted the templates for the winFBE editor.

Hope it all goes well despite the number 13 :)

Johan Klassen


José Roca

For those that haven't followed previous discussions, be aware that you must use RETURN instead of FUNCTION = to return a CWSTR or a CBSTR type as the result of a function. FUNCTION = calls the destructor of the returned type before calling the constructor of the temporary copy to be returned, making it impossible to make a copy. While returning a CBSTR succeeds in most cases because, by default, Windows caches BSTR strings, if done with CWSTR it will crash.

This is a serious bug that invalidates FUNCTION = to return user defined types that have a constructor.

José Roca

#3
AfxTime. inc.

An include file with many functions to deal with dates.

James Fuller

Jose,

  This fails:

'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
'afxtime tests
'=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
#include once "Afx/AfxTime.inc"
Dim As Word w1 = AfxLocalDay()
? w1
sleep


with

fbc  -s console "C:\FbRadAsm\Fb64\Examples\jcf\afxtime01.bas"
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(121) error 58: Illegal specification, at parameter 4 (ppTInfo) in 'GetTypeInfo as function(byval This as IXMLDOMImplementation ptr, byval iTInfo as UINT, byval lcid as LCID, byval ppTInfo as ITypeInfo ptr ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(122) error 58: Illegal specification, at parameter 6 (rgDispId) in 'GetIDsOfNames as function(byval This as IXMLDOMImplementation ptr, byval riid as const IID const ptr, byval rgszNames as LPOLESTR ptr, byval cNames as UINT, byval lcid as LCID, byval rgDispId as DISPID ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(123) error 58: Illegal specification, at parameter 2 (dispIdMember) in 'Invoke as function(byval This as IXMLDOMImplementation ptr, byval dispIdMember as DISPID, byval riid as const IID const ptr, byval lcid as LCID, byval wFlags as WORD, byval pDispParams as DISPPARAMS ptr, byval pVarResult as VARIANT ptr, byval pExcepInfo as EXCEPINFO ptr, byval puArgErr as UINT ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(154) error 58: Illegal specification, at parameter 4 (ppTInfo) in 'GetTypeInfo as function(byval This as IXMLDOMNode ptr, byval iTInfo as UINT, byval lcid as LCID, byval ppTInfo as ITypeInfo ptr ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(155) error 58: Illegal specification, at parameter 6 (rgDispId) in 'GetIDsOfNames as function(byval This as IXMLDOMNode ptr, byval riid as const IID const ptr, byval rgszNames as LPOLESTR ptr, byval cNames as UINT, byval lcid as LCID, byval rgDispId as DISPID ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(156) error 58: Illegal specification, at parameter 2 (dispIdMember) in 'Invoke as function(byval This as IXMLDOMNode ptr, byval dispIdMember as DISPID, byval riid as const IID const ptr, byval lcid as LCID, byval wFlags as WORD, byval pDispParams as DISPPARAMS ptr, byval pVarResult as VARIANT ptr, byval pExcepInfo as EXCEPINFO ptr, byval puArgErr as UINT ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(159) error 70: Incomplete type, before ')' in 'put_nodeValue as function(byval This as IXMLDOMNode ptr, byval value as VARIANT) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(168) error 70: Incomplete type, before ',' in 'insertBefore as function(byval This as IXMLDOMNode ptr, byval newChild as IXMLDOMNode ptr, byval refChild as VARIANT, byval outNewChild as IXMLDOMNode ptr ptr) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(181) error 70: Incomplete type, before ')' in 'put_nodeTypedValue as function(byval This as IXMLDOMNode ptr, byval typedValue as VARIANT) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(192) error 70: Incomplete type, before ')' in 'transformNodeToObject as function(byval This as IXMLDOMNode ptr, byval stylesheet as IXMLDOMNode ptr, byval outputObject as VARIANT) as HRESULT'
C:\FreeBASIC-1.05.0-win64\inc\win\msxml.bi(192) error 132: Too many errors, exiting



José Roca

Sorry, it was missing "using Afx". I have reuploaded the file.

James Fuller

Jose,
  A number of warnings now with the new upload.
James


fbc  -s console "C:\FbRadAsm\Fb64\Examples\jcf\afxtime01.bas"
C:\FreeBASIC-1.05.0-win64\inc\Afx\AfxTime.inc(723) warning 3(1): Passing different pointer types, at parameter 4 of VARBSTRFROMDATE()
C:\FreeBASIC-1.05.0-win64\inc\Afx\AfxTime.inc(733) warning 3(1): Passing different pointer types, at parameter 4 of VARBSTRFROMDATE()
C:\FreeBASIC-1.05.0-win64\inc\Afx\AfxTime.inc(743) warning 3(1): Passing different pointer types, at parameter 4 of VARBSTRFROMDATE()
C:\FbRadAsm\Fb64\Examples\jcf\afxtime01.c: In function 'AFXWEEKONE':
C:\FbRadAsm\Fb64\Examples\jcf\afxtime01.c:1193:32: warning: 'NFIRSTDAY$1' is used uninitialized in this function [-Wuninitialized]
  NFIRSTDAY$1 = (int32)(int64)-((int64)NFIRSTDAY$1 == ((int64)vr$2 + -1ll));
                                ^

Make done.

José Roca

I'm not getting these errors. You must be using different compiler switches.
New file uploaded.

James Fuller

Quote from: Jose Roca on July 16, 2016, 10:24:22 AM
I'm not getting these errors. You must be using different compiler switches.
New file uploaded.

fbc  -s console "C:\FbRadAsm\Fb64\Examples\jcf\afxtime01.bas"

New file seems to be fine on a quick retest.

James

James Fuller

Jose,
  How do you center the IFileOpenDialog if the hwndOwner is the Desktop?

James

José Roca

You can try to find the handle of the dialog and use MoveWindow or SetWindowPos.

José Roca

#11
AfxPrinter.inc

Some useful printer procedures.

José Roca

AfxNls.inc - National language support functions

José Roca

Renamed the old AfxEnumPrinterPorts as AfxEnumLocalPrinterPorts and added a new AfxEnumPrinterPorts function that can also enumerate ports available for printing in the specified server.

New file reuploaded in the original post.

Paul Squires

Problems with AfxStrPathName. Jose, there were a couple of problems with the routine so I fixed them and include the modified source below:

1)  PATH did not return the trailing "\".
2)  NAME would return a blank string if the incoming file string did not have a path. In PB, a filename without a path will return the filename.
3)  NAMEX. Same problem as NAME.


Private Function AfxStrPathName (ByRef wszOption As WString, ByRef wszFileSpec As WString) As CWSTR
   Dim cws As CWSTR = ""
   If Len(wszFileSpec) = 0 Then Return cws
   Select Case Ucase(wszOption)
      Case "PATH"
         ' // Returns the path portion of file spec
         Dim nPos As Long = InstrRev(wszFileSpec, Any ":/\")
         If nPos Then cws = Mid(wszFileSpec, 1, nPos)
         Return cws
      Case "NAME"
         ' // Retrieve the full filename
         cws = wszFileSpec
         Dim nPos As Long = InstrRev(wszFileSpec, Any ":/\")
         If nPos Then cws = Mid(wszFileSpec, nPos + 1)
         ' // Retrieve the filename
         nPos = InstrRev(cws, ".")
         If nPos Then cws = Mid(cws, 1, nPos - 1)
         Return cws
      Case "NAMEX"
         ' // Retrieve the name and extension combined
         Dim nPos As Long = InStrRev(wszFileSpec, Any ":/\")
         If nPos Then cws = Mid(wszFileSpec, nPos + 1) Else cws = wszFileSpec
         Return cws
      Case "EXTN"
         ' // Retrieve the name and extension combined
         Dim nPos As Long = InstrRev(wszFileSpec, Any ":/\")
         If nPos Then cws = Mid(wszFileSpec, nPos + 1) Else cws = wszFileSpec
         ' // Retrieve the extension
         nPos = InStrRev(cws, ".")
         If nPos Then cws = Mid(cws, nPos) Else cws = ""
         Return cws
   End Select
End Function


Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer