5.0

5.0 | 2 ratings Rate this file 24 Downloads (last 30 days) File Size: 526.82 KB File ID: #24261

How to load / call functions from a VB DLL

by Gordon

 

26 May 2009

A brief overview on how to create a DLL in VB .Net which can be used from within Matlab.

| Watch this File

File Information
Description

A brief overview on how to create a DLL (Dynamically Linked Library) in VB (Visual Basic) .Net which can be used from within Matlab. This is done using the actxserver command. One needs to use an approach like this instead of using the "loadlibrary" command, as one does not have the appropriate header file.
Hopefully this will provide a starting point for people like me who need some indication on where to start.

the zip contains:
- Step By Step Instructions in a PDF Document
- A Visual Studio 2008 VB.net DLL (Class) Project
- A Matlab file which shows how to call functions from the VB Dll, once it's been created
 
(I did this With Visual Studio 2008, and Matlab 2009a, but it should work with older versions too)

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Using C# functions and forms in Matlab

MATLAB release MATLAB 7.8 (R2009a)
Other requirements .Net Framework version 2 Visual Studio .Net
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
04 Aug 2009 Miguel Couto

I did what u told and it works! Great! Thanks.
Do you know how to use the object's methods in Simulink?

07 Aug 2009 Miguel Couto

Ok, now I've got the answer to my previous question. Each object's display method is assigned to a matlab function (m-file), then the call from simulink is made using the block "MATLAB Function". That's it, so easy.

But, I'm still thinking about those COM objects...how to start a xserver in C s-function and then use the object's methods? Is this senseless??

What if the dll was made in C++, was it easier to use the library in simulink s-functions?

28 Nov 2011 Jonathan

I tried this and had no success. It seems that (at least in 2011 versions), that when registering the file using regasm.exe, it is necessary to use the /codebase option. For example using the Windows command prompt (run as administrator) from the directory that the file is located):

c:\...\...\>c:\windows\microsoft.net\framework\v4.0.30319\regasm.exe VB_Dll_Demo.dll /codebase

Under the 64 bit version of Matlab, do the same thing except use framework64 instead of framework:

c:\...\...>c:\windows\microsoft.net\framework64\v4.0.30319\regasm.exe VB_Dll_Demo.dll /codebase

I used .net framework 4.0 and compiled as "anycpu", selecting "register for COM interop". It warned that the name wasn't strong when I ran regasm so the .dll should be signed to avoid problems.

20 Feb 2012 Keiko  
Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
vb Gordon 26 May 2009 12:36:54
visual basic Gordon 26 May 2009 12:36:54
dll Gordon 26 May 2009 12:36:54
matlab Gordon 26 May 2009 12:36:54
function Gordon 26 May 2009 12:36:54
dynamic Gordon 26 May 2009 12:36:54
activexserver Gordon 26 May 2009 12:36:54
library Gordon 26 May 2009 12:36:54
loadlibrary Gordon 26 May 2009 12:36:54
linked Gordon 26 May 2009 12:36:54
com Miguel Couto 07 Aug 2009 12:59:28
function ben22240 08 Aug 2011 16:30:00

Contact us at files@mathworks.com