Basic Define Function ... causes LO 4.4.5.2 to crash

Keyboard macros or custom scripts

Basic Define Function ... causes LO 4.4.5.2 to crash

Postby bertram » Wed Dec 06, 2017 11:29 pm

running LibreOffice 4 in XPsp3 ... (I see I need to update my profile)

I may have isolated a problem in Basic ...

the following Basic code explains

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****

'Case 1
'this is not a bug, but suggests a feature
'it would allow a user to declare his working path to DLLs used in a Declare Sub/Function statements
Const Path_to_DLL_Filename      As String = "c:\0000_temp" & "\"
Const DLL_Filename            As String = "test0000_user32.dll"
Const DLL_Filename_with_Path   As String = Path_to_DLL_Filename & DLL_Filename

'the next two commands each cause failure to compile ...
'Declare Function Test_CharUpper Lib DLL_Filename_with_Path Alias "CharUpperA" ( ByVal lpsz As String ) As String
'Declare Sub Test_Beep Lib DLL_Filename_with_Path Alias "MessageBeep" ( Optional BeepTime As Long )

'Arghh ... it would be nice if users could place his project DLLs in a folder other than system32 or OpenOffice working folder

'OK ... just a suggestion
'if someone investigates this bug, they will have to open this code anyway.
'lets replace Const string for path and DLL filename with raw text values
'we test for two cases ...
'the first test passes OK ... meaning code is OK
'in this case, Lib calls user32.dll and LO application searches %path% and finds user32.DLL in system32 folder.

Declare Function Test_CharUpper1 Lib "user32.dll" Alias "CharUpperA" ( ByVal lpsz As String ) As String
Declare Sub Test_Beep1 Lib "user32.dll" Alias "MessageBeep" ( Optional BeepTime As Long )

'then copying the same code, with name change from 1 to 2, have the DLL be addressed by its full path string

'thus, create a temporary dir, C:\0000_temp
'copy C:\WINDOWS\system32\user32.dll into temp folder with name change to ... C:\0000_temp\test0000_user32.dll
'the renamed file, test0000_user32.dll is not in environment %path% -- the actual path must be given

'declare function and sub as above, with name change 1 to 2, but have Lib use text string for full path+filename
Declare Function Test_CharUpper2 Lib "c:\0000_temp\test0000_user32.dll" Alias "CharUpperA" ( ByVal lpsz As String ) As String
Declare Sub Test_Beep2 Lib "c:\0000_temp\test0000_user32.dll" Alias "MessageBeep" ( Optional BeepTime As Long )

'now test the code for the first case ...
Sub Test_CallsToLibDLLinSystem32
   Dim TestStrIn As String
   Dim TestStrOut As String
   TestStrIn = "I Have Upper and Lower."
'this sub calls Test_CharUpper1 and Test_Beep1, where Lib DLL is user32.dll found by %path% environment variable
   TestStrOut = Test_CharUpper1( ByVal TestStrIn )

   MsgBox "pass variable with ByVal" & CHR$(10) & CHR$(10) & TestStrIn & CHR$(10) & "converted to:" & CHR$(10) & TestStrOut, 0, "Call a DLL Function"

   Dim nBeepTest As Long
   nBeepTest = 1000
   Test_Beep1( nBeepTest )
'it passes test!
   MsgBox "This MsgBox is the last command." & _
      CHR$(10) & CHR$(10) & "Click [OK] and LibreOffice 4 ..." & _
      CHR$(10) & CHR$(10) & "SURVIVES!"

End Sub

'OK that was nice ...
'now let's test for the second case.
'in this case, the application finds the DLL file, opens it, and executes routines same as above.

'BUT ... after completing routines ...
'on closing the Sub, LibreOffice 4 causes an instantaneous application crash ...
'POOF it goes, with no crash warning, afer last MsgBox ... !!

Sub Test_CallsToLibDLLwithPath
   Dim TestStrIn As String
   Dim TestStrOut As String
   TestStrIn = "I Have Upper and Lower."
'call Test_CharUpper2 and Test_Beep2, with Lib DLL file identified by full path in declare statement
   TestStrOut = Test_CharUpper2( ByVal TestStrIn )
   MsgBox "pass variable with ByVal" & CHR$(10) & CHR$(10) & TestStrIn & CHR$(10) & "converted to:" & CHR$(10) & TestStrOut, 0, "Call a DLL Function"

   Dim nBeepTest As Long
   nBeepTest = 1000
   Test_Beep2( nBeepTest )

   MsgBox "Both calls to Lib path_filename.dll worked OK."

'   include the FreeLibrary command below and the application will crash BEFORE it gets to MsgBox.
'   FreeLibrary( "c:\0000_temp\test0000_user32.dll" )

   MsgBox "This MsgBox is the last command." & _
      CHR$(10) & CHR$(10) & "Click [OK] and LibreOffice 4 ..." & _
      CHR$(10) & CHR$(10) & "CRASHES!"

'   After this MsgBox, LibreOffice 4 application also crashes, i.e. on End Sub.

End Sub
User avatar
bertram
 
Posts: 4
Joined: Sat Mar 17, 2012 4:35 am

Re: Basic Define Function ... causes LO 4.4.5.2 to crash

Postby Zizi64 » Thu Dec 07, 2017 8:33 pm

Please upload the ODF type sample file, with the embedded full macro code, and the zipped DLL file (if they are public...) then we will able to make some try with them...
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Basic Define Function ... causes LO 4.4.5.2 to crash

Postby bertram » Fri Dec 08, 2017 1:58 am

thanks Zizi!

LO spreadsheet file attached

a zip with the user32.dll is greater than 128KB
the user32.dll in any Windows system should work
anyway it's probably safer to not have my user32.dll and your user32.dll both in your system

also comments within the macro were expanded and cleaned up

Code: Select all   Expand viewCollapse view
REM  *****  BASIC  *****

' In this header section of this macro
' - I declare three string constants, which I'd like to use in Declare statements
' - I declare three sets of subs and functions
' - They call standard functions in a standard MS Windows DLL library
' - I use a standard DLL that is installed with Windows XP Pro XP3 ... C:\WINDOWS\system32\user32.dll
' - I'm using it to test the Declare statement ...

' In the first set, v1, of subs and functions,
' - I attempt to use string constants to tell LO Basic where the DLL Library that I want to use is.
' - I had to rem these calls out, because the Basic compiler fails when it tries to compile the library.
' - At compile time, LO Basic rejects use of constants (also in the header).
' - OK, fair enough ... I understand.
' - But it would still be nice if Basic could compile header constants first,
' - so they could then be used in header declares which follow.
' - At least as argument for Lib declaration of the location of the users development DLL file.
' - Thus, to test the two other sets of declares, v2 and v3, the first set v1 has to be rem'd out.

Const Path_to_DLL_Filename      As String = "c:\0000_temp" & "\"
Const DLL_Filename            As String = "temp0000_user32.dll"
Const DLL_Filename_with_Path   As String = Path_to_DLL_Filename & DLL_Filename

' - The next two declares (set v1) attempt to use string constants for the address to the Lib DLL.
' - they cause the compiler to fail, so to continue development, they have to be rem'd out.
' - un-rem the next two lines and compile, to see if your compiler makes the same complaint ...
'Declare Function v1_Test_CharUpper Lib DLL_Filename_with_Path Alias "CharUpperA" ( ByVal lpsz As String ) As String
'Declare Sub      v1_Test_Beep      Lib DLL_Filename_with_Path Alias "MessageBeep" ( Optional BeepTime As Long )

' - It would be nice if users could place development DLLs in a work folder other than a system or %path% folder.

'In the second set of declares, v2, we verify that the code is OK.
' - for the Lib we use a standard Windows DLL from XP system folder ... user32.dll
' - In XP, it is located in C:\WINDOWS\system32 which is in the system %path%

Declare Function v2_Test_CharUpper Lib "user32.dll" Alias "CharUpperA" ( ByVal lpsz As String ) As String
Declare Sub      v2_Test_Beep      Lib "user32.dll" Alias "MessageBeep" ( Optional BeepTime As Long )

' - We will call these v2 versions in a sub after the header, named SUB v2_TestCallToLibDLL ()

' - We still have one more set of declarations to make to finish the header ...
' - in v3 we use the same code, but the Lib DLL will be addressed by given path + filename
' - thus we are not going to mix our development DLL with DLLs in the system %path%

' - some temporary work is required
' - create a temporary folder, for example, C:\0000_temp
' - copy a working dll to this folder (in XP, user32.dll is found in folder C:\WINDOWS\system32)
' - change the file name, for example to temp0000_user32.dll,
' - now the system can't find it in a 5path% folder
' - it has to use the path given in the declare statement

Declare Function v3_Test_CharUpper Lib "C:\0000_temp\temp0000_user32.dll" Alias "CharUpperA" ( ByVal lpsz As String ) As String
Declare Sub      v3_Test_Beep      Lib "C:\0000_temp\temp0000_user32.dll" Alias "MessageBeep" ( Optional BeepTime As Long )

' - We will call these v3 versions in a sub named v3_TestCallToLibDLL

'we also test addressing to the DLL, relative to the current drive used by LibreOffice
Declare Function v4_Test_CharUpper Lib   "\0001_temp\temp0001_user32.dll" Alias "CharUpperA" ( ByVal lpsz As String ) As String
Declare Sub      v4_Test_Beep      Lib   "\0001_temp\temp0001_user32.dll" Alias "MessageBeep" ( Optional BeepTime As Long )

'OK, that complets the header, and we're ready to test the above declare statements, v2 and v3, in the macro
' - v1 can't compile, so it can't be tested

'PLACE the cursor anywhere within the following Sub and run it (presss F5)

Sub v2_TestCalToLibDLL
   Dim TestStrIn As String
   Dim TestStrOut As String
   TestStrIn = "I Have Upper and Lower."

   'in v2, Lib DLL is user32.dll, which is found the system32 dir, whic his included in the system %path%
   'interesting ... the ByVal statement has to be here to avoid ByRef
   'the ByVal statement in the declare is apparently ignored
   
   TestStrOut = v2_Test_CharUpper( ByVal TestStrIn )
   MsgBox "pass variable with ByVal ..." & CHR$(10) & CHR$(10) & _
      "TestStrIn = " & TestStrIn & CHR$(10) & _
      "is converted to:" & CHR$(10) & _
      "TestStrOut = " & TestStrOut, 0, "Call a Lib DLL in system %path%"

   'drop the ByVal in the call, but leave ByVal the declare,
   'note that a ByVal variable is now passed ByRef.
   TestStrOut = v2_Test_CharUpper( TestStrIn )
   MsgBox "pass variable ByRef with ByVal declared ..." & CHR$(10) & CHR$(10) & _
      "TestStrIn = " & TestStrIn & CHR$(10) & _
      "is converted to:" & CHR$(10) & _
      "TestStrOut = " & TestStrOut, 0, "Call a Lib DLL in system %path%"

   'OK, that's not the point of this macro.
   'turn speaker volume on ...

   Dim nBeepTest As Long
   nBeepTest = 1000  'actually any value, including null will work
   v2_Test_Beep( nBeepTest )

   MsgBox "This MsgBox is the last command in this sub." & _
      CHR$(10) & CHR$(10) & "Click [OK] and LibreOffice 4 ..." & _
      CHR$(10) & CHR$(10) & "      SURVIVES!"
End Sub

'OK, calls to Lib DLL in v2 worked just fine ...
'the DLL is a standard DLL in a standard system folder, i.e. in a system %path% folder

' - now test v3, using the same file, renamed and put in a working development folder
' - use the same code as v2 above

'Now, place the cursor anywhere in sub v3 that follows ... and press F5

Sub v3_Test_CallsToLibDLL
   Dim TestStrIn As String
   Dim TestStrOut As String
   TestStrIn = "I Have Upper and Lower."

   TestStrOut = v3_Test_CharUpper( ByVal TestStrIn )
   MsgBox "pass argument with ByVal in the call ..." & CHR$(10) & CHR$(10) & _
      "TestStrIn = " & TestStrIn & CHR$(10) & _
      "is converted to:" & CHR$(10) & _
      "TestStrOut = " & TestStrOut, 0, "Call the Lib DLL by path + filename"

   'OK, that worked ...

   Dim nBeepTest As Long
   nBeepTest = 1000
   v3_Test_Beep( nBeepTest )

   MsgBox "Both declares in V3, Sub and Function," & CHR$(10) & _
   "using path + filename as argument for Lib" & CHR$(10) & _
   "worked OK."

'   include the FreeLibrary command below and the application will crash BEFORE it gets to the next MsgBox.
'   FreeLibrary( "C:\0000_temp\temp0000_user32.dll" )

   MsgBox "This MsgBox will be the last you see of LibreOffice." & _
      CHR$(10) & CHR$(10) & "Click [OK] and LibreOffice 4 will ..." & _
      CHR$(10) & CHR$(10) & "      INSTANTANEOUSLY DISAPPEAR!"

'   When the sub returns from MsgBox, the application instantaneously crashes ...

End Sub

'v4 tests argument address relative to working drive for LibreOffice spreadsheet file ...
'... LO fails to locate file, doesn't run and also doesn't crash

Sub v4_Test_CallsToLibDLL
   Dim TestStrIn As String
   Dim TestStrOut As String
   TestStrIn = "I Have Upper and Lower."

   TestStrOut = v4_Test_CharUpper( ByVal TestStrIn )
   MsgBox "pass argument with ByVal in the call ..." & CHR$(10) & CHR$(10) & _
      "TestStrIn = " & TestStrIn & CHR$(10) & _
      "is converted to:" & CHR$(10) & _
      "TestStrOut = " & TestStrOut, 0, "Call the Lib DLL by path + filename"

   'OK, that worked ...

   Dim nBeepTest As Long
   nBeepTest = 1000
   v4_Test_Beep( nBeepTest )

   MsgBox "Both declares in V3, Sub and Function," & CHR$(10) & _
   "using path + filename as argument for Lib" & CHR$(10) & _
   "worked OK."

'   include the FreeLibrary command below and the application will crash BEFORE it gets to the next MsgBox.
'   FreeLibrary( "\0001_temp\temp0001_user32.dll" )

   MsgBox "This MsgBox will be the last you see of LibreOffice." & _
      CHR$(10) & CHR$(10) & "Click [OK] and LibreOffice 4 will ..." & _
      CHR$(10) & CHR$(10) & "      INSTANTANEOUSLY DISAPPEAR!"

'   When the sub returns from MsgBox, the application instantaneously crashes ...

End Sub
Attachments
LibreOffice_v4452_PossibleBug_BasicIDE_DeclareStatement.ods
(22.36 KiB) Downloaded 5 times
Platonic solids can be constructed by modulation of rotational action -- the tetrahedron for example.
Windows XP pro SP3, LibreOffice 4.4.5.2
User avatar
bertram
 
Posts: 4
Joined: Sat Mar 17, 2012 4:35 am

Re: Basic Define Function ... causes LO 4.4.5.2 to crash

Postby Zizi64 » Fri Dec 08, 2017 8:18 am

w98se with unicode, OOo 2.4, ...


What??? Are you really using OpenOffice.org 2.4 version??? I think: nobody can try your file with that version today... And nobody remember the bugs and issues of the OOo 2.4.

(The newer versions can not run on the Win98se, therefore you can not upgrade to a newer version on that operating system...)

Code: Select all   Expand viewCollapse view
FreeLibrary( "C:\0000_temp\temp0000_user32.dll"

But we need the DLL file too - to try it on the latest (or older) AOO or LO versions. What is that temp0000_user32.dll? Is it a copy of some system DLL?

 Edit: oops, I see now:
Code: Select all   Expand viewCollapse view
(in XP, user32.dll is found in folder C:\WINDOWS\system32)

Then are you using WinXP or Win98SE - or other operating system??? 
Tibor Kovacs, Hungary; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Basic Define Function ... causes LO 4.4.5.2 to crash

Postby bertram » Fri Dec 08, 2017 9:28 pm

==== edit ====

Zizi -- read my post below first.

==== original post ====
sorry Zizi-- I was active on this board long ago, and was using 98se at the time.

I got in a hurry and forgot to update my profilie. It's been corrected. I'm running LibreOffice 4.4.5.2, in XP pro SP3.

XP has a DLL, by Microsoft, with utilities for users. It's called user32.dll. In XP it is found in the c:\WINDOWS\system32 folder.

It's a basic utiliitty DLL and I think every MS windows system probably has one, but I'm not sure.

for Windows 7, see https://www.win7dll.info/user32_dll.html
The same file is present, just a newer version. It's also in the same folder, i.e. C:\WINDOWS\system32
The utilties in the XP version are also carried forward in the 7-version.
I'm testing the macro using MESSAGEBEEP in the standard MS utilties DLL, called "user32.dll."

In my updated build of XP (yes, MS is still updating XP, but it's not advertised), the MS user API file, the "user32.dll" file is ...
filename "user32.dll"
version 5.1.2600.5577
file size 578,560 bytes
MD5 checksum 3de22354c3609b3c3e5dc2c19c5e0693 *user32.dll

7ZIP (at maximum compression) reduces the size down to 246,148 bytes.

I can't upload my copy of the Microsoft DLL, because it exceeds the 128 KiB maximum allowed for uploads.
It's probably available somewhere on DigitalLife, but newer versions of user32.dll will also have the XP functions in it, like MESSAGEBEEP.

====

I got the macro working using a Define Sub statement in the header. The "Lib" argument works when it calls user32.dll, by filenamem only.
The macro finds the file in system32 folder, which is in the system path.

Then, I copied DLL to another folder, that is not in the system path, and I renamed the file, so it couidn't be found in path.
I wanted to test if I could pass a Lib-argument in a Declare Sub statement, with complete filename with drive and path.
For example I used ... C:\0000_temp\temp0000_user32.dll, where temp000_user32.dll is a renamed copy of user32.dll in the system32 folder.

OO/LO Basic literature suggests that the Lib-argument works for just filename only ... meaning the file must be placed in the system path.

The macro works! The Lib argument, with full name, drive path and filename, finds the renamed file, in the drive-folder location, which is not in the path.

Which is wonderful ... until
the End Sub command
and that when LO 4.4.5.2 simply disappears off the screen. It doesn't hang. it simply disappears. ... "POOF!"

Thus this code works
Code: Select all   Expand viewCollapse view
header:
Declare Sub      v3_Test_Beep      Lib "C:\0000_temp\temp0000_user32.dll" Alias "MessageBeep" ( Optional BeepTime As Long )
'later a sub in program space calls the above declared sub, v3_Test_Beep :
Sub somename ()
...
'call the declared function, with Lib argument as full path + filename for the DLL.
v3_Test_Beep( 1000 )
'the macro works OK up to here
...
'until End Sub is reached ...
That's when LO simply disappears off the screen.
End Sub


It's quite amazing ...

--- edit ---
The difference is When the function is called using only the filename as the Lib-argument, and when the macro reaches End Sub, the program control continues in a normal way, and LO doesn't crash ... actually disappear.
When the Lib-argument contains full path, with drive path and filename, the macro works, i.e. calls the DLL etc., but when the macro comes to End Sub, LO application simply disappears off the desktop.
Last edited by bertram on Sat Dec 09, 2017 3:36 am, edited 1 time in total.
Platonic solids can be constructed by modulation of rotational action -- the tetrahedron for example.
Windows XP pro SP3, LibreOffice 4.4.5.2
User avatar
bertram
 
Posts: 4
Joined: Sat Mar 17, 2012 4:35 am

Re: Basic Define Function ... causes LO 4.4.5.2 to crash

Postby bertram » Sat Dec 09, 2017 3:35 am

hi Zizi --

I made a huge error -- I'll need a day or two to hack the correction.

I just learned that the file that I am using to test with -- user32.dll in system32 folder under WINDOWS ...

It is statically linked to three other files, also in system32 folder
ntdll.dll
GDI32.dll
KERNEL32.dll

"This means that when user32.dll is loaded, the above files are automatically loaded too."

It might be that user32.dll is hard coded to look for these three files in the system32 folder.

This might be the cause of the problem. End Sub causes user32.dll to close. When it tries to close, it can't find them, causing GDI to crash, causing graphics display of LO application to disappear.

I'll post my results in a few days ... sorry for late discovery of my error.

I really prefer the idea of pointing Lib-argument to a working DLL that can be some folder not the system folder or in the system path.
Platonic solids can be constructed by modulation of rotational action -- the tetrahedron for example.
Windows XP pro SP3, LibreOffice 4.4.5.2
User avatar
bertram
 
Posts: 4
Joined: Sat Mar 17, 2012 4:35 am

Re: Basic Define Function ... causes LO 4.4.5.2 to crash

Postby robleyd » Sat Dec 09, 2017 3:51 am

You might want to have a look at Dependency Walker - might save you some headaches :-)
Cheers
David
Apache OpenOffice 4.1.4 - Windows 7
Apache OpenOffice 4.1.4 - Slackware 14.2 - 64 bit
User avatar
robleyd
Moderator
 
Posts: 1094
Joined: Mon Aug 19, 2013 3:47 am
Location: Murbko, Australia


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 7 guests