|
-
Mar 22nd, 2003, 05:20 PM
#1
Thread Starter
PowerPoster
(solved) Going back to cander's IPlugin tutorial
(Ref: http://www.vbforums.com/showthread.p...=plugin+cander)
Hi. I've implemented something very similar to Cander's IPlugin tutorial. In fact, I'm using almost the exact same code for the LoadPlugin() function. However, after I create the plugin object, I am unable to cast it to the interface. I recieve a "the specified cast is not valid" error. Here's my interface:
PHP Code:
using System;
using BattleNet;
using BattleNet.Bots;
namespace IBPlugin
{
public interface IHost
{
string Author();
string Version();
ChatBot Bot();
}
public interface IPlugin
{
string Author();
string Name();
string Version();
string Info();
bool Initialize(IHost host);
bool Shutdown();
event ChatBot.BnEvent_Channel OnChannel;
event ChatBot.BnEvent_Emote OnEmote;
event ChatBot.BnEvent_Error OnError;
event ChatBot.BnEvent_Flags OnFlags;
event ChatBot.BnEvent_Info OnInfo;
event ChatBot.BnEvent_Join OnJoin;
event ChatBot.BnEvent_Leave OnLeave;
event ChatBot.BnEvent_Name OnName;
event ChatBot.BnEvent_Null OnNull;
event ChatBot.BnEvent_Other OnOther;
event ChatBot.BnEvent_Talk OnTalk;
event ChatBot.BnEvent_User OnUser;
event ChatBot.BnEvent_WhisperIn OnWhisperIn;
event ChatBot.BnEvent_WhisperOut OnWhisperOut;
event ChatBot.LbEvent_Connected BotConnected;
event ChatBot.LbEvent_Disconnected BotDisconnected;
event ChatBot.LbEvent_Error BotError;
}
}
And here's the line from the other project where it cops out..
PHP Code:
if(pluginImplemented.GetInterface("IPlugin") != null)
{
// Invalid cast!
plugin = (IPlugin)Activator.CreateInstance (pluginImplemented);
if (plugin.Initialize(this.Host))
{
Console.WriteLine(plugin.Name() + " "
+ plugin.Version() +
" by " + plugin.Author() + " Loaded.");
Plugins.Add(plugin);
}
else
{
Console.WriteLine("Plugin failed to initialize.");
}
And here's the implementation...
PHP Code:
using System;
using IBPlugin;
using BattleNet.Bots;
namespace IronBot
{
public class Plugin : IPlugin
{
private IHost _host;
public string Author()
{
return "Kaegan";
}
public string Version()
{
return "1.0";
}
public string Name()
{
return "Test Plugin";
}
public bool Initialize(IHost host)
{
_host = host;
return true;
}
public bool Shutdown()
{
return true;
}
public string Info()
{
return "Just a simple plugin.";
}
public event ChatBot.BnEvent_Channel OnChannel = null;
public event ChatBot.BnEvent_Emote OnEmote = null;
public event ChatBot.BnEvent_Error OnError = null;
public event ChatBot.BnEvent_Flags OnFlags = null;
public event ChatBot.BnEvent_Info OnInfo = null;
public event ChatBot.BnEvent_Join OnJoin = null;
public event ChatBot.BnEvent_Leave OnLeave = null;
public event ChatBot.BnEvent_Name OnName = null;
public event ChatBot.BnEvent_Null OnNull = null;
public event ChatBot.BnEvent_Other OnOther = null;
public event ChatBot.BnEvent_Talk OnTalk = null;
public event ChatBot.BnEvent_User OnUser = null;
public event ChatBot.BnEvent_WhisperIn OnWhisperIn = null;
public event ChatBot.BnEvent_WhisperOut OnWhisperOut = null;
public event ChatBot.LbEvent_Connected BotConnected = null;
public event ChatBot.LbEvent_Disconnected BotDisconnected = null;
public event ChatBot.LbEvent_Error BotError = null;
}
}
The ChatBot class is implemented in within the BattleNet.Bots namespace I created. I made sure that the versions of the interface library and Battlenet library being referenced by each project was the same. Any suggestions? Perhaps its a problem with the events? I've never created an interface with events before...
Last edited by sunburnt; Mar 22nd, 2003 at 11:50 PM.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
-
Mar 22nd, 2003, 07:56 PM
#2
yay gay
are both projects(plugin and host) implementing the same DLL? u cant hard code each plugin in the host and plugin, it must be exactly the same dll!
\m/  \m/
-
Mar 22nd, 2003, 11:38 PM
#3
Thread Starter
PowerPoster
Yup, they both reference the same library.
EDIT: Ha, I misunderstood what you meant! I had the plugin dlls in a different directory with duplicate copies of the battlenet and iplugin libraries. when I put them in the same folder, it worked perfectly. Thanks!
Last edited by sunburnt; Mar 22nd, 2003 at 11:50 PM.
Every passing hour brings the Solar System forty-three thousand miles closer to Globular Cluster M13 in Hercules -- and still there are some misfits who insist that there is no such thing as progress.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|