Click here to Skip to main content
11,635,098 members (76,773 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ F# DLL
Hello ,
I need some help about dlls and interoperating. The problem is that i have to call a F# dll from c++ dll and use some F# functions, but not by using COM.

I searched for some kind of solution but i didn't manage to find one. I saw something intresting about mixed dlls but as far as i understand its for managed/unmanaged c++ code (please correct me if i am wrong). I though it will be a good idea to call the F# functions from c# dll (its way too easy), but the problem still remains (calling the functions from the new c# dll into the c++ dll)

My question is can you help me with ideas what i can do to be able to use few of the F# functions in the F# dll in my c++ project.

Thanks for your help Smile | :)
Posted 11-Sep-12 23:55pm
Argonia11.5K

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Argonia -

Hello, this is my first attempt to answer a codeproject question. I would have liked to add pictures, but I will try to guide you the best I can.

In Visual Studio (I am using VS2010), Right Click on your C++ project and select the Properties menu item. Under Configuration Properties add Common Language Runtime Support by selecting Common Language Runtime Support(/clr) from the Common Language Runtime Support dropdown. Under Common Properties there is an "Add New Reference" button. Press this button and select the C# or F# project you would like to use.

In your C++ code add the following line
using namespace <the namespace of your .net project>;
e.g.
using namespace TestLib;

I declared a static function in my Test class, so my call looks like
Test::SayHello();
If you would like to call a member function you can use the following:
Test^ test = gcnew Test;
test->MemberSayHello();
  Permalink  
v3
Comments
Mattias Högström at 12-Sep-12 15:12pm
   
The F# language is a managed language.
You must call it from managed or mixed code (or call it from COM)

Solution 1, suggested by Cdrake.
1. Convert your C++ app to C++/CLI (/clr switch)

Another option is:
2. Create an interop assembly/DLL in C++/CLI which you use as a normal DLL from your C++
Argonia at 14-Sep-12 9:09am
   
Now i just have to find suitable types in c++ which can hold values from the types in f# :'(

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

  Print Answers RSS
0 OriginalGriff 8,736
1 Sergey Alexandrovich Kryukov 8,419
2 Mika Wendelius 6,845
3 F-ES Sitecore 2,354
4 Suvendu Shekhar Giri 2,205


Advertise | Privacy | Mobile
Web04 | 2.8.150728.1 | Last Updated 12 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100