[Solved] Can macros using a dll written in c#
[Solved] Can macros using a dll written in c#
i'm trying to use dll written in c# but, i don't know how to do it .
can anyone help me?
thx
can anyone help me?
thx
Last edited by samchanfs on Fri Aug 05, 2011 6:06 am, edited 1 time in total.
OpenOffice 3.3 on Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Can macros using a dll written in c#
This could turn into a rather involved thread which would belong in the macros forum. But for starters, let's discuss calling dll functions in a OOo Basic macro.samchanfs wrote:i'm trying to use dll written in c# but, i don't know how to do it .
can anyone help me?
thx
That uses the Declare statement (see Basic help)
Code: Select all
Declare {Sub | Function} Name Lib "Libname" [Alias "Aliasname"] [Parameter] [As Type]
Code: Select all
__declspec(dllexport) double add2numbers(double a, double b)
{
return a + b;
}
Code: Select all
?add2numbers@@YANNN@Z
How to find the exported names? In c++ there is a thing called DumpBin, but you can also just load the dll into a text or hex editor and look for names such as above.
Code: Select all
Declare Function addnumbers Lib "path\filename.dll" Alias "?add2numbers@@YANNN@Z" (ByVal a As Double,ByVal b As Double) As Double
Function Add(a As double,b As Double) As Double
Add = addnumbers(a,b)
End Function
Hopefully this'll get you started.
Note well that Declare is used at the module level, not within a Sub or Function.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Can macros using a dll written in c#
I can't find the Aliasname in C# dll and when i use the function it have an error at this code
Declare Function myFirstDll Lib "c:/testdll.dll" Alias "myFirstDll" (ByVal a as string) As String
it was show me an error "basic runtime error sub-procedure or function procedure not defined"
Declare Function myFirstDll Lib "c:/testdll.dll" Alias "myFirstDll" (ByVal a as string) As String
it was show me an error "basic runtime error sub-procedure or function procedure not defined"
OpenOffice 3.3 on Windows XP
- Charlie Young
- Volunteer
- Posts: 1559
- Joined: Fri May 14, 2010 1:07 am
Re: Can macros using a dll written in c#
Where did the dll come from? If you wrote it yourself you can control the aliasnames. There are differences between c# and c++, but if I write my add2numbers function likesamchanfs wrote:I can't find the Aliasname in C# dll and when i use the function it have an error at this code
Declare Function myFirstDll Lib "c:/testdll.dll" Alias "myFirstDll" (ByVal a as string) As String
it was show me an error "basic runtime error sub-procedure or function procedure not defined"
Code: Select all
extern "C" __declspec(dllexport) double add2numbers(double a, double b)
{
return a + b;
}
[code]
then the aliasname is just add2numbers instead of the mangled ("decorated") name I presented in my first reply.
Of course you need to know the function arguments by type and its return type.
Apache OpenOffice 4.1.1
Windows XP
Windows XP
Re: Can macros using a dll written in c#
Or open your mind a bit and look at it from a different point of view. In OpenOffice you are not bound to Basic as macro language as you are with the Microsoft Office suite. As far as I know there is a C#-Uno bridge which can be used to programm the UNO objects of OpenOffice. You can work in your familiar C# development environment and should have no problems at all to use code from within Dlls (whatever you can load with C# or the .NET framework).
Edit: I guess I should be a bit more constructive. So please look in the External Programs subforum of the Macro forum for some ideas how to work with C# |
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: Can macros using a dll written in c#
to Charlie
the dll is my boss give, so I can't change to use c++. And i can't find any code can make c# dll use like this
the dll is my boss give, so I can't change to use c++. And i can't find any code can make c# dll use like this
Code: Select all
extern "C" __declspec(dllexport) double add2numbers(double a, double b)
{
return a + b;
}
OpenOffice 3.3 on Windows XP
Re: [SOLVED]Can macros using a dll written in c#
samschanfs,
you have marked this thread as solved. But unfortunately if others are looking at this thread they won't see a solution.
So it would be nice, if you add a short comment how you solved it. Did your boss modify the calling convention in the C# Dll? Or did you find another way to use the Dll?
A forum can't live without questions. But it won't survive very long without answers. So please think from the point of view of a community project and add this little more effort to make this thread more helpful for others.
Thanks for the cooperation.
you have marked this thread as solved. But unfortunately if others are looking at this thread they won't see a solution.
So it would be nice, if you add a short comment how you solved it. Did your boss modify the calling convention in the C# Dll? Or did you find another way to use the Dll?
A forum can't live without questions. But it won't survive very long without answers. So please think from the point of view of a community project and add this little more effort to make this thread more helpful for others.
Thanks for the cooperation.
OpenOffice 3.1.1 (2.4.3 until October 2009) and LibreOffice 3.3.2 on Windows 2000, AOO 3.4.1 on Windows 7
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
There are several macro languages in OOo, but none of them is called Visual Basic or VB(A)! Please call it OOo Basic, Star Basic or simply Basic.
Re: [Solved] Can macros using a dll written in c#
it need register to com object and use following code to call.
sub TestDll
bj = CreateObject("test.Class1")
msgbox bj.test()
End sub
sub TestDll
bj = CreateObject("test.Class1")
msgbox bj.test()
End sub
OpenOffice 3.3 on Windows XP