Main Restorations Software Audio/Jukebox/MP3 Everything Else Buy/Sell/Trade
Project Announcements Monitor/Video GroovyMAME Merit/JVL Touchscreen Meet Up Retail Vendors
Driving & Racing Woodworking Software Support Forums Consoles Project Arcade Reviews
Automated Projects Artwork Frontend Support Forums Pinball Forum Discussion Old Boards
Raspberry Pi & Dev Board controls.dat Linux Miscellaneous Arcade Wiki Discussion Old Archives
Lightguns Arcade1Up Try the site in https mode Site News

Unread posts | New Replies | Recent posts | Rules | Chatroom | Wiki | File Repository | RSS | Submit news

  

Author Topic: Plugins: A Little wrapper for dynamic loading (Please Lock, no need)  (Read 3674 times)

0 Members and 1 Guest are viewing this topic.

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
This old "SDK" system is completly removed.
But developing a new wrapper to meet the new agreed standard.

This original thread would not been deleted, but instead I renamed it and update with a new post when done (but I do not change this original post)


All info in this post is outdated.

First i using PlugMyJuke as work name (might not been the final name).

VERSION .7

Since some languages seen to have limits about retrieve info by the plug-in I have tried to create a wrapper dll, that dosent require use as a dynamic Dll at all (all functions can been defined at once). The wrapper does all the dymanic read og all plugins from a directory of your choice.

It use all functions contained from this thread:
http://forum.arcadecontrols.com/index.php?topic=75083.0




About PlugMyJuke.Dll:


There is few commands added to the PlugMyJuke.Dll which you can use:

total=Load_Plugins(path$)
This tell the wrapper to read all other plugins one by one using a path where the plug-in contain. I return a value with a total number of plugs loaded. By now it reading both Dall and pmj extensions (which is a renamed extension, later i only use the winning name).

length=StringLength()
The length of the last result string after invoked a string respons command.

StringCopy(StringPointer)
Copy the result string into this memory adress (pointer). Make sure you create spaces with the length of the stringlength() command before using this command.

pointer=StringPointer()
Return a integer pointer where there string is after invoked a string repons command. Remember to copy it to a another string in your applcation, if you use this command.



All other functions remain the same from the list, but there are one exception that is needed by all functions:
- You need to add PluginNumber argument that tell the wrapper which plug-in it should sending the function to.

Examles:
Juke_Initialize() whould been Juke_Initialize(PluginNumber)
Juke_GetPluginInfo() whould been Juke_GetPluginInfo(PluginNumber, value$)


- All functions also return a value that tell if the function sendt was a succes or not. It can returned one of these value:
0 = did not found the dll number
1 = succes
-1 = found the plugin, but not the function


For strings it either return the whole content or a emtpy string if failed or other reason.




Example plugin:


There is also a example plugin that contain all functions that is corretly in the functions list by the other thread. I do now not touch the exists commands in the while, but might still add new commands.

Its called it messages, because it just show a message requster as succes and some strings returned on returned string commands. I hope that going to work, since I also got some trouble to get around some limits (as headkaze and other told).

Plugin Writers:
Make sure to use a global function to the strings that need to been returned by these 3 functions. Otherwice it might been gone, and result a memory invaild message instead.




Example host:


A example host is in the file as well, but only constain the souce code for it, made in BlitzMax (hence I called that name). It should been very clear how I succesful connected to PlugMyJuke.Dll in the none dynamic method (which is meant by this dll).

Beware some language might check if the string was returned as a pointer, but it should do automatich by all language that does not have manual check like c++.

All strings returned here 8 bit, but it might constain UTF8 tags, if your jukebox application support unicode.



I hope it now got to work with Visual Basic (which have same limits as BlitzMax), includning these that require getting a string from the plugin !! The last one is why I tried making this little main dll, which also include the source code in Pure Basic as well.

Debate + help: http://forum.arcadecontrols.com/index.php?topic=75010.0
Choose a name: http://forum.arcadecontrols.com/index.php?topic=75132.0
« Last Edit: January 11, 2008, 01:23:44 am by Space Fractal »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
Re: Plugins: Starting a little SDK with a main dll
« Reply #1 on: January 06, 2008, 08:40:25 am »
Updated the SDK to sync to the new command changes in the list.

I have also included *.lib files for those who need to use this to import the dll commands using that.



Updated again to suit the min and max values to the volume command.

NB. If the PlugMyJuke.dll (normal format) dosent work, try PlugMyJukeC.dll (CDecl format).
« Last Edit: January 07, 2008, 02:24:51 am by Space Fractal »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.

headkaze

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2943
  • Last login:August 14, 2023, 02:00:48 am
  • 0x2b|~0x2b?
Re: Plugins: Starting a little SDK with a main dll
« Reply #2 on: January 06, 2008, 10:13:16 am »
Are any of the other Jukebox coders going to use your plugin wrapper dll? If not it would be a waste of time. I notice there is only one download so far, is anyone else taking a look at this?

Personally I think it's a good idea since VB6 has some major issues with dynamic dll's, but the problem is you write this wrapper in a language noone else here uses. What happens if you go AWOL and the plugin wrapper needs to be updated? Having a dll wrapper means there is an extra depandancy (and programmer) to rely on.

I think you should make sure you have the other coders onboard with this before committing to it. They may infact want to stay using the hack method in VB6. It's a horrible limitation I know but they may find it easier to implement.

Also some things of note. Does your wrapper export your functions using stdcall? VB6 cannot support cdecl calls. You really need to include a VB6 example for using the wrapper because the other two Juke coders we know both write in VB6.

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
Re: Plugins: Starting a little SDK with a main dll
« Reply #3 on: January 06, 2008, 11:08:48 am »
I have same limits in BlitzMax, hence i was needed to write it anyway, before I can use it in MultiJuke. I just dedicated to share it with other jukebox authors if they want to use the same dll I use.

Let me know if the dll actuelly work in Visual Basic. I have added a another file with the another call method. One of them should works with Visual Basic. Let mw known which one that hopefully works.

Of course I include various language examples when I got it, or they could simple show here.

Elsewice there is a demo of PureBasic on http://www.purebasic.com and is still in development.

Otherwice fell free to translate that wrapper to other language as well. The source is included.
« Last Edit: January 06, 2008, 11:25:46 am by Space Fractal »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.

headkaze

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2943
  • Last login:August 14, 2023, 02:00:48 am
  • 0x2b|~0x2b?
Re: Plugins: Starting a little SDK with a main dll
« Reply #4 on: January 06, 2008, 03:33:20 pm »
VB6 does NOT support cdecl. So no point in creating a dll with that.

I created a VB6 app to work with your wrapper and it's having trouble getting the string values from Plugin_GetPluginInfo(). I've given up, so hopefully the other VB6 programmers can finished what I've started.

I would probably go further with this, but I really dislike coding in VB6. Once you go .NET it's hard to go back to it :P

Code: [Select]
Declare Function Load_Plugins Lib "PlugMyJuke" (ByVal Path As String) As Long

Declare Function Juke_AddQueue Lib "PlugMyJuke" (ByVal File As String, ByVal SongTime As Long, ByVal Status As Long, ByVal CoverArt As String, ByVal Title As String, ByVal Artist As String, ByVal Album As String, ByVal Genre As String, ByVal Special As String) As Long

Declare Function Juke_SongTags Lib "PlugMyJuke" (ByVal PluginNumber As Long) As String

Declare Function Juke_SongSuggestion Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal File As String) As String

Declare Function Juke_SongBegin Lib "PlugMyJuke" (ByVal PluginNumber As Long) As Long

Declare Function Juke_SongEnd Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Skip As Long) As Long

Declare Function Juke_SongPlayed Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Secs As Long) As Long

Declare Function Juke_SongStatus Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Status As String) As Long

Declare Function Juke_GetPluginInfo Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Value As String) As String

Declare Function Juke_Volume Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Value As Long, ByVal Min As Long, ByVal Max As Long) As Long

Declare Function Juke_Initialize Lib "PlugMyJuke" (ByVal PluginNumber As Long) As Long

Declare Function Juke_Shutdown Lib "PlugMyJuke" (ByVal PluginNumber As Long) As Long

Declare Function Juke_LCDString Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Text As String, ByVal Line As Long) As Long

Declare Function Juke_CommandList Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Number As Long, ByVal Command As String) As Long

Declare Function Juke_CommandDisable Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Command As String) As Long

Declare Function Juke_CommandEnable Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Command As String) As Long

Declare Function Juke_CommandSend Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Command As String) As Long

Declare Function Juke_CommandGet Lib "PlugMyJuke" (ByVal PluginNumber As Long) As String

Declare Function Juke_AddCoin Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Coins As Long) As Long

Declare Function Juke_PaidCoin Lib "PlugMyJuke" (ByVal PluginNumber As Long, ByVal Coins As Long) As Long

Code: [Select]
Option Explicit

Private Sub Form_Load()
    Dim NumPlugins As Long
   
    ' Init PlugMyJuke and let its read all plugin files
    NumPlugins = Load_Plugins(App.Path & "\Plugins")
   
    ' Output the number of plugins used
    MsgBox "NumPlugins:" & NumPlugins
   
    Dim Name As String
    Dim Author As String
    Dim Version As String
   
    Dim I As Long
    ' Init All Plugins
    For I = 0 To NumPlugins - 1
        Dim RetVal As Long
       
        RetVal = Juke_Initialize(I)
       
        ' GetPlugin Info
        Name = Juke_GetPluginInfo(I, "name") ' <--- error here
        Author = Juke_GetPluginInfo(I, "author")
        Version = Juke_GetPluginInfo(I, "version")
       
        ' Print them out
        MsgBox Name & "," & Author & "," & Version
    Next I
   
    ' Try Some commands for fun
    Juke_AddCoin 0, 1
   
    ' Get a command
    Dim Command As String
    Command = Juke_CommandGet(0)
    MsgBox "Command: " & Command
End Sub
« Last Edit: January 06, 2008, 03:35:02 pm by headkaze »

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
Re: Plugins: Starting a little SDK with a main dll
« Reply #5 on: January 06, 2008, 03:57:07 pm »
Thanks.

Can VB6 use pointers?

I trying to alter the code so it return a pointer istead of a string.







« Last Edit: January 06, 2008, 04:02:10 pm by Space Fractal »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
Re: Plugins: Starting a little SDK with a main dll
« Reply #6 on: January 06, 2008, 04:19:51 pm »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.

headkaze

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2943
  • Last login:August 14, 2023, 02:00:48 am
  • 0x2b|~0x2b?
Re: Plugins: Starting a little SDK with a main dll
« Reply #7 on: January 06, 2008, 04:38:33 pm »
Thanks.

Can VB6 use pointers?

I trying to alter the code so it return a pointer istead of a string.

I don't think you can with a return value. Using parameters you can have ByRef (pointer) or ByVal (value). But you can't specify that with a value returned by a function.

This is why originally it was Plugin_GetPluginInfo(PCHAR Name, PCHAR Author, PCHAR Version), so you can copy the values into those pointers. Then in VB6 you can use (ByRef Name As String, ByRef Author As String, ByRef Version As String).

Returning a pointer might work but return values should be an integer really anyway.

Try replace String with CString..

http://www.aivosto.com/vbtips/stringopt2.html#memorylayout

That wont work, CString is a class.

You will have to return BSTR or pass the variables out through parameters. They really should come from paramters not through the return value. The return value should always be an integer (1 for success 0 for failure). They should not be used for returning a string IMHO.

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
Re: Plugins: Starting a little SDK with a main dll
« Reply #8 on: January 06, 2008, 05:01:25 pm »
I try this one. I have added a another command:

value=StringPointer() that return a integer pointer to the memory where the string is by the last response command.

Should been used after Plugin_GetPluginInfo().

I also updated the example to sync with the 2 command functions that was changed a bit.

___ removed v4 ___ se last post.
« Last Edit: January 07, 2008, 02:25:25 am by Space Fractal »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.

headkaze

  • Trade Count: (0)
  • Full Member
  • ***
  • Offline Offline
  • Posts: 2943
  • Last login:August 14, 2023, 02:00:48 am
  • 0x2b|~0x2b?
Re: Plugins: A Little wrapper dll for dynamic loading of Plugins
« Reply #9 on: January 06, 2008, 06:48:11 pm »
You will need to change this

Code: [Select]
Name$=Juke_GetPluginInfo(i, "name")
Author$=Juke_GetPluginInfo(i, "author")
Version$=Juke_GetPluginInfo(i, "version")

to this

Code: [Select]
Global sName:String
Global sAuthor:String
Global sVersionString

Local pName:Byte Ptr
Local pAuthor:Byte Ptr
Local pVersion:Byte Ptr

Local retVal:Integer

sName = "                                    " ' Make a big enough size not sure how in Blitz
sAuthor = "                                    " ' Make a big enough size not sure how in Blitz
sVersion = "                                    " ' Make a big enough size not sure how in Blitz

pName = sName.ToCString()
pAuthor = sAuthor.ToCString()
pVersion = sVersion.ToCString()

retVal = Juke_GetPluginInfo(i, pName, pAuthor, pVersion)

sName.FromCString(pName)
sAuthor.FromCString(pAuthor)
sVersion.FromCString(pVersion)

FreeMem pName
FreeMem pAuthor
FreeMem pVersion

That way we can have it working in VB6 okay as well.

Space Fractal

  • Wiki Master
  • Trade Count: (+1)
  • Full Member
  • *****
  • Offline Offline
  • Posts: 1888
  • Last login:September 26, 2023, 11:32:13 am
  • Space Fractal
    • Space Fractal
Re: Plugins: A Little wrapper dll for dynamic loading of Plugins
« Reply #10 on: January 07, 2008, 02:17:36 am »
Here is '5th version to try avoid the visual basic problem. first use the call as normal, even it dosent return a string.

Then

length=StringLength()

This detect the length of the last result string.

make a sSpace(length) in your visual basic to create some empty space, something like this:

Code: [Select]
space$=""
for i=1 to length
   space$=space$+" "
next
return space$

or a use Space() functon to create that if that exists in Vb6, I known the above could been faster.

Then use this function to copy the string to the variable:
stringCopy(pname)

To the last, Trim the string, so it dosent have some wasted space at the end.

now it should finally works with the wrapper.

hoping it dosent crash when I use memcopy (stringCopy)....

Agian PlugMyJuke is still a work name, if the name is not finally used.

Now hope it now finally works with the 2 new helper functions.

NB: I do highly recommered to create A function, that handles the returned strings.



EDIT: Updated again to version 6 to add 2 new functions that is nothing directly with plugin functions to due.

Look in the first post for the file.
« Last Edit: January 07, 2008, 06:48:29 am by Space Fractal »
Decade Old Work: MultiFE, ArcadeMusicBox
Today Works: Various Spectrum Next games from Rusty Pixels and html5 games.