Call DLL Function (from Event Handler) Crashes?

Java, C++, C#, Delphi, ??? - Using the UNO bridges

Call DLL Function (from Event Handler) Crashes?

Postby todd_mm » Fri Feb 03, 2017 5:15 pm

I'm attempting to call functions in an external DLL from a button handler in scalc, but LibreOffice crashes at the end of the handler.
I'm not certain what I'm doing incorrectly. The external function calls "succeed" (has the desired effect, returns data, etc.), but at the end of the handler, LO crashes.

Here's the BASIC macro I have.

Code: Select all   Expand viewCollapse view
Declare Function _myfunc Lib "path\to\my.dll" Alias "myfunc" (ByVal inst as Integer) as Integer
Function myFunc(ByVal x as Integer) as Integer
    Dim rc as Integer
    rc = _myfunc(x)
    myFunc = rc
End Function

Sub ButtonHandler(oEvent)
    Print myFunc(0)
    FreeLibrary "path\to\my.dll"
End Sub


Am I doing this the proper way? Do I need to FreeLibrary at the end? It crashes with or without it. I tried putting it inside the function making the external call, without meaningful effect. Is there some other setup/teardown I need to do, in general? Are there limitations on event handlers?
Thanks.
LibreOffice 5.2.4 on Windows 7
todd_mm
 
Posts: 4
Joined: Fri Feb 03, 2017 4:47 pm

Re: Call DLL Function (from Event Handler) Crashes?

Postby RoryOF » Fri Feb 03, 2017 5:43 pm

Are not LibreOffice/OpenOffice BASIC variables case insensitive?
Apache OpenOffice 4.1.3 on Xubuntu 16.04 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 24171
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Call DLL Function (from Event Handler) Crashes?

Postby todd_mm » Fri Feb 03, 2017 5:45 pm

Probably.
Why would that matter? Am I using two variables with the same (insensitive) name?
LibreOffice 5.2.4 on Windows 7
todd_mm
 
Posts: 4
Joined: Fri Feb 03, 2017 4:47 pm

Re: Call DLL Function (from Event Handler) Crashes?

Postby JeJe » Sat Feb 04, 2017 12:58 am

Try in an otherwise empty module

Declare Function _myfunc Lib "path\to\my.dll" Alias "myfunc" (ByVal inst as Integer) as Integer

Sub test()
dim a as integer,b as integer
a= _myfunc(b)
End Sub

Make things the simplest possible and try...
Openoffice 4.1.2
Windows 8
JeJe
 
Posts: 105
Joined: Wed Mar 09, 2016 2:40 pm

Re: Call DLL Function (from Event Handler) Crashes?

Postby Zizi64 » Sat Feb 04, 2017 9:19 am

Or upload please the project (the ODF file with the macro code, and the DLL file. Then we will able to try it and (maybe) to fix the bug.
Tibor Kovacs, Hungary; LibreOffice4.4.7 - Portable versions: LO3.3.0-LO5.3.3 and AOO4.1.3; on Win7x64Prof.
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: 5128
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Call DLL Function (from Event Handler) Crashes?

Postby todd_mm » Tue Feb 07, 2017 7:33 pm

It's possible that there's a stack problem. Is there a way to specify the calling convention to be used? I'm having trouble finding documentation for this kind of thing.
LibreOffice 5.2.4 on Windows 7
todd_mm
 
Posts: 4
Joined: Fri Feb 03, 2017 4:47 pm

Re: Call DLL Function (from Event Handler) Crashes?

Postby Villeroy » Tue Feb 07, 2017 9:05 pm

OpenOffice on Windows is a 32-bit application.
LibreOffice is availlable in 64 bit.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 23732
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Call DLL Function (from Event Handler) Crashes?

Postby todd_mm » Thu Feb 09, 2017 8:39 pm

I'm using all 32-bit stuff. The DLL is a 32-bit binary, and I'm using a 32-bit version of LibreOffice.
LibreOffice 5.2.4 on Windows 7
todd_mm
 
Posts: 4
Joined: Fri Feb 03, 2017 4:47 pm

Re: Call DLL Function (from Event Handler) Crashes?

Postby ms777 » Sat Apr 15, 2017 6:24 pm

... this works on my Windows 10 (writes a '9'). You may want to try if this also crashes in your handler. Then you can be pretty sure that it is an AO problem

Code: Select all   Expand viewCollapse view
Declare function keybd_event Lib "user32.dll" ( ByVal bVk As Long, ByVal bScan As Long, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

sub main
  call keybd_event(57, 0, 0, 0)
end sub
ms777
 
Posts: 129
Joined: Mon Oct 08, 2007 1:33 am


Return to External Programs

Who is online

Users browsing this forum: No registered users and 1 guest