xsharp.eu • Transferring large VO project to X# - Page 2
Page 2 of 5

Transferring large VO project to X#

Posted: Thu May 06, 2021 12:28 am
by GlenT
That's one of the compelling reason for doing this trial.

Glen
jonhn wrote:Yes, you are quite right. I was, however, surprised by the dozens of relatively serious other errors the VO compiler let through to my .exe that X# will not. All kinds of warnings I had ignored for years, sorry to say, but they are all listed there.

Transferring large VO project to X#

Posted: Thu May 06, 2021 2:03 am
by GlenT
OK. I've got RightSLE compiling successfully with one warning that I can't understand. The warning is:

warning XS9068: The compiler generated an automatic conversion to PSZ. This may create a memory leak in your application. Please use String2Psz() to let the compiler manage the lifetime of the PSZ or use StringAlloc() and manage the lifetime of the PSZ yourself.

and the offending line is line is

AppendMenu( hMenu, MF_STRING, ID_MONTH1 + (DWORD)(i-1), SELF:aMonthsbyName)

in the EditMonth() method of PECalendar.prg

The parameters being passed are OK as far as I can see.

Cheers

Glen

Transferring large VO project to X#

Posted: Thu May 06, 2021 4:03 am
by stecosta66
jonhn wrote:Try this version of FAB tools attached.
Thanks jonhn
these are the dll that I already have.

I was trying to compile the FabTools source code I've downloaded from GitHub but this gives me error when importing FabTools.xsproj or FabTools.sln in VS19 (and in XIDE too)

maybe this needs to be updated from Fabrice or I'm doing something wrong

ciao
Stefano

Transferring large VO project to X#

Posted: Thu May 06, 2021 5:54 am
by robert
Glen,
AppendMenu is a windows API function in the VOWin32ApiLibrary.
This function expects a PSZ as last parameter.
You are (Willie is) passing in an array element.
To "satisfy" the compiler this Array element needs to be converted from a USUAL (array elements are untyped) to a PSZ. Of course that will only work when the array contains strings.

The compiler does not know what AppendMenu is doing with the PSZ. It could be making a copy of it, but it could also store the address of the PSZ and hold on to it. For that reason it cannot compile this into a call of String2Psz() since the PSZs allocated by that function will be automatically freed when the calling function ends.
For that reason the compiler creates an instance of the PSZ type and simply does not free that type.
Something like:

Code: Select all

AppendMenu( hMenu, MF_STRING, ID_MONTH1 + (DWORD)(i-1), PSZ{ (STRING) SELF:aMonthsbyName})
The PSZ type allocates a block of static memory and converts the string from Unicode to Ansi and stores this Ansi string in the static memory.
If you know that AppendMenu does not hold on to the PSZ but makes a copy (which it does) then you should change the code to:

Code: Select all

AppendMenu( hMenu, MF_STRING, ID_MONTH1 + (DWORD)(i-1), String2Psz(SELF:aMonthsbyName))
Robert

Transferring large VO project to X#

Posted: Thu May 06, 2021 6:50 am
by GlenT
Robert,

Thank you for the solution and particularly the detailed explanation. I have much to learn I think.

Cheers

Glen
robert wrote:Glen,
AppendMenu is a windows API function in the VOWin32ApiLibrary.
This function expects a PSZ as last parameter.
You are (Willie is) passing in an array element.
To "satisfy" the compiler this Array element needs to be converted from a USUAL (array elements are untyped) to a PSZ. Of course that will only work when the array contains strings.

The compiler does not know what AppendMenu is doing with the PSZ. It could be making a copy of it, but it could also store the address of the PSZ and hold on to it. For that reason it cannot compile this into a call of String2Psz() since the PSZs allocated by that function will be automatically freed when the calling function ends.
For that reason the compiler creates an instance of the PSZ type and simply does not free that type.
Something like:

Code: Select all

AppendMenu( hMenu, MF_STRING, ID_MONTH1 + (DWORD)(i-1), PSZ{ (STRING) SELF:aMonthsbyName})
The PSZ type allocates a block of static memory and converts the string from Unicode to Ansi and stores this Ansi string in the static memory.
If you know that AppendMenu does not hold on to the PSZ but makes a copy (which it does) then you should change the code to:

Code: Select all

AppendMenu( hMenu, MF_STRING, ID_MONTH1 + (DWORD)(i-1), String2Psz(SELF:aMonthsbyName))
Robert

Transferring large VO project to X#

Posted: Thu May 06, 2021 8:06 am
by Chris
diobrando wrote:
jonhn wrote:Try this version of FAB tools attached.
Thanks jonhn
these are the dll that I already have.

I was trying to compile the FabTools source code I've downloaded from GitHub but this gives me error when importing FabTools.xsproj or FabTools.sln in VS19 (and in XIDE too)

maybe this needs to be updated from Fabrice or I'm doing something wrong

ciao
Stefano
Thanks, Stefano, I see some problems, too, will tell Fabrice about it.

If you download the binaries only, do those work OK for you?

Transferring large VO project to X#

Posted: Thu May 06, 2021 11:49 pm
by GlenT
I now have FabTools and FabPaint compiling and have moved on to my WebBrowser class

In the WebBrowser, I have the line

CLASS WebBrowser INHERIT OleControl

and the compiler gives an error

error XS0246: The type or namespace name 'OleControl' could not be found (are you missing a using directive or an assembly reference?)

Is OleControl in the X# VO Classes?

Cheers

Glen

Transferring large VO project to X#

Posted: Fri May 07, 2021 12:05 am
by GlenT
Working on my function library now and I have two issues. Firstly, I have the function:

FUNCTION PCE_Is64BitOS() AS LOGIC
LOCAL hModule AS PTR
LOCAL hFunc AS PTR
LOCAL lIsWow64 AS LOGIC

hModule := GetModuleHandle( PSZ( "kernel32" ) )
hFunc := GetProcAddress( hModule, PSZ( "IsWow64Process" ) )

IF ! hFunc == NULL_PTR
PCALL( hFunc, GetCurrentProcess(), @lIsWow64 ) // <--error
ENDIF
RETURN lIsWow64

the error returned is

error XS9035: The first argument to PCALL must be a 'typed function pointer'.

I can't work out what I've got to declare hFunc as.

The 2nd issue is a dialogue that I expand in the show method to ensure that the text passed is fully displayed. The show method is

METHOD show( kShowState )
LOCAL strRect IS _WinRect
LOCAL hDC AS PTR
LOCAL nHeight AS LONGINT
LOCAL cStr AS STRING
LOCAL oSize AS dimension
LOCAL oPnt AS Point

// calculate the height of the message
cStr := SELF:oDCFTxtMessage:value
hDC := GetDC( SELF:Handle() )
SelectObject( hDC, SELF:oDCFTxtMessage:Font:Handle() )
strRect.bottom := SELF:Size:Height - SELF:oDCFTxtMessage:Origin:Y
strRect.top := SELF:Size:Height - ( SELF:oDCFTxtMessage:Origin:Y + SELF:oDCFTxtMessage:Size:Height )
strRect.left := SELF:oDCFTxtMessage:Origin:X
strRect.right := SELF:oDCFTxtMessage:Origin:X + SELF:oDCFTxtMessage:Size:Width
DrawText( hDC, String2Psz( cStr ), -1, @strRect, DT_CALCRECT + DT_WORDBREAK + DT_LEFT + DT_NOPREFIX )
nHeight := strRect.bottom - strRect.top
IF nHeight > SELF:oDCFTxtMessage:Size:Height
oSize := SELF:oDCFTxtMessage:Size
oSize:Height := nHeight
SELF:oDCFTxtMessage:Size := oSize
nHeight -= 111
oPnt := SELF:oDCFTxtMessage:Origin
oPnt:Y -= nHeight
SELF:oDCFTxtMessage:Origin := oPnt
oSize := SELF:Size
oSize:Height += nHeight
SELF:Size := oSize
ENDIF
SUPER:show( kShowState )
RETURN NIL

The compiler is detecting an error on the SelectObject line. The error message being

error XS0119: 'VO.TextControl.Font(params XSharp.__Usual[])' is a method, which is not valid in the given context

and I just can't understand that one.

Can anyone help please?

Cheers

Glen

Transferring large VO project to X#

Posted: Fri May 07, 2021 3:17 am
by wriedmann
Hi Glen,
OLE/COM as it worked in VO does not works anymore in X#.
Please see the X# help, "Migrating apps from VO to X#", "Example 5 - The Email Client Example".
That works (I have done it myself).
Wolfgang

Transferring large VO project to X#

Posted: Fri May 07, 2021 5:02 am
by stecosta66
Chris wrote:
diobrando wrote:
jonhn wrote:Try this version of FAB tools attached.
Thanks jonhn
these are the dll that I already have.

I was trying to compile the FabTools source code I've downloaded from GitHub but this gives me error when importing FabTools.xsproj or FabTools.sln in VS19 (and in XIDE too)

maybe this needs to be updated from Fabrice or I'm doing something wrong

ciao
Stefano
Thanks, Stefano, I see some problems, too, will tell Fabrice about it.

If you download the binaries only, do those work OK for you?
Hi Chris,
I've already added reference of FabTools.dll to the project, but it would be nice to have the FabTools source code compiling and running as we do in VO

thanks
Stefano