Forum > Packages and Libraries
.NET Libraries Loading from native application
MaxM74:
is there a way to use a library written in .NET from an application written in lazarus/fpc?
I downloaded and looked at this Bridge library written in c++, so theoretically it is possible to do it from pascal too.
https://www.codeproject.com/Articles/42319/Using-NET-Classes-Modules-from-Native-Cplusplus
I didn't find anything written in fpc or delphi
Thaddy:
It is possible, though not recommended in more than one way.
The easiest way is to treat the .net libraries as COM: they usually contain a type library.
This works on Windows, I never even tried to use that with mono on linux.
There are examples here on this forum that do it the hard way.
Also have a look at p/invoke and/or mkbundle that both creates libraries that freepascal can use.
(if I need C#, I tend to write everything in C#)
d2010:
Hello
I found two parallel routines
--- Code: ---#include "StdAfx.h"
#include "ManagedProxy.h"
//Here is C++ inside ManagedProxy.cpp
using namespace System;
using namespace System::Runtime::InteropServices;
using namespace System::Reflection;
--- End code ---
--- Code: ---using System;
using System.Text;
using System.Diagnostics;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.IO;
Here is C#
[CommandMethod("samp32")]
public static void samp32()
{
_AcEd.Editor ed = _AcAp.Application.DocumentManager.MdiActiveDocument.Editor;
try
{
Bricscad.Windows.OpenFileDialog dlg =
new Bricscad.Windows.OpenFileDialog("Test", "Drawing", "dwg", "Bricscad File Nav",
_AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowAnyExtension |
_AcWnd.OpenFileDialog.OpenFileDialogFlags.AllowMultiple);
if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
foreach (String file in dlg.GetFilenames())
ed.WriteMessage(file);
}
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
}
--- End code ---
Solution01 , ;D
step00=you start any app.cpp.exe with NativeToManagedBridge.dll
step01=you extract all DLL.names. files from NativeToManagedBridge.dll
step02=you search all 'dll.names outoff C# from step01
you extract all 'DLL.names inside C++ from step01
step03=You write sample MINICALL.LPI OR MINICALL.DPR (e.g consoleapp)
step04=You load all 'DLL from step02 but inside C++
Cele mai frumoase rugăciuni ale Pr. Arsenie Boca. Multumesc.
Anyone can remaster source ..
Thank you.
Thaddy:
I found some good answers here later:
Ask this to DeepSeek.com ....:
"can you point me the directions to use libraries written in C#/Mono in Freepascal?"
Came up with pretty much the same as I wrote already... :P
But with working - well, slight mods needed - example code.
gidesa:
Hello,
a FPC program can use a C# DLL in these cases:
- as said from Thaddy, the C# DLL exports COM (activeX) classes, and you are on Windows (it's possible
also to use COM Dll not previously registered with regsvr32)
- the C# library exports C-style functions.
There is also a very old unit from Jedi project, called JclDotNet.pas, to call directly Net functions
inside an assembly.
See here:
https://adamjohnston.me/delphi-dotnet-interop-with-jvcl/
Navigation
[0] Message Index
[#] Next page