本文介绍了调用C从基本​​的LibreOffice共享库函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图调用C从基本​​的LibreOffice共享库函数,但我总是得到基本运行时错误。没有实现,当它击中的声明一致。这只是一个有趣的事情,但暂时无法做到这一点是窃听我。

I'm trying to call a C shared library function from LibreOffice Basic, but I always get "Basic Runtime Error. Not implemented" when it hits the Declare line. It's just for a fun thing but being unable to do it is bugging me.

的声明语句如下:

声明功能score_word库libscrabblescore.so(为ByRef字作为字符串,为ByRef奖金作为字符串)作为整数

C函数delaration看起来是这样的:

The C function delaration looks like this:

INT score_word(字符*词,字符* word_bonuses)

(可能为ByRef字作为字符串不是字符*单词的正确翻译?我找不到如何使用的char *参数从LibreOffice的基本功能的文档。)

(Maybe ByRef word As String is not the right translation of char* word? I can't find documentation on how to use char* parameters to functions from LibreOffice Basic.)

我验证共享库本身使用Python的ctypes的模块调用它:

I validated the shared library itself by calling it using Python's ctypes module:

>>> from ctypes import CDLL
>>> lib = CDLL("/usr/lib/libscrabblescore.so")
>>> lib.score_word("qi", "dw dlq")
42
>>>

(所以我有答案生命,宇宙和万物的终极问题,只是没有就如何在LibreOffice中基本做到这一点!)

(So I have the "Answer to the Ultimate Question of Life, the Universe, and Everything," just not for how to do this in LibreOffice Basic!)

我试着用Declare语句中的绝对路径,以及,它并没有区别。

I tried using the absolute path in the Declare statement as well, and it made no difference.

我发现调用DLL的地方提问者说,他需要把DLL在一个特定的位置(LibreOffice的bin目录下),这样的LibreOffice可以访问它的话题一个Windows线程。有每本身没有LibreOffice的bin目录在Linux上,不幸的是有351候选目录,我能够确定我的机器(我的道路上,并用LibreOffice的所有文件夹的名称或文件夹下,在LibreOffice的名)。

I found a Windows thread on the topic of calling DLL's where the asker said he needed to put the DLL in a specific location (the LibreOffice bin directory) so LibreOffice could access it. There is no LibreOffice bin directory per-se on Linux, and unfortunately there are 351 candidate directories I was able to identify on my machine (my path, and all folders with "libreoffice" in the name or under a folder with "libreoffice" in the name).

我尝试了鸟枪法,把一个符号链接共享库中的所有目录351,但随后计算器挂起启动。所以我删除这些,开始计算器,并把它们全部到位回来,并试图功能。如果这是一个位置的东西,你会以为是LibreOffice的基本假定在​​申报点加载库,将工作。仍然没有运气。

I tried a shotgun approach and put a symbolic link to the shared library in all 351 directories, but then Calc hangs on startup. So I removed those, started Calc, and put them all back in place and tried the function. If it was a location thing, you'd think that would work as LibreOffice Basic is supposed to load the library at the point of the Declare. Still no luck.

有些东西看着oooforums但网站超时有前途的,当我尝试查看线程。 (编辑:我设法今天晚上来查看线程,它是Windows的安全问题,我在LibreOffice中关闭所有的宏安全性,仍然有问题。)

There was something that looked promising on oooforums but the site times out when I try to view the thread. ( I managed to view the thread this evening and it was Windows security problem. I turned off all macro security in my LibreOffice and still have the problem.)

那么,有没有人曾经成功地称作C从知道我做错了一的LibreOffice Basic程序共享库函数?谢谢!

So, has anybody ever successfully called a C shared library function from a LibreOffice Basic program that knows what I'm doing wrong? Thanks!

推荐答案

除非你仅限于基本那么它看起来像你的问题已经具备了很好的解决方案。写这样的事情在Python UNO:

Unless you are limited to Basic then it looks like your question already shows a good solution. Write something like this in Python UNO:

import ctypes
lib = ctypes.cdll.loadLibrary("/usr/lib/libscrabblescore.so")
result = lib.score_word("qi", "dw dlq")
oText.insertString(oTextCursor, result, 0)

这篇关于调用C从基本​​的LibreOffice共享库函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:51
查看更多