How to call .dll without header file

14 vues (au cours des 30 derniers jours)
Kiruthika
Kiruthika le 7 Mai 2025
Commenté : Kiruthika le 8 Mai 2025
DLL is generated from C# code. So there's no header file. I want to call this dll from matlab.
Loadlibrary requiries .h file which is not available in my case. What is the best way to run the dll from matlab.?

Réponse acceptée

Walter Roberson
Walter Roberson le 7 Mai 2025
The header files is necessary for identifying function "signatures" -- knowing what datatype each function parameter is.
So the answer is "You don't call a C# dll without a header file. Write the header file yourself if need be.
The main alternative is to create the C# as a .NET assembly and use https://www.mathworks.com/help/matlab/ref/net.addassembly.html
  1 commentaire
Kiruthika
Kiruthika le 8 Mai 2025
Hi Walter,
Thanks for replying. I used addassembly. It loads the all the structures, classes, etc. How do I call the methods from the dll.?
I'm not very clear on how to instantiate the class and use it. Attached the screenshot of the workspace after running addassembly and the c# code.
I'm trying to connect to http link. Any leads will be appreciated.
Thanks.

Connectez-vous pour commenter.

Plus de réponses (1)

TED MOSBY
TED MOSBY le 7 Mai 2025
Hi Kiruthika,
Loadlibrary is only for native (un‑managed) DLLs. A DLL that comes from C# is managed code—a .NET assembly—so you should use MATLAB’s built‑in .NET interface instead of loadlibrary.
dllPath = fullfile('C:\path\to','MyDotNetLib.dll');
asmInfo = NET.addAssembly(dllPath);
Here's a link to the above MATLAB function: https://www.mathworks.com/help/matlab/ref/net.addassembly.html
Hope ths helps!

Catégories

En savoir plus sur MATLAB Compiler SDK dans Help Center et File Exchange

Produits


Version

R2006a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by