Hi,
Thank you for the quick reply.
What I did was:
to place your code in a file named fonseca3.vb
add a line at the beginning of your code, with: Imports
ExcelDna.Integration
add a line at the beginning of the .dna file, with: <ExternalLibrary
Path="fonseca3.dll" Pack="true"/>
checked with dumpbin the name of the function
change the NativeFunctionLib to mathFunctions (the name of the dll
file)
change the fnNativeFunction to compiledFunction1 (the name of the
function retrieved with the dumbin)
compiled the fonseca3.vb (no errors)
packed the xll (no errors)
place the fonseca3.dll file in the same folder as the packed xll
opened excel (no errors)
tried the function: #VALUE! (it should have given the square of the
number: please see code below)
Since I'm an amateur, I probably didn't understood something
Help me please,
P Fonseca
- - - - - - - - - - - - - - - - - - -
mathFunctions.dll original C code:
#include "math.h"
#include "WolframLibrary.h"
#include "WolframCompileLibrary.h"
static WolframCompileLibrary_Functions funStructCompile;
static mbool initialize = 1;
DLLEXPORT mint WolframLibrary_getVersion()
{
return WolframLibraryVersion;
}
static int Initialize_compiledFunction1(WolframLibraryData libData)
{
if( initialize)
{
funStructCompile = libData->compileLibraryFunctions;
initialize = 0;
}
return 0;
}
static void Uninitialize_compiledFunction1(WolframLibraryData libData)
{
if( !initialize)
{
initialize = 1;
}
}
DLLEXPORT int WolframLibrary_initialize(WolframLibraryData libData)
{
return Initialize_compiledFunction1(libData);
}
void WolframLibrary_uninitialize(WolframLibraryData libData)
{
Uninitialize_compiledFunction1(libData);
}
DLLEXPORT char * WolframCompileLibrary_exportName()
{
return "compiledFunction1";
}
DLLEXPORT char * WolframCompileLibrary_wrapper()
{
return "Function[CompiledFunction[List[8, 8.`, 5468],
List[Blank[Real]], List[List[3, 0, 0], List[3, 0, 1]], List[], List[0,
0, 2, 0, 0], List[List[40, 56, 3, 0, 0, 3, 0, 1], List[1]],
Function[List[x], Power[x, 2]], Evaluate, Slot[1]]]";
}
DLLEXPORT mint WolframCompileLibrary_getArgumentTypes(int ** pt, mint
** pr)
{
static int types[] = {3, 3};
static mint ranks[] = {0, 0};
*pt = &types[0];
*pr = &ranks[0];
return 1;
}
DLLEXPORT int compiledFunction1(WolframLibraryData libData, mint Argc,
MArgument *Args, MArgument Res)
{
mreal R0_0;
mreal R0_1;
R0_0 = MArgument_getReal(Args[0]);
R0_1 = R0_0 * R0_0;
MArgument_setReal(Res, R0_1);
return 0;
}
- - - - - - - - - - - - - - - - - - -
fonseca3.vb content
Imports ExcelDna.Integration
Imports System.IO
Imports System.Runtime.InteropServices
Public Module TestDeclare
'em DLLImport, colcoa-se o nome da DLL e nao da funcao
<DllImport("mathFunctions")> _
Function compiledFunction1(value as double) as double
End Function
<ExcelFunction(Description:="Call that native function",
Category:="My Native Functions")> _
Function CallMyFunction(value As Double) As Double
Return compiledFunction1(value)
End Function
' A test function that will show error details.
Function TestCall() As String
Dim d As Double
Try
d = CallMyFunction(100)
Return "OK: " & d
Catch e as Exception
Return e.ToString()
End Try
End Function
End Module
Public Class MyAddIn
Implements IExcelAddIn
<DllImport("kernel32", SetLastError:=True)> _
Shared Function LoadLibrary(ByVal lpFileName As String) As IntPtr
End Function
Public Sub AutoOpen Implements IExcelAddIn.AutoOpen
Dim xllDirectory As String
Dim dllPath As String
Dim dllHandle as IntPtr
xllDirectory = AppDomain.CurrentDomain.BaseDirectory
dllPath = Path.Combine(xllDirectory, "mathFunctions.dll")
dllHandle = LoadLibrary(dllPath)
' Can check for error: dllHandle = IntPtr.Zero etc.
End Sub
Public Sub AutoClose Implements IExcelAddIn.AutoClose
End Sub
End Class
- - - - - - - - - - - - - - - - - - -
DUMP content:
Dump of file mathFunctions.dll
File Type: DLL
Section contains the following exports for compiledFunction1.dll
0 characteristics
4D7157F7 time date stamp Fri Mar 04 21:21:59 2011
0.00 version
1 ordinal base
6 number of functions
6 number of names
ordinal hint RVA name
1 0 000012D0 WolframCompileLibrary_exportName
2 1 000012E8 WolframCompileLibrary_getArgumentTypes
3 2 000012DC WolframCompileLibrary_wrapper
4 3 00001280 WolframLibrary_getVersion
5 4 0000128C WolframLibrary_initialize
6 5 00001304 compiledFunction1
Summary
1000 .CRT
1000 .bss
1000 .data
1000 .edata
1000 .eh_fram
1000 .idata
1000 .rdata
1000 .reloc
1000 .text
1000 .tls
- - - - - - - - - - - - - - - - - - -