I may have isolated a problem in Basic ...
the following Basic code explains
Code: Select all
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