Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
Hello everyone,

I need to build a C# dll and to call it from VBA. I've tested it on a simple example with a method that returns strings. But how can I return more complex objects? For instance, my method will return a C# proprietary binary tree. How will it be converted to VBA?

Thanks in advance,
Mark
Posted

1 solution

So basically you want your C# dll to populate a binary tree that you can then interrogate from VBA.
You will probably have to implement methods such as Load, First, Next, Count etc. and use them from VBA to get the data out of the DLL. I don't think you can use a C# proprietary binary tree for much in VBA, but I will probably stand corrected shortly.

You may get some hints from this answer.
installing and Refereing .net dll programmatically from vba app[^]
You've basically got to create a COM dll. I've had various issues trying to do so with .NET in the past - and I've resorted to make my dll in Delphi, because it just worked without any of the hoops.
 
Share this answer
 
v2
Comments
Maciej Los 4-Sep-12 16:19pm    
Good answer! +5
Erik Rude 5-Sep-12 7:12am    
Thanks!
mark4 6-Sep-12 8:09am    
I just did a test with a method that returns a complex C# class. When VBA tries to call it, it generates an error ("Undefined object"). So, my question is still open...
Erik Rude 7-Sep-12 4:21am    
If you share your code and experiences you may get a better response.
mark4 7-Sep-12 7:59am    
My question is not linked with a specific code, suppose my mehod returns a binary tree (a class Node). The idea is to write a COM component that can be shared between applications. But I find the tutorials quite difficult and I'm looking for a simple way to do it. If you know a simple tutorial, it can help me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900