Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Work in Progress / k.Net (VB.Net & C# DLLs in DarkBasic Pro)

Author
Message
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 27th Jan 2011 02:44 Edited at: 22nd May 2011 17:45

[ Current Status: Active (Internal Testing, Help Wanted) ]


Hi guys, this is a new plugin for DBPro I've been working on.

It allows VB.Net and C# DLLs to be used in DBPro without any special editing of the DLLs and without needing to open the DLLs for COM Interop, etc..
You simply open Visual Studio, make your DLL, build it and you're done

It can load any public class from your DLL, currently one at a time but if it's wanted among forum users I'll add in, multiple class loading and other better things

Included in the DLL are the plugin DLL, full keywords file, help files documenting the commands and three fully working examples with source code for the DLLs and DBPro source.

Current Project Status:
I'm currently continuing to test the plugin and I'm requesting anyone who can make VB.Net and/or C# DLLs to make a simple one like the below VB.Net code example screenshot and upload them.
I can then test them and make sure it works with everyone's DLLs.

Your DLL functions and subs can request Strings, Decimals(Floats in DBPro), Integers and Booleans, other types are not yet supported.

Tested and working with the following .Net Frameworks:
.NET Framework 2.0
.NET Framework 3.0
.NET Framework 3.5
.NET Framework 4.0 (some things do return an error, but not enough to render it unusable with .Net Framework 4.0 )

DLL creation in the following IDEs fully working:
Visual Studio 2005 (Express edition)
Visual Studio 2008 (Express & Ultimate editions)
Visual Studio 2010 (Express & Ultimate editions)

As far as I know(untested as of yet), the .NET Framework used to make the DLL will need to be installed on the end user's pc for the DLL to run.

Screenshots:[/center]
Below are examples of the stuff you need to use the plugin. It shows the VB.Net DLL code, the DBPro code and then the DBPro exe running the code.

DarkBasic Pro Code Example:


VB.Net Code Example:


DarkBasic Pro EXE Example:


P.S: I know similar to this has been done before but it required converting DLLs or opening for COM Interop, while mine doesn't.
Plus I wanted to learn how to do it so...

Frank C
13
Years of Service
User Offline
Joined: 3rd Jul 2010
Location: Houston TX
Posted: 27th Jan 2011 14:19
I'd be interested in testing this for you, I won't be able to do it for a couple weeks due to some Dev/Testing deadlines at work but I am interested.
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 27th Jan 2011 23:19
Ok, thanks Frank Let me know when you've got time available

Super Sabueso
14
Years of Service
User Offline
Joined: 10th Apr 2010
Location:
Posted: 2nd Mar 2011 00:34
im interested in test your dll, im making a dll to get the id processor, hd serial, mac address to protect a arcade game =)

Hello
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 2nd Mar 2011 01:17
Quote: "im interested in test your dll"

That's awesome, if you can send me your email address then I'll send you the DLL for you to test.
Just email me at knxrb@yahoo.co.uk.

Airslide
19
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 2nd Mar 2011 01:22 Edited at: 2nd Mar 2011 01:40
Looks very interesting. Are you calling the methods with reflection? I'm not really good with conceptualizing time so I don't know how good 9 milliseconds is for what that is doing, but I know that if you use reflection extensively the performance impact would probably show in a fast paced game.

EDIT: Attached a C# dll for you to try, Net 4.0. Source included.

Attachments

Login to view attachments
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 2nd Mar 2011 01:54
Quote: "Are you calling the methods with reflection?"

Yes, it uses some Reflection calls to process the DLLs.

Quote: "but I know that if you use reflection extensively the performance impact would probably show in a fast paced game"

As far as I've seen so far with my testing, there's been no slow down with DBPro when the calls are made and the FPS stays roughly the same. Only drops about 1-2 FPS when doing more than 50 calls a second.

Super Sabueso
14
Years of Service
User Offline
Joined: 10th Apr 2010
Location:
Posted: 2nd Mar 2011 03:30
mail sent

Hello
Airslide
19
Years of Service
User Offline
Joined: 18th Oct 2004
Location: California
Posted: 2nd Mar 2011 04:58
Quote: "As far as I've seen so far with my testing, there's been no slow down with DBPro when the calls are made and the FPS stays roughly the same. Only drops about 1-2 FPS when doing more than 50 calls a second."


It might be less of a concern considering DBP's base performance is not nearly as good as C#. And I imagine much of the talk of reflection being slow is largely irrelevant in practice and more theoretical, depending on how it is used. You see huge differences in benchmarking tests but those are usually performing an exaggerated number of calculations.
budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 7th Mar 2011 23:56 Edited at: 7th Mar 2011 23:56
Attached a VB.net 4.0 dll, with source.


Mystic-Mod: Putting the fear back into sliced bread since 4th May 2010

Attachments

Login to view attachments
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 8th Mar 2011 01:04 Edited at: 8th Mar 2011 01:21
Thanks budokaiman, I'm testing it out now
I'll post the results in about 10 minutes.

[Edit]
I've now tested it and the function 'messageBox' works perfectly.
The 'stackPush' and 'stackPop' functions wouldn't work as they required a 'Stack object' to be given which currently isn't in the supported types.

I've edited and attached the code you've sent so it works with the DLL as it is now so you can see the kind of code it currently uses.
The current approach gives you total control over any error messages you want to give back to DBPro if an error occurs.

If you could take a look at it and let me know what you think then I'd appreciate it

For support for other types, if there's enough interest in this plugin then I'll add integrated support for object arguments like Stacks and other Arrays, etc.

Attachments

Login to view attachments
budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 8th Mar 2011 15:44
Quote: "If you could take a look at it and let me know what you think then I'd appreciate it"


I think that would work just the same thing, but would require declaring variables with the stack name, and number, in order to keep it organized.

Quote: "I've now tested it and the function 'messageBox' works perfectly."

I'll assume then, the runMethod function in your dll can parse more than just the function name and 2 values, like you have shown in your screenshot.

Quote: "For support for other types, if there's enough interest in this plugin then I'll add integrated support for object arguments like Stacks and other Arrays, etc."

I could see that being useful for other functions as well, but that's just my opinion. I'm sure there are workarounds to using them, like you did.


Mystic-Mod: Putting the fear back into sliced bread since 4th May 2010
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 8th Mar 2011 15:51
Quote: "I think that would work just the same thing, but would require declaring variables with the stack name, and number, in order to keep it organized."

Yes, that's possible and would make it easy to organise, the example I coded does similar but it uses a number for each Stack.
If the coder remembers which number is for which Stack then they could use it like that, or edit it so it uses easy to remember names.

Quote: "I'll assume then, the runMethod function in your dll can parse more than just the function name and 2 values, like you have shown in your screenshot."

Yes it does, I've not yet tested how many can be sent in one call but in my tests so far I've had 4 working perfectly.

budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 8th Mar 2011 16:01
Quote: "Yes it does, I've not yet tested how many can be sent in one call but in my tests so far I've had 4 working perfectly."

I'll try to get an example of one that uses a large amount of values. I'll make another dll later, containing more useful functions for you to test too.


Mystic-Mod: Putting the fear back into sliced bread since 4th May 2010
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 8th Mar 2011 16:06
Quote: "I'll make another dll later, containing more useful functions for you to test too."

Ok thanks budokaiman, remember to use the supported types only though (Strings, Decimals(Floats in DBPro), Integers and Booleans)
If you want any other types added then let me know and I'll look into it for you.

budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 8th Mar 2011 20:15 Edited at: 8th Mar 2011 20:15
I have another question. When making the values, can I use the "optional" feature that VB has?

Quote: "Yes, that's possible and would make it easy to organise, the example I coded does similar but it uses a number for each Stack.
If the coder remembers which number is for which Stack then they could use it like that, or edit it so it uses easy to remember names."

I think that you misinterpreted what I said. What I meant was to create the variables within dbp. IE
instead of

you would do



Mystic-Mod: Putting the fear back into sliced bread since 4th May 2010
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 8th Mar 2011 20:29 Edited at: 8th Mar 2011 20:32
Quote: "When making the values, can I use the "optional" feature that VB has?"

Hmm, good question. As far as I know it doesn't but I've not looked into optional parameters.

I'll do some tests now and if it won't work with them I'll add support

Quote: "I think that you misinterpreted what I said. What I meant was to create the variables within dbp. IE"

Yeah, it looks like I misunderstood.
You can send DBPro variables in the CallMethod command although the example you gave would be along these lines:


That would call the function or sub "stackpush" and give two string parameters with it (the "s,s") with the values in the last section (str$(stackname)+",value").
The values for the parameter types and the parameter values are currently separated by commas as I'm still deciding on the best way to pass parameters so it's easy for the end-coder to use.

budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 8th Mar 2011 20:46 Edited at: 8th Mar 2011 21:44
Quote: "I'm still deciding on the best way to pass parameters so it's easy for the end-coder to use."

I think it would be easy to do

runmethod("functionname","10,-234,'string','char',0")

keeping the function name and the values separate, but the values would be grouped together in one string.

(^if that makes sense)

Also, I attached another .dll and source.[i][/i]


Mystic-Mod: Putting the fear back into sliced bread since 4th May 2010
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 8th Mar 2011 21:08 Edited at: 8th Mar 2011 21:17
Thanks budokaiman, I understand what you mean
I'm going to try and make it simpler by making my DLL detect the parameter types that the function/sub you are trying to call requires.

Then all you'll need to put in the command would be the name and the values, like this:

Or


After running tests on the new DLL, I've got the following:
Any optional parameters must be included otherwise the "parameter count mismatch" error is shown. I'll add support for optional parameters later tonight.

IsURLValid: Successfully checked my site and Google.
EncryptString: Successfully encrypted the string "encryptme".
DecryptString: Successfully decrypted the result of the above call. (11 milliseconds to process both calls)
sumTest: Failed, support for optional parameters needs to be added.
sumTestNoOptionals: Successfully completed.
Compress: Successfully compressed a 264kb exe file to a 149kb .gz archive.
Decompress: Successfully decompressed the resulting compressed file from above call back to a working exe.

budokaiman
FPSC Tool Maker
14
Years of Service
User Offline
Joined: 24th Jun 2009
Playing: Hard to get
Posted: 22nd Mar 2011 21:21
Hey, I'm just curious if you got the optional parameters fixed, or added any other good new features. I can't wait for release, it looks really useful.

knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 23rd Mar 2011 00:18 Edited at: 23rd Mar 2011 00:19
Hi budokaiman, the answer to your question is yes I've got it working.

It now accepts optional parameters and it also no longer requires you to specify the type of parameter that is given to the function/sub.
The system works out what type is required and converts the values you give in DBPro to the correct values for VB and C#.

So this in DBPro..


...becomes this:


It still currently supports integers, decimals, strings and boolean values only.

Grasmann
15
Years of Service
User Offline
Joined: 1st Sep 2008
Location:
Posted: 21st May 2011 17:00
I would like to test this, too. ^^
Grasmann
15
Years of Service
User Offline
Joined: 1st Sep 2008
Location:
Posted: 22nd May 2011 23:28 Edited at: 22nd May 2011 23:41
Mh I got a problem here. I managed to create a vb.net dll. But when I try to load the class it crashes my app.

So I don´t even get to the "Class couldn´t be loaded."-Part ... it just crashes. What could I possibly be doing wrong?

Class:


DB-Code:
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 23rd May 2011 00:51 Edited at: 23rd May 2011 00:52
Quote: "Mh I got a problem here. I managed to create a vb.net dll. But when I try to load the class it crashes my app.
So I don´t even get to the "Class couldn´t be loaded."-Part ... it just crashes. What could I possibly be doing wrong?"

It could be the .Net Framework 4 bit, I've updated the plguin with a new section of code and it's been causing problems with the .Net Framework 4 compatibility.
Try making your DLL run off of the 2.0, 3.0 or 3.5 frameworks versions
I am looking into the cause and hope to ahve the problem resolved for final release.

Grasmann
15
Years of Service
User Offline
Joined: 1st Sep 2008
Location:
Posted: 2nd Jun 2011 16:55 Edited at: 2nd Jun 2011 18:17
So, I finally had some time to test this. And now with a 3.5 DLL this is working really great.

My tests so far:

Running 200 Methods in a row: ~ 10 ms
Running 2.000 Methods in a row: ~ 60 - 70 ms
Running 20.000 Methods in a row: ~ 660 - 680 ms
Running 200.000 Methods in a row: ~ 6800 - 6900 ms

I think the Speed is ok. As long as one doesn´t try to clone minecraft or something and wants to manage all the blocks per DLL.

Perfect to use as a backend for the application with a small cache for the important values in dark basic

The only thing that is annoying me is that RunMethod just returns strings. ^^
If it would be possible to change this to get real numbers it would be a little easier to use efficiently.

But the biggest advantage is, of course, the possibility to manage big parts of the game code in the awsome IDE of VB.Net ( or better Visual Studio 2010 ).
Grasmann
15
Years of Service
User Offline
Joined: 1st Sep 2008
Location:
Posted: 19th Jun 2011 06:41
I didn´t have much time/motivation to work on my private stuff lately.

But when I played around with your plugin I discovered that multiple
classes are allready possible. All you have to do is make a frontend
DLL + a backend DLL.

Then you have to import the backend DLL as reference into the frontend
DLL.

The frontend DLL only has one class ( the class you are loading in
Dark Basic ) while the backend DLL can have as much classes as you
want. If you import it as reference you can just use everything from
the backend DLL as if they were part of the frontend.
knxrb
FPSC Tool Maker
15
Years of Service
User Offline
Joined: 10th Oct 2008
Location: United Kingdom
Posted: 20th Jun 2011 00:21
Sweet, thanks for testing
Do you reckon I should add in support for multiple classes and DLLs for the first public release or not?

knxrb
Grasmann
15
Years of Service
User Offline
Joined: 1st Sep 2008
Location:
Posted: 25th Jun 2011 03:57 Edited at: 25th Jun 2011 04:00
Im not sure how this would look like ... you mean
loading different classes with the command "LOADCLASS"?

Maybe you could Change the loading process to only require "LOADDLL"
and it binds all classes and modules.

It would be nice to have property support .... but it would also
work without it. I mean direct control of classes and class
instances is not nessecary.

But to have the subs and function of all classes in vb.Net should be
the minimum. So you should be able to use class instances ( and
their properties ) inside the VB.Net-module-functions. And you
should only be able to call the VB.Net-module-functions in Dark
Basic.

That would be easy, clean and awesome.

Login to post a reply

Server time is: 2024-04-25 10:53:42
Your offset time is: 2024-04-25 10:53:42