Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
3.33/5 (3 votes)
See more:
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 :)
Posted

1 solution

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.
C++
using namespace TestLib;


I declared a static function in my Test class, so my call looks like
C++
Test::SayHello();

If you would like to call a member function you can use the following:
C#
Test^ test = gcnew Test;
test->MemberSayHello();
 
Share this answer
 
v3
Comments
Mattias Högström 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 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900