P
Peter S.
Hi everybody,
I'm trying to get access to a selfdeveloped DLL. What I did:
I created a new Classobject in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ZufallArray
{
public class ZufallArray
{
[ExportDllAttribute.ExportDll("ZArray",
System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static int[] ZArray (int beginn, int ende, int anzahl)
{
int[] ZZahl = new int[anzahl];
Random randObj = new Random();
for (int j = 0; j < anzahl; j++)
{
ZZahl[j]= randObj.Next(beginn, ende);
}
return ZZahl;
}
}
}
I exported the function with "ExportDLL"
(http://www.codeproject.com/KB/dotnet/DllExport.aspx) and checked the result
with Dependency Walker.
I used the function with VBA (Excel):
Declare Function Zar Lib _
"C:\........\bin\Release\ZufallArray.dll" _
Alias "ZArray" (ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
As Integer()
Sub zarray()
Dim a() As Integer
a = Zar(10, 20, 3)
For i = 1 To UBound(a)
MsgBox a(i)
Next i
End Sub
Excel crashes! Why?
P.S.: I don't want to use the function by using a reference to .... .tlb and
than creating a new class in Excel (in this case the function must be defined
without "static). By the way this is working pretty good.
I want to use the function this way, because if this works, I can use the
function in other applications.
Peter
I'm trying to get access to a selfdeveloped DLL. What I did:
I created a new Classobject in C#:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace ZufallArray
{
public class ZufallArray
{
[ExportDllAttribute.ExportDll("ZArray",
System.Runtime.InteropServices.CallingConvention.Cdecl)]
public static int[] ZArray (int beginn, int ende, int anzahl)
{
int[] ZZahl = new int[anzahl];
Random randObj = new Random();
for (int j = 0; j < anzahl; j++)
{
ZZahl[j]= randObj.Next(beginn, ende);
}
return ZZahl;
}
}
}
I exported the function with "ExportDLL"
(http://www.codeproject.com/KB/dotnet/DllExport.aspx) and checked the result
with Dependency Walker.
I used the function with VBA (Excel):
Declare Function Zar Lib _
"C:\........\bin\Release\ZufallArray.dll" _
Alias "ZArray" (ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
As Integer()
Sub zarray()
Dim a() As Integer
a = Zar(10, 20, 3)
For i = 1 To UBound(a)
MsgBox a(i)
Next i
End Sub
Excel crashes! Why?
P.S.: I don't want to use the function by using a reference to .... .tlb and
than creating a new class in Excel (in this case the function must be defined
without "static). By the way this is working pretty good.
I want to use the function this way, because if this works, I can use the
function in other applications.
Peter