PDA

View Full Version : Are you having trouble getting started with C++ plugin?


SteveNelson
28 Sep 2002, 01:21 PM
I think i'm in the same boat as many other people here on this list. I have almost zero experience with C++. But! i'm very determined to learn. I've been playing with the sample code in Visual C++ 6 for a few hours now and have been making a diary on my progress.

If anyone would like to read my notes, here you go

http://www.secretagents.com/index.cfm?fuseaction=trillian.trillianplugin

I'll be working on this off and on so check back often if you'd like. Hopefully it'll help others with the same problems I've had.

Like i said, i'm an absolute beginner with c++, I'm probably screwing up a bunch of definitions, so if any experienced folks see something wrong, please let me know.

Steve Nelson

Azhrarn
28 Sep 2002, 02:12 PM
Hehe, nice job on the diary. One of the first things I did as well was remove the contact list popups. ;)

I know TrillHunter said he was working on a C++ framework, and I am somewhat working on one as well. Mainly for my own learning experience, as I have never really attempted some of the more advanced C++ features. Especially not Windows specific programming like DLLs.

Basically, I have been rereading my old C/C++ books, and going through the various help dialogs in Visual studio to get a handle on all the things I have never used. Also, if you are using Visual Studio, and see something that you don't understand, try highlighting the word and pressing F1. There is a good chance there is a few examples in the help. Or just google it. :)

rolith_te
28 Sep 2002, 02:15 PM
great idea for a basic intro... been looking for something like this for a while

timvw
28 Sep 2002, 02:53 PM
Hello,

Actually the code in the sample plugin is pure c and has little to do with c++. Btw, a sample.h file is NOT needed, but when u are going to use some functions which aren't defined yet in your code, u have to tell the compiler that code will be provided further in the file.... You can do that to put all function signatures on the start of your code.c file, or you put in a line #include code.h (this will make the preprocessor/compiler copy all the contents of code.h into code.c)

---------------------

To create a really minimalistic plugin, using visual c++, all you need to do is create a new project, (win32 dll). Normally you should have a dllMain(...) function generated now. If you read the trillian sdk, they put clear that every plugin should have methods

- int __declspec(dllexport)plugin_main(.....) {
return 0;
}

int __declspec(dllexport)plugin_version(void) {
return 1;
}

When you go compiling this, u will end up with a dll. however, when you try to load it, trillian will say it is not a valid trillian plugin. So we are missing something.... Oh yeah, we forget to tell we want to export these 2 functions... So create a .def file like this
LIBRARY NameOfYourLib
EXPORTS
plugin_main @1
plugin_version @2

Now we can load the dll into trillian.

Actually, anytime trillian wants to tell us something, it will call the plugin_main function, that contains a char * that is telling us, what trillian is trying to tell us. When having a look at the sdk we can see, trillian will inform us about load, initialLoad, start, stop, finalUnload, unload, prefsShow and prefsAction.

Now it is up to you to decide what should happen on these actions. For example, when trillian calls the plugin_main function with plugin_main("load", plugin_info_t *); we know the plugin is being loaded, and we should provide trillian info about our plugin. Everything you are expected to send back to trillian is explained in the sdk, so use it ;)

timvw
28 Sep 2002, 03:00 PM
Ill make a beginners howto, with some nice screenshots this week.... I guess that will be easier to understand ;)

TrillHunter
28 Sep 2002, 03:04 PM
Well, I was writing a response, but timvw beat me to it. :P

BTW, I like the diary idea, and I like your point of view. Experienced programmers like myself aren't usually able to help an absolute beginner, because everything comes so naturally to us, and we make assumptions about what the beginner knows (e.g. what is a struct). Keep up the good work, and keep asking questions so we can help you, and documenting your point of view on it so you can help other upcoming developers. :)

timvw
28 Sep 2002, 04:16 PM
I was kinda bored, so i created a little howto ;)

Have a look at the files on
http://prdownloads.sourceforge.net/trillianplug.

(http://prdownloads.sourceforge.net/trillianplug/howto_begin.zip?download)

timvw
28 Sep 2002, 04:52 PM
I putted it online at http://trillianplug.sourceforge.net/howto/howto_begin.html

Azhrarn
28 Sep 2002, 06:30 PM
Well, among other things, I spent a lot of today refreshing myself on how C++ classes work, and how I wanted to try and make a C++ header file to ease plugin programming.

Eventually I realized the approach I had been taking was probably bad. I was going to basically rewrite plugin.h to suite my needs, then realized it would be a pain to update, and that there was no real need to rewrite that header. As it is basically just defining structs and a few compiler macros. ANYhoo...

I figured out the following, which should basically let me encapsulate all the plugin stuff I want to do inside a class in an event driven interface. Basically allowing me to hide almost all the API stuff, and have the plugin programmer pass me a list of all the handlers (callbacks) he wants for each event.

Sorry if some of you readers out ther already know this or find it easy, but I have to say this is the coolest thing I personally have ever figured out on my own with C/C++. The following code is what I'm talking about:


// testproj.cpp

#include "stdafx.h"

/* stdafx has the following:

#include <iostream>
#include <string>

using namespace std;
*/

class blah
{
public:

blah::blah( void )
{
mystring = "m000";
}

void blah::print( void )
{
cout << mystring << endl;
}

void blah::dothis(void (&function)( string ))
{
function( mystring );
}


private:

string mystring;

};

void test( string );

int main(int argc, char* argv[])
{
blah moo;

moo.dothis(test);


return 0;
}

void test( string argstring )
{
cout << "moo = " << argstring << endl;
}


/*
output:

moo = m000
*/


Basically this allows me to make the dothis member function accept a pointer to a function as an argument. Since I believe all the callbacks would have standard arguments, I can define an accessor that will allow people to tell the class to use X function for Y event. ;) Hopefully, this will actually work like I am planning, but either way, this is a fun discovery for me; as I never really even considered the usage of pointers to functions before. :)

Edit: the print function was from a previous test. I still havent worked out directly calling another accessor from the passed function. But I imagine a way is possible. possibly by passing self and having the function look for a class object.

timvw
28 Sep 2002, 07:33 PM
Perhaps you should have a look at the code at http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/trillianplug/pluggie/

When i finish the pluggie class, creating a new plugin should only require to implement the needed functions, and inherit all the rest from the pluggie class.

Azhrarn
28 Sep 2002, 07:39 PM
Yup, saw that you were doing that before, but I am trying to code this myself as a learning experience right now. A lot of what I have is similiar. :) I'll be sure to keep an eye on it though.

quietbritishjim
29 Sep 2002, 07:37 AM
Originally posted by timvw
I putted it online at http://trillianplug.sourceforge.net/howto/howto_begin.html

:o This is fantastic! I already know C++ (well, I understand it, I can't necessarily remember it) but every other introduction to Visual C++ want to go through the app builder X-( Even this little bit you've done should be enough to get me started, thanks tmvw (beer) (y)

Jim

Krule
29 Sep 2002, 10:23 AM
TIMVW, how close are you to finishing the class? I'm waiting with much anticipation for it.

timvw
29 Sep 2002, 06:01 PM
Currently i don't have that much time to spend on trillian thingies... (uni just started, and they are buzzing me with a lot of work)

All i can say is: be patient, young paduan ;)

Or u could complete the source, and then send it to me ;)

timvw
29 Sep 2002, 06:08 PM
I forgot to mention it, but i added a second lesson to the howto ;)

http://trillianplug.sourceforge.net/howto/index.html

i'll try to make an howto add a preferences page tomorrow.

Azhrarn
29 Sep 2002, 11:18 PM
If anyone is interested, let me know what you think about the C++ stuff I was working on today. This is just a snapshot of my project in the middle of doing stuff, so some of the headers are slightly mangled with a few things I was testing. But the general layout should be somewhat workable.

The main thing that is giving me problems now is passing the void *data structure to a user supplied function. It's not quite working...

Also, I am trying to find a good location for the user to place their hook declarations and such. As I moved the exported functions into the header files. I may end up moving them back in if I can't get a clean way to keep them in the library.

But, anyhoo... enjoy :)