Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Thu Aug 17, 2017 12:30 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 11 posts ] 
Author Message
 Post subject: hello world plugin
PostPosted: Thu Jan 15, 2009 6:25 pm 
Offline

Joined: Fri Dec 01, 2006 8:45 am
Posts: 70
Location: home
Hi!

I'm trying to learn about writing my own plugings in C++. And I can't start....
I need to do a very very simple simple plugin and make it work inside RB.

For example I don't understand if I need to compile the C++ code or put it somehow inside RB to make the plugin.

so... where to start?

a simple tutorial for example... thank you very much.
Fgrant.


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Thu Jan 15, 2009 8:00 pm 
Offline

Joined: Fri Sep 30, 2005 9:12 am
Posts: 725
Location: Rockford, IL
First off, here are a couple of places to look:
http://jdiwnab.no-ip.org/program/other/plugin-tutorial.php
http://ramblings.aaronballman.com/2007/11/plugins_can_be_fun_part_one_vi.html
http://ramblings.aaronballman.com/2007/11/plugins_can_be_fun_part_two_g.html

First off, you'll need a C++ compiler (I use Code::Blocks). You'll also need the Plugin SDK, which is included with the latest version of RB. Here is a step-by-step walkthru of how I created the famous "add5" plugin. Note that I created a Windows plugin. If you're working on a different platform, then some of these steps will be different, though the overall procedure is the same.

  • Start up Code::Blocks.
  • File>New>Project…
    Select Dynamic Link Library icon and click [Go].
    Type in name for project, select where to save it, release version only.
  • Double click Main.ccp and delete the example code.
    Right click Main.h and select Remove file from project.
  • Goto Plugin SDK, copy all files within the Glue Code folder and Includes folder to the folder containing your DLL project file.
  • Project>Add Files… select PluginMain.cpp, rb_plugin.h, REALplugin.h, and WinHeader++.h.
  • Double click PluginMain.cpp, change line 10 to “#if WIN32”, File>Save, then remove PluginMain tab from editor.

    Double click WinHeader++.h, change line 37 to “#ifdef IGNOREQT”, File>Save, then remove WinHeader++ tab from editor. Note that I used this procedure to get the compiler to ignore quicktime, which is needed on Windows. I'm sure I'll get raked over the coals for this, but it worked for me. :|
  • Go back to Main.cpp tab, put in this code:
    #if WIN32
       #include "WinHeader++.h"
    #endif
    #include "rb_plugin.h"
    static int add5func(int v)
    {
    return v + 5;
    }

    REALmethodDefinition add5defn = {
    (REALproc) add5func,
    REALnoImplementation,
    "add5(v as integer) as integer"
    };


    void PluginEntry(void)
    {
    REALRegisterMethod(&add5defn);
    }

  • File>Save
    Build>Build (making sure that the build target is Release and not Debug).
    The DLL file will be located at: project file folder>bin>Release>filename.dll
  • Exit Code::Blocks.
  • Goto Plugins SDK>Plugin Converter. There are two RB project files there (Plugin Converter and Plugin Creator). Use REALbasic to compile both of those projects. Place PluginConverter.exe into the Plugin Creator folder that RB made when it compiled the Plugin Creator project.
  • Double click Plugin Creator.exe. Click the [Add File] button and locate your dll file. Next, drag reorder the dll into the Windows folder. Click the [Save…] button and choose a filename and location for the plugin. Exit the Plugin Creator program.
  • Goto the location of your plugin and move it into RB's Plugins folder. Start up Realbasic, add a pushbutton to Window1, and put the following code into the action event: MsgBox Str(add5(6))

    Run the project and push the button. A message box should pop up with the number 11 in it.

I'd also like to say that I'd much rather write programs in realbasic than c++ :shock:

_________________
RB2010r2.1 Pro on Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Fri Jan 16, 2009 5:52 am 
Offline

Joined: Fri Dec 01, 2006 8:45 am
Posts: 70
Location: home
THANK you Verrry much
I try all your steps and it works perfectly.

I will check those links.


When using the pluging creator I notice we drag into "Windows"... what if the plugin is for linux?

thank you again.


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Sat Jan 17, 2009 1:09 am 
Offline

Joined: Fri Sep 30, 2005 9:12 am
Posts: 725
Location: Rockford, IL
kokorini wrote:
When using the pluging creator I notice we drag into "Windows"... what if the plugin is for linux?

Then you drag it into the linux folder.

_________________
RB2010r2.1 Pro on Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Sat Jan 17, 2009 9:07 am 
Offline

Joined: Fri Dec 01, 2006 8:45 am
Posts: 70
Location: home
piMaster wrote:
kokorini wrote:
When using the pluging creator I notice we drag into "Windows"... what if the plugin is for linux?

Then you drag it into the linux folder.


then if it has to work for both just put it on both?

It sound like magic, because we will be using a windows dll on linux! thank!


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Sat Jan 17, 2009 11:33 am 
Offline

Joined: Fri Sep 30, 2005 9:12 am
Posts: 725
Location: Rockford, IL
kokorini wrote:
then if it has to work for both just put it on both?

It sound like magic, because we will be using a windows dll on linux! thank!

No, it doesn't work that way. You have to compile the c++ code differently for each platform you want. A windows dll will only work on windows. You'll need a different type of file for mac or linux.

_________________
RB2010r2.1 Pro on Windows 7


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Wed Jan 06, 2010 1:30 pm 
Offline

Joined: Fri Feb 29, 2008 5:25 pm
Posts: 557
piMaster wrote:
kokorini wrote:
then if it has to work for both just put it on both?

It sound like magic, because we will be using a windows dll on linux! thank!

No, it doesn't work that way. You have to compile the c++ code differently for each platform you want. A windows dll will only work on windows. You'll need a different type of file for mac or linux.



Thank you for simplifying this process!

One question.

I am using a Mac for development
and
Mac/Win for deployment.

Whats the best approach for Win/Mac cross platform plugins? Do I need to compile on each platform?

_________________
http://www.mupromo.com/?ref=4850
Support Indie Developers and Buy Their Products!


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Wed Jan 06, 2010 1:53 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
shaggymac wrote:
Do I need to compile on each platform?

Yes.


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Tue Jan 17, 2012 12:22 pm 
Offline

Joined: Sun Oct 07, 2007 8:06 am
Posts: 25
Hi,
I created the plugin on Windows XP + code compiled and worked.
But If I execute the code compiled in other computer (with another Windows XP), I see an error message:

Image

Why ?


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Tue Jan 17, 2012 1:40 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
Looks like you compiled it and neglected to copy the Libs directory to that other computer

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: hello world plugin
PostPosted: Wed Jan 18, 2012 2:00 pm 
Offline

Joined: Sun Oct 07, 2007 8:06 am
Posts: 25
npalardy wrote:
Looks like you compiled it and neglected to copy the Libs directory to that other computer


exactly !
now it work.
thank's


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 11 posts ] 

All times are UTC - 5 hours


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

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