/*
	Reload Plugin
	Written by Sandy Barbour - 24/02/2004

	This examples shows how reload plugins
	This is handy for debugging as you don't have to stop XPlane
*/

#if IBM
#include <windows.h>
#endif
#include <string.h>
#include <stdio.h>

#include "XPLMPlugin.h"
#include "XPLMMenus.h"

static void ReloadPluginsMenuHandler(void * mRef, void * iRef);

/*
 * XPluginStart
 * 
 * Our start routine registers our window and does any other initialization we 
 * must do.
 * 
 */
PLUGIN_API int XPluginStart(
						char *		outName,
						char *		outSig,
						char *		outDesc)
{
	/* First we must fill in the passed in buffers to describe our
	 * plugin to the plugin-system. */
	XPLMMenuID	id;
	int			item;

	strcpy(outName, "ReloadPlugins");
	strcpy(outSig, "xplanesdk.sandybarbour.ReloadPlugins");
	strcpy(outDesc, "A plugin that allows plugins to be reloaded.");
			
	item = XPLMAppendMenuItem(XPLMFindPluginsMenu(), "ReloadPlugins", NULL, 1);

	id = XPLMCreateMenu("ReloadPlugins", XPLMFindPluginsMenu(), item, ReloadPluginsMenuHandler, NULL);
	XPLMAppendMenuItem(id, "Reload", (void *)"Reload plugins",1);

	/* We must return 1 to indicate successful initialization, otherwise we
	 * will not be called back again. */
	 
	return 1;
}

/*
 * XPluginStop
 * 
 * Our cleanup routine deallocates our window.
 * 
 */
PLUGIN_API void	XPluginStop(void)
{
}

/*
 * XPluginDisable
 * 
 * We do not need to do anything when we are disabled, but we must provide the handler.
 * 
 */
PLUGIN_API void XPluginDisable(void)
{
}

/*
 * XPluginEnable.
 * 
 * We don't do any enable-specific initialization, but we must return 1 to indicate
 * that we may be enabled at this time.
 * 
 */
PLUGIN_API int XPluginEnable(void)
{
	return 1;
}

/*
 * XPluginReceiveMessage
 * 
 * We don't have to do anything in our receive message handler, but we must provide one.
 * 
 */
PLUGIN_API void XPluginReceiveMessage(
					XPLMPluginID	inFromWho,
					int				inMessage,
					void *			inParam)
{
}


void ReloadPluginsMenuHandler(void * mRef, void * iRef)
{
	if (!strcmp((char *) iRef, "Reload plugins"))
	{
		XPLMReloadPlugins();
	}
}

4 comments on “ReloadPlugins

  1. Hello,
    So I tried modifying this code to have two+ sub-menus and have one not do anything and have one reload the plugins. I am not sure exactly how to do this. I have been able to create a second sub-menu but am not able to attach a function to it. I tried

    “XPLMAppendMenuItemWithCommand(id, “Hello Again”, (void *)”Hello People”, XPLMCommandRef, MakeMenuHandler);”‘

    And Visual Studio would not let me compile it. If there is any more code you want me to include that would allow you to better diagnose the problem, please let me know.

    Thanks,
    Lorenzo Beronilla

  2. I’m confused as to was the void * mRef does and void * iRef does. Can you provide an example of what should be entered here as part of the function?

    1. This is a “refcon” parameter, and it’s used throughout our APIs. If you pass a pointer to some struct of your own when you register a callback with the XPLM, we’ll give you that same pointer back each call. This is how you can associate a particular “object” with a call.

  3. The Linux build of this plugin does not work correctly on X-Plane 11.41. The version of the SDK included in this code results in an ELF file where the XPluginStart, etc., are defined as “local” symbols instead of “global” symbols.

    I was able to fix this problem by overwriting all the contents of /SDK/ with those of the most recent version of the Hello World sample plugin.

Leave a Reply

Your email address will not be published. Required fields are marked *

Please do not report bugs in the blog comments.
Only bugs reported via the X-Plane Bug Reporter are tracked.