Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2014-01

Load .NET dll (or bootstrap CLR to be precise) from FPC

10 messages · 6 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

leledumbo

I'm writing a web app hosting several tasks in FPC, however one of the task is calling a function residing in a .NET dll. I've made a flat C interface for the dll (so that I can call it from FPC easily), and it works just fine IF the dll is somehow loaded first. Currently, I use a trick to debug my web app from Visual Studio and makes the app calls the dll function. This automatically bootstraps the CLR and as long as there's no update on the dll my app would stay working. However, this is of course cumbersome. I wonder if there's any way to load the dll without such a dirty trick.

View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Load-NET-dll-or-bootstrap-CLR-to-be-precise-from-FPC-tp5717880.html Sent from the Free Pascal - General mailing list .
Mark Morgan Lloyd
to leledumbo
leledumbo wrote 8 lines
I'm writing a web app hosting several tasks in FPC, however one of the task is calling a function residing in a .NET dll. I've made a flat C interface for the dll (so that I can call it from FPC easily), and it works just fine IF the dll is somehow loaded first. Currently, I use a trick to debug my web app from Visual Studio and makes the app calls the dll function. This automatically bootstraps the CLR and as long as there's no update on the dll my app would stay working. However, this is of course cumbersome. I wonder if there's any way to load the dll without such a dirty trick.

Nasty. Presumably the .dll wants to invoke entry points in the calling program: I don't know whether you can work around that and you might end up having to do something like http://www.mono-project.com/Embedding_Mono

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Dmitry Boyarintsev
to leledumbo: I'm writing a web app hosting several tasks in FPC, however one of the task is calling a…
leledumbo wrote 5 lines
I'm writing a web app hosting several tasks in FPC, however one of the task is calling a function residing in a .NET dll. I've made a flat C interface for the dll (so that I can call it from FPC easily), and it works just fine...

For the same task, I typically create .NET executable that would use the .NET dll and call the executable from FPC code. No hacks - no worries.

thanks,
Dmitry

Sven Barth
to leledumbo: I'm writing a web app hosting several tasks in FPC, however one of the task is calling a…
"leledumbo" wrote
I'm writing a web app hosting several tasks in FPC, however one of the

task

is calling a function residing in a .NET dll. I've made a flat C interface for the dll (so that I can call it from FPC easily), and it works just

fine

IF the dll is somehow loaded first. Currently, I use a trick to debug my

web

app from Visual Studio and makes the app calls the dll function. This automatically bootstraps the CLR and as long as there's no update on the

dll

my app would stay working. However, this is of course cumbersome. I wonder if there's any way to load the dll without such a dirty trick.

There are basically two possibilities: adjust the .Net assembly to be hosted as a COM server, generate a TLB and use that to generate a interface unit for FPC. Please ask Google or the search engine of your choice for the first two steps.

The other possibility is to host the .Net runtime in your application. For this you can take a look at these links:
http://www.codeproject.com/Articles/416471/CLR-Hosting-Customizing-the-CLR http://code.msdn.microsoft.com/windowsdesktop/CppHostCLR-e6581ee0 The CLRCreateInstance function seems to be defined in mscoree.dll, so you'll need to import that.

I've not done this myself yet, but I hope it helps you.

Regards,
Sven

Michael Van Canneyt
to Sven Barth
Sven Barth wrote 22 lines
Am 10.01.2014 08:19 schrieb "leledumbo" : > > I'm writing a web app hosting several tasks in FPC, however one of the task > is calling a function residing in a .NET dll. I've made a flat C interface > for the dll (so that I can call it from FPC easily), and it works just fine > IF the dll is somehow loaded first. Currently, I use a trick to debug my web > app from Visual Studio and makes the app calls the dll function. This > automatically bootstraps the CLR and as long as there's no update on the dll > my app would stay working. However, this is of course cumbersome. I wonder > if there's any way to load the dll without such a dirty trick. > There are basically two possibilities: adjust the .Net assembly to be hosted as a COM server, generate a TLB and use that to generate a interface unit for FPC. Please ask Google or the search engine of your choice for the first two steps. The other possibility is to host the .Net runtime in your application. For this you can take a look at these links: http://www.codeproject.com/Articles/416471/CLR-Hosting-Customizing-the-CLR http://code.msdn.microsoft.com/windowsdesktop/CppHostCLR-e6581ee0 The CLRCreateInstance function seems to be defined in mscoree.dll, so you'll need to import that. I've not done this myself yet, but I hope it helps you.

The CrossTalk project for Delphi automates this latter task for you. It also imports .NET assemblies. Maybe we can ask if it would work with FPC.

Michael.

leledumbo
to Dmitry Boyarintsev: For the same task, I typically create .NET executable that would use the .NET dll and…
For the same task, I typically create .NET executable that would use the

.NET dll and call the executable from FPC code. No hacks - no worries

This could be possible, maybe just with a little delay. This is the only task that uses .NET dll, the others are pure FPC. I'll consider it, good idea.

leledumbo
to Sven Barth: task fine web dll There are basically two possibilities: adjust the .Net assembly to be…

COM server... I thought I've read that somewhere, I'll search again.

The code to host .NET runtime seems plenty, but quite possible. I'll try to make a good use of those links.

leledumbo
to Michael Van Canneyt: The CrossTalk project for Delphi automates this latter task for you. It also imports .NET…

This seems to be the best solution, though a proprietary one. I don't think my office would like to buy, especially since the price is somewhat shocking :p