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.

DLL Talk / TUTORIAL: Making a .NET based plugin that has access to DBPro native commands.

Author
Message
MoomanFL
18
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 22nd Jan 2008 06:19 Edited at: 22nd Jan 2008 08:51
This may have been covered somewhere in the forums or elsewhere, but I have been trying for months to find it and couldn't. I finally, however, pieced enough info together to do it myself so here is a brief tutorial:

CREATING A VB.NET PLUGIN FOR DBPRO WHICH CAN USE DBPRO FUNCTIONS

Introduction
The title of this tutorial says it all. Making plugins that add math functions and other things not already included in DBPro is relatively easy. Actually working with DBPro resources is another story. For example, creating an object through your own plugin DLL.

The purpose of this tutorial isn't to teach you all the ways you can implement this knowledge. That is for you to create on your own. What this tutorial will do, however, is show you how you can access the DBPro functions within your plugin to directly create or manipulate the DBPro created resources from your plugin.

What You Will Need
You will need several things to do this:

A .NET compiler and IDE capable of making .NET Class Libraries. A good free one is SharpDevelop.

A program to view DLL exports. For free you can try the DLL Export Viewer

A program to add string tables to your .NET library to make it available to non-.NET programs such as Winch's dll_tool

An idea of what you want to accomplish and a little knowledge of both DBPro and the language you will make your DLL in.

Patience.

Step 1: Creating our Plugin

For this tutorial we are going to do something really simple. All we are going to do is use the native DBPro functions to make a cube from within our plugin, then rotate it on the X axis from within DBPro.

The first thing you will need to do is open your .NET IDE of choice and start a new Class Library project. Name it whatever you want. For the purpose of this tutorial I just named it My_DBP_Plugin.

Next you will want to add a reference to System.Runtime.InteropServices to your project. If you don't know how to do this then consult your IDE's help files.

After you have added this reference you need to open your main source file. In it you should already have your base class. Make sure it is set for Public. Since I am using VB.NET (C# will use a different key words) you will add this line:



This simply makes it so that you don't have to add the full .NET name every time you want to use a method, property, etc from this namespace.

Next we are going to open our Export Viewer. The following instructions are for those that are using the export viewer I recommended above (if you aren't then you have to find how to do this on your own).

In the dialog that shows, select the second option. This should say "Load functions from the following DLL file:". Once you have done that hit the Browse button and select a DBPro plugin that carries the commands we want to access. For this tutorial we will open the DBProBasic3DDebug.dll (located on my machine in "Crogram FilesThe Game CreatorsDark Basic ProfessionalCompilerplugins"). Make sure that "scan exported functions" is checked at the bottom of the dialog, then hit the OK button.

You will see a long list of familiar command names in an unfamiliar format. That is, unless you are familiar with looking at export string tables in which case this may be very familiar. Scroll down until you see this one:

?MakeCube@@YAXHM@Z

Once you have found that one, highlight it and then right-click and select "Properties" from the menu. In the "Function Name" box you will see the above text. Copy it to your clipboard, you will need it in a second.

Next you will add the following code to your project, pasting the function name above into the appropriate spot:



A little explanation is in order here. The Dark Basic Pro compiler includes all plugins used by your program, even the ones made by TGC, into the executable when you compile a DBP project. When you run it, it unpacks these to a temp directory and your program is then able to access them. What the above code does, is load the DLL responsible for the Basic 3D functions after it has been unpacked. The string table for the TGC DLL doesn't list the commands as simple function names such as "Make Object Cube"... instead the full string MUST be used or your plugin will not be able to find the correct entry point into the DLL you are trying to use. The above code simply declares the "Make Object Cube" function in such a way that your .NET code can use it from the DLL.

Marking it as Private makes sure that it this wrapped function will not be exported directly but can be used within our plugin. Marking it as shared is necessary for several reason, one of which is that we want to be able to use it in a function that will be exported. We designate it as a Sub because the DBP command does not return a value.

Now that this function is declared we can use it in our plugin. Now add the following code to your program:



As you can see, all we are doing is taking the function from DBP function and wrapping it in our own function. DO NOT WRAP FUNCTIONS FOR USE OUTSIDE DARKBASIC PRO. TGC will get mad. I only wrap this function within a DBPro plugin for tutorial purposes to show you how to use the commands in your plugin. Typically a plugin that uses DBPro commands will do more than just echo an existing command.

To explain the above code, we used "Public" and "Shared" so that we, and the .NET compiler, know it is to be exported. Inside we call the "MakeCube" function and just pass along the parameters from the "CubeTest" function.

The full source should look something like this:



Once this is done, you can build your project.

Step 2: Converting from a .NET DLL to a DBP Plugin

Next you will want to open your .Net DLL Tool. If you are using Winch's dll_tool then I will refer you to his site for the instructions. If you are using another DLL conversion tool then use the appropriate instructions for the tool you are using.

Once you have your DLL converted you should be able to move the converted DLL to your DBPro compilers "plugins-user" directory. Mines is located at "Crogram FilesThe Game CreatorsDark Basic ProfessionalCompilerplugins-user". It will then be available from within DBPro which brings us to...

Step 3: Using Your New Plugin

As I mentioned before, and cannot stress enough, YOU MUST USE ANOTHER FUNCTION FROM THE DLL YOU CALLED IN YOUR PLUGIN FOR THAT DLL TO BE INCLUDED IN YOUR DBPRO EXECUTABLE.

Now that I have said this, the following code should be self explanatory. Open up your DBPro IDE of choice and make a project with the following code:



If you see a rotated cube... congratulations. You have successfully called a DBPro command from within your own .NET DLL. The world is your oyster, go create something wonderful.


Conclusion

As with any tutorial your mileage may vary. Use at your own risk. I just hope this saves someone the frustration that I felt in trying to learn how to do this myself.

If anyone has corrections or improvements to suggest... speak up. I am always willing to learn something new.

Enjoy.

Design documents?!? What design documents??? I thought we were just going to wing it!!!
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 23rd Jan 2008 22:19
On these lines:


Would it not be possible to just use:

(No need for <> or the end sub)

Hayer
18
Years of Service
User Offline
Joined: 4th Nov 2005
Location: Norway
Posted: 23rd Jan 2008 22:54
When using the "dll_tool"
I get this error


Could u help me fix that?


Without that error it was a perfect tutorial, exactly what I needed.
Respect

MoomanFL
18
Years of Service
User Offline
Joined: 12th Nov 2005
Location:
Posted: 24th Jan 2008 08:02
@Diggsey -- It is six of one and a half-dozen of the other really. Use which ever one you are most comfortable with. I simply showed it the pure .NET way but there is really no difference in this instance between the two methods.

@Hayer -- You would be better off talking to the_winch on that one since it is his program.

Design documents?!? What design documents??? I thought we were just going to wing it!!!

Login to post a reply

Server time is: 2024-05-04 04:22:14
Your offset time is: 2024-05-04 04:22:14