Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently December 23rd, 2024, 7:35 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Writing a DLL
PostPosted: May 15th, 2007, 7:38 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Have followed some online instructions to create a DLL using C# and a Console Application to call DLL's function. This works fine. However, when I try to call it in Opus, I get nothing.

I'm calling the Add function
Code:
using System;

namespace mcMath
{

    /// <summary>
    /// Summary description for Class1.
    /// </summary>
    public class mcMathComp
    {
        private bool bTest = false;

        public mcMathComp()
        {
            // TODO: Add constructor logic here
        }

        /// <summary>
        /// //This is a test method
        /// </summary>
        public void mcTestMethod()
        { }

        public long Add(long val1, long val2)
        {
            return val1 + val2;
        }

        /// <summary>
        /// //This is a test property
        /// </summary>
        public bool Extra
        {
            get
            {
                return bTest;
            }
            set
            {
                bTest = Extra;
            }
        }
    }
}


Can anybody point me in the right direction. It's not a major concern, but I would like to get to grips with this new Opus function.

Cheers

Mack


You do not have the required permissions to view the files attached to this post.

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 15th, 2007, 9:44 pm 
Offline

Joined: November 11th, 2004, 4:05 am
Posts: 636
Location: Christchurch, NZ
I'm not familiar with managed code environments like C# and what code is put into the project automatically, but have you exported the function to make it available outside the dll?

when I use an exported function viewer on your dll and DW's sample dll, I can see an exported function list in DW's example but not in yours.

Now DW have put this DLL functionality in, I'll have to dig out my dusty copy of Visual Studio :)

Paul


Top
 Profile  
 
 Post subject:
PostPosted: May 15th, 2007, 10:35 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Mack,
If the DLL is called mcMath.dll and it's in the windows\system32 directory, create a function in a script to call it as follows:-, then attach the function to a button to add the two numbers. The result will be put in the pub variable AddNumbers

Code:
function Add(Number1,Number2)
{
   MyDLL=LoadDLL(SYSTEM_WINSYS_DIR+"mcMath.dll")
   if(MyDLL)
   {
      AddNumbers=MyDLL.CallFn("Add","false","slong","slong",Number1,"slong",Number2)
      }

   else
   {
      Debug.trace("DLL not loaded")
   }
}


I think the syntax of the call is OK, but without the DLL to try I can't guarantee
Add :-is the exported function in the DLL
false:- because you aren't using the display user interface
slong:-is the type of the returned value...could be ulong
slong:-is the type of the first parameter passed(Number 1)
Number1:-the first parameter
slong:-the type of the second parameter
Number2:the second parametrer.

let me know how you get on.
How did you compile the C# class?? I normally use the command line compiler csc.exe.

Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 15th, 2007, 10:49 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Sandyn,

The DLL is attached in the first post, if that's any help.

I tried hacking the example publication that DW included, but will use your code and see if it works :-)

Mack

P.S Compiled in MS C# Express

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 15th, 2007, 11:11 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Hi Mack,
The only way I have used DLL support is with a DLL. I think that's the only way of calling it from Opus??
Need to find how to create mcMath.DLL from the C# code.
I will try compiling a library class from C# to see if it produces a DLL??
I had a look on the web, but as usual, it tells you everything, except what you want to know!!

Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 15th, 2007, 11:47 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Sandyn,

I've also looked into Paul's suggestion and there aren't any exported functions in the DLL. My C# and understanding of DLLs is not enough to know if this is significant or how to modify the the code to solve this.

It seems odd that I can create a console application to access the DLL, but not do it in Opus.

Any help welcome :-)

Mack,

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 15th, 2007, 11:59 pm 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
I was trying to find how to create the mcMath.DLL form the code. I tried compiling the *.cs file, to see if it would produce the DLL, but nothing. Once we figure out how to create the DLL, then the exported function will be Add.
I was wondering if there is any benefit in producing a DLL anyway??. So you produce a DLL that you can call from Opus?? why not just add the functionality to Opus. I suppose it keeps the Opus code smaller, but you still have to include the DLL, then put it in the right directory...etc.
The only benefit I see in using DLL support with Opus is to use common code already on the users machine from windows. But I would still like to find out how to do it from C#

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 16th, 2007, 12:12 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Sorry, I wasn't logged in and didn't see the DLL attached, just the code.
I tried looking at the DLL with PE expolrer and also found there is no exported function. I tried it in Opus and it didn't work.

Sandy

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 16th, 2007, 12:49 am 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
I'm not a C# expert (C++ is my thing!), but I think you're creating .NET managed code, not native Win32 code. You can't call managed code from unmanaged (i.e. normal executables); so your managed test app can use your DLL, but no Win32 application can. You'll need to create a standard Win32 DLL with exported functions - which may not be possible in C#. VP, C++, Delphi and others can do this.

_________________
ddww Opus Developer


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 16th, 2007, 3:35 am 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Sorry for my stupid question ,but I'd like to know about DLL.
My question:
Why do we need a DLL when we can write functions in the Opus script?
Is it a matter of sharing with other programes or what is the story?


Top
 Profile  
 
 Post subject:
PostPosted: May 16th, 2007, 7:39 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Hi Duncan,

That seems to be the thinking that I've discovered reading through the web. It may still be possible, but looks a little complicated.

Does anyone have any code to create a basic DLL in any form of C, that we beginners could look at?

Hi OpusLover, there are a lot of reasons for using DLLs. Reading through post suggests that a lot of people would like to interface with external hardware.

I'm starting small, and want to create a DLL that contains a few functions that aren't available via OpusScript / JavaScript. If I ever, get the DLL created, I'll uploaded and you can have a play and see the practicalities.

Mack,

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 16th, 2007, 8:04 am 
Offline

Joined: November 25th, 2004, 1:24 pm
Posts: 512
Location: Scotland
Opus: 9.75
OS: Win 10
System: Asus i7-7700K 16Gb
Hi Opuslover,

To clarify a bit more, the discussion is really in two parts:-

1 Using DLLs with Opus
2 Creating DLLs

So...

1. Using Opus you can now call DLL functions---if you know what's in them.
This allows you to talk to hardware and use windows code which already exists

2 Opus does not create DLLs, you use other software to create a DLL. This would be useful as Mack says to add additional functionality to Opus.


The point to be noted is that with DLL support, it opens up all kinds of new possibilities.

_________________
Whoever designed this, never actually used it!


Top
 Profile  
 
 Post subject:
PostPosted: May 16th, 2007, 11:30 am 
Offline

Joined: October 26th, 2004, 10:23 am
Posts: 666
Location: Digital Workshop
opuslover wrote:
Why do we need a DLL when we can write functions in the Opus script?
Is it a matter of sharing with other programes or what is the story?

The ability to call functions in DLLs is an advanced feature for situations where it is not possible to achieve a solution from within OpusScript or actions. Mainly it is useful for getting information in or out to some device or system that is not connected directly to Opus.

The supplied sample, for example, allows you to obtain information from a user (a colour) using a standard system interface without having to re-implement it directly in Opus. As others are doing, you could use it to read or control specific hardware.

Basically it is a way for people to access other software from Opus. The majority of users are unlikely to need it, but for those doing something out of the ordinary, it can provide a solution.

_________________
ddww Opus Developer


Top
 Profile Visit website  
 
 Post subject:
PostPosted: May 16th, 2007, 1:42 pm 
Offline

Joined: September 11th, 2006, 2:38 pm
Posts: 125
Really No more words to say

Thanks all ....

But for us as Dll's Idiots we need someone to lead us to Dll's World.

Please if anyone has information about using DLL with Opus SHARE'm
here to Help US.


Top
 Profile  
 
 Post subject:
PostPosted: May 16th, 2007, 7:15 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
UPDATE!!!

It seems the folk who wandered about the lack of viewable exports from a C# DLL were heading in the right direction. As far as I can tell, (thanks here to DW for pointing the way) because C# is a managed language and Opus is created in an unmanaged language(C++?), C# DLLs can't be used as is.

However, it is possible to disassemble a C# DLL in MSIL and edit the source to make the functions usable in unmanaged languages such as C++. Having at last managed to get the .il file to recompile it still won't display it's functions or work in Opus. :-(

Anybody with XP of this, or interested in get C# DLLs to work in Opus let me know and I'll happily exchange ideas.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 58 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group