Showing results for 
Search instead for 
Do you mean 
Reply

How do I access a function from a .NET library within a Ufunc application developed in C/C++?

I have a ufunc application and a library of methods in a .NET dll. The ufunc application needs to make a call to a function that is in the .NET dll. There is one possible way I know is to use

nx_ja_session_execute. I can create a temporary rule from my C application as shown below

 

UF_KF_value_p_t kf_value;

int int_value;

UF_KF_create_rule_no_update("Root:","my_tmp_rule","Integer","nx_ja_session_execute(\"MyDotNetLibrary.dll\",\"MyClass\",\"MyMethod\",{\"MyArg1\",\"MyArg2\"})",NULL);

UF_KF_evaluate_rule("Root:my_tmp_rule:", &kf_value);

UF_KF_ask_integer(kf_value, &int_value);

UF_KF_remove_rule_only("Root:","my_tmp_rule");

 

This approach will only work if there is an active part in the session as KF environment doesn't work on a empty session. There are other limitations to it as well.

 

I then thought, I can develope a warpper dll using managed C++ which will act as a layer between my C application and .NET dll. My thought is to have wrapper functions (in C style and exposed) inside managed cpp wrapper dll which would call methods from .NET dll and my C application would call these wrapper functions from managed cpp dll. 

 

This is my managed wrapper looks like

extern __declspec(dllexport) int MyMethod(char* _MyArg1, char* _MyArg2)

{

String^ MyArg1 = gcnew String(_MyArg1);

String^ MyArg1 = gcnew String(_MyArg1);

return MyDotNetLibrary:MyClass::MyMethod(MyArg1,MyArg1);

}

 

This is how my C application code looks like

int ret_val;

ret_val = MyMethod("Arg1 Value","Arg2 Value");

 

 

My C application is able to trigger the wrapper functions from managed cpp library, but managed cpp function is failing to trigger method from .NET dll as NX is not loading. How do I make this work? Appreciate your help.