LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Using DLL from C#

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.C decl)]
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

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 07:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"