|
|
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » Linking to a .net DLL ?
Linking to a .net DLL ? [message #33346] |
Tue, 26 July 2011 22:43  |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Can't find anything on this when I search these fora.
I would like to be able to use some functionality which is proprietary and only available as .net
My colleague can get what I want to compile into a DLL but I am wondering how I then can use that DLL in UPP.
Cheers,
Nick
|
|
|
|
|
Re: Linking to a .net DLL ? [message #33370 is a reply to message #33368] |
Thu, 28 July 2011 23:12   |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Hey Koldo,
Should this work for a .NET compiled DLL? I am trying the following
AgiRadar::AgiRadar()
{
// connecting to .net DLL to use the following functions
// Public Shared Function testFunc1() As Integer
// Return 123
// End Function
// Public Shared Function testFunc2(ByVal x As Double) As Double
// Return x * x
// End Function
Dl turbineSpeedCalc;
String myDllFolder = "D:\\temp\\test\\Debug\\";
/////////////////////////////////////////
double (*testFunc2)(double);
if (!turbineSpeedCalc.Load(AppendFileName(myDllFolder, "turbineSpeedCalc.dll")))
throw Exc(Format(t_("% dll not found"), "turbineSpeedCalc"));
testFunc2 = (double (*)(double))turbineSpeedCalc.GetFunction("testFunc2");
if (!testFunc2)
throw Exc(Format(t_("Function %s was not found in dll"), "testFunc2"));
double argOut = testFunc2(15.0);
String s = Format("answer is %f",argOut);
PromptOK(s);
//////////////////////////////////////////
int (*testFunc1)();
if (!turbineSpeedCalc.Load(AppendFileName(myDllFolder, "turbineSpeedCalc.dll")))
throw Exc(Format(t_("% dll not found"), "turbineSpeedCalc"));
testFunc1 = (int (*)())turbineSpeedCalc.GetFunction("testFunc1");
if (!testFunc1)
throw Exc(Format(t_("Function %s was not found in dll"), "testFunc1"));
double argOut2 = testFunc1();
s = Format("answer is %f",argOut2);
PromptOK(s);
}
is there a way to list the functions available in a DLL? I figure if I can get these simple functions to work then I should be able to pass structs and arrays to real functions.
It successfully finds and loads the DLL but fails to find either function.
Cheers,
Nick
[Updated on: Thu, 28 July 2011 23:14] Report message to a moderator
|
|
|
|
|
Re: Linking to a .net DLL ? [message #33400 is a reply to message #33398] |
Mon, 01 August 2011 00:51   |
nixnixnix
Messages: 415 Registered: February 2007 Location: Kelowna, British Columbia
|
Senior Member |
|
|
Thanks.
Dependency walker does not see any functions in the DLL so am thinking there is something that my colleague has neglected to do that is akin to publishing the functions. I have never used DLLs before so am not really sure what am talking about. He is on vacation just now so I will have to ask him when he gets back.
Cheers,
Nick
EDIT: so I just tried linking into the DLL with MS VC++ express and a piece of code from http://support.microsoft.com/kb/953836
With some small adjustment I can trigger the function turbineSpeedCalc::testFunc1. The main difference appears to be that Functions4U allows me to access only global functions within the DLL whereas I appear to need access to a class. If I can make an instance of the class that is within the DLL then I should be able to access its functions.
[Updated on: Mon, 01 August 2011 04:08] Report message to a moderator
|
|
|
Re: Linking to a .net DLL ? [message #61558 is a reply to message #33398] |
Mon, 17 March 2025 14:25   |
JeyCi
Messages: 68 Registered: July 2020
|
Member |
|
|
Why compiling similar example, - getting
error: 'Dl' was not declared in this scope
though I have done everything like here, but cannot declare Dl Plugin; object in Upp CONSOLE_APP_MAIN.
p.s.
Details: using upp-v.13664 x32, in Console Project (with Core package in package organizer).
DLL was made from C#.NET-source:
using System;
using System.IO;
using System.Runtime.InteropServices;
using RGiesecke.DllExport;
namespace Plugins
{
public class Plugins
{ // CallingConvention.StdCall
[DllExport("OnPluginStart", CallingConvention = CallingConvention.Cdecl)]
public static bool OnPluginStart()
{
using (var file = new StreamWriter(@"c:\\pluginLog.txt", true))
{
file.WriteLine("OnPluginStart");
}
return true;
}
}
}
compiled with CMD Line:
Quote:C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /t:library /platform:x86 /r:C:\Test\UnmanagedExports\lib\net\RGiesecke.DllExport.Meta data.dll /out:C:\Plugins.dll C:\Plugins.cs
MY .dli
FN(bool, OnPluginStart,(void))
Another problem, In Upp CONSOLE_APP_MAIN with
bool nn= PLUGINS().Load();
Cout() << nn << '\n';
- getting false.
And with
bool retval= PLUGINS().Load("C:\\Plugins.dll");
- Upp CONSOLE_APP_MAIN crashes
P.P.S.
Sorry, if am not right posting to this topic - just my problem seemed to be simply another problem under the same title...
Best regards.
[Updated on: Mon, 17 March 2025 19:56] Report message to a moderator
|
|
|
|
Re: Linking to a .net DLL ? [message #61561 is a reply to message #61560] |
Mon, 17 March 2025 18:23   |
JeyCi
Messages: 68 Registered: July 2020
|
Member |
|
|
Koldo, thanks for your appointment where can I find class Dl, but I looked it through and I am not sure that I need to include it in my_app in general. Anyway, what do you think - if I have already
#define dllFILENAME "C:\\Plugins.dll"
#define DLIMODULE PLUGINS
#define DLIHEADER <my_use_DLL_cs/Plugins.dli>
#define dllCALL LNPUBLIC
then, as I understand, I don't need to put dll_path to T_PLUGINS::Load() once again, because it is already defined by #define-macros, I think. But why could this
bool n= PLUGINS().Load();
Cout() << n << '\n';
PLUGINS().Force();
give false to Console ?? - I cannot load my dll PLUGINS().OnPluginStart() at all in
if (PLUGINS().Load())
{
bool MSG = PLUGINS().Load().OnPluginStart();
LOG(MSG);
Cout() << MSG << '\n';
}
with error
Quote:error: request for member 'OnPluginStart' in '(& PLUGINS())->T_PLUGINS::Load()', which is of non-class type 'bool'
Can it be due to twice-calling Load() ?? how to avoid it (if need) ? Anyway,just PLUGINS().Load(); seems to be not working - with PLUGINS().Load("C:\\Plugins.dll"); crashes here, without path given as argument - results false of Load()-method usage.
Best regards.
[Updated on: Mon, 17 March 2025 18:50] Report message to a moderator
|
|
|
Re: Linking to a .net DLL ? [message #61562 is a reply to message #61561] |
Mon, 17 March 2025 18:55  |
JeyCi
Messages: 68 Registered: July 2020
|
Member |
|
|
Ok, I see in Core/dli.h
DLLTYPE& DLIMODULE()
{
DLLTYPE& out = COMBINE(DLIMODULE, _)();
out.Load();
return out;
}
therefore I just use
bool n= PLUGINS();
Cout() << n << '\n';
- result is false.
Koldo, SORRY Works
- result is true.
Still
CONSOLE_APP_MAIN
{
StdLogSetup(LOG_COUT|LOG_FILE);
{
bool n= PLUGINS;
Cout() << n << '\n';
//DLOG(AsString(n));
}
{
bool (*testFunc2)();
testFunc2 = (bool (*)())PLUGINS().OnPluginStart;
Cout() << Value(*testFunc2) << '\n';
}
if (PLUGINS)
{
bool MSG = PLUGINS().OnPluginStart();
//LOG(MSG);
Cout() << MSG << '\n';
}
}
- returns
Quote:true
false
without creating "c:\\pluginLog.txt" in dll's function OnPluginStart exported ...
p.s. added archive with .net-recompiled dll ( with CallingConvention.Cdecl to avoid doing anything with mangled name for the export function)
-
Attachment: Plugins.zip
(Size: 1.50KB, Downloaded 35 times)
Best regards.
[Updated on: Tue, 18 March 2025 12:17] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Jun 01 19:55:28 CEST 2025
Total time taken to generate the page: 0.02820 seconds
|
|
|