#include "XPLMDisplay.h"
#include "XPLMGraphics.h"
#include <string.h>
#if IBM
	#include <windows.h>
#if LIN
	#include <GL/gl.h>
#elif __GNUC__
	#include <OpenGL/gl.h>
	#include <GL/gl.h>

#ifndef XPLM300
	#error This is made to be compiled against the XPLM300 SDK

// An opaque handle to the window we will create
static XPLMWindowID	g_window;

// Callbacks we will register when we create our window
void				draw_hello_world(XPLMWindowID in_window_id, void * in_refcon);
int					dummy_mouse_handler(XPLMWindowID in_window_id, int x, int y, int is_down, void * in_refcon) { return 0; }
XPLMCursorStatus	dummy_cursor_status_handler(XPLMWindowID in_window_id, int x, int y, void * in_refcon) { return xplm_CursorDefault; }
int					dummy_wheel_handler(XPLMWindowID in_window_id, int x, int y, int wheel, int clicks, void * in_refcon) { return 0; }
void				dummy_key_handler(XPLMWindowID in_window_id, char key, XPLMKeyFlags flags, char virtual_key, void * in_refcon, int losing_focus) { }

PLUGIN_API int XPluginStart(
							char *		outName,
							char *		outSig,
							char *		outDesc)
	strcpy(outName, "HelloWorld3Plugin");
	strcpy(outSig, "xpsdk.examples.helloworld3plugin");
	strcpy(outDesc, "A Hello World plug-in for the XPLM300 SDK.");
	XPLMCreateWindow_t params;
	params.structSize = sizeof(params);
	params.visible = 1;
	params.drawWindowFunc = draw_hello_world;
	// Note on "dummy" handlers:
	// Even if we don't want to handle these events, we have to register a "do-nothing" callback for them
	params.handleMouseClickFunc = dummy_mouse_handler;
	params.handleRightClickFunc = dummy_mouse_handler;
	params.handleMouseWheelFunc = dummy_wheel_handler;
	params.handleKeyFunc = dummy_key_handler;
	params.handleCursorFunc = dummy_cursor_status_handler;
	params.refcon = NULL;
	params.layer = xplm_WindowLayerFloatingWindows;
	// Opt-in to styling our window like an X-Plane 11 native window
	// If you're on XPLM300, not XPLM301, swap this enum for the literal value 1.
	params.decorateAsFloatingWindow = xplm_WindowDecorationRoundRectangle;
	// Set the window's initial bounds
	// Note that we're not guaranteed that the main monitor's lower left is at (0, 0)...
	// We'll need to query for the global desktop bounds!
	int left, bottom, right, top;
	XPLMGetScreenBoundsGlobal(&left, &top, &right, &bottom);
	params.left = left + 50;
	params.bottom = bottom + 150;
	params.right = params.left + 200;
	params.top = params.bottom + 200;
	g_window = XPLMCreateWindowEx(&params);
	// Position the window as a "free" floating window, which the user can drag around
	XPLMSetWindowPositioningMode(g_window, xplm_WindowPositionFree, -1);
	// Limit resizing our window: maintain a minimum width/height of 100 boxels and a max width/height of 300 boxels
	XPLMSetWindowResizingLimits(g_window, 200, 200, 300, 300);
	XPLMSetWindowTitle(g_window, "Sample Window");
	return g_window != NULL;

PLUGIN_API void	XPluginStop(void)
	// Since we created the window, we'll be good citizens and clean it up
	g_window = NULL;

PLUGIN_API void XPluginDisable(void) { }
PLUGIN_API int  XPluginEnable(void)  { return 1; }
PLUGIN_API void XPluginReceiveMessage(XPLMPluginID inFrom, int inMsg, void * inParam) { }

void	draw_hello_world(XPLMWindowID in_window_id, void * in_refcon)
	// Mandatory: We *must* set the OpenGL state before drawing
	// (we can't make any assumptions about it)
						 0 /* no fog */,
						 0 /* 0 texture units */,
						 0 /* no lighting */,
						 0 /* no alpha testing */,
						 1 /* do alpha blend */,
						 1 /* do depth testing */,
						 0 /* no depth writing */
	int l, t, r, b;
	XPLMGetWindowGeometry(in_window_id, &l, &t, &r, &b);
	float col_white[] = {1.0, 1.0, 1.0}; // red, green, blue
	XPLMDrawString(col_white, l + 10, t - 20, "Hello world!", NULL, xplmFont_Proportional);

14 comments on “Hello World (SDK 3)

  1. Hi,

    I downloaded this Hello World project for Visual Studio 2010.
    I installed a fresh copy of Visual Studio 2010 with SP1
    The project is compiling without problem, and I copied the file in : “…./Resources/plugins/X-Plane-11-Window-API-Sample/64/win.xpl”.

    I launch XPlane11, the plugin is not loaded and the log.txt file shows:
    “> : Error Code = 127 : The specified procedure could not be found.”

    Can you help ?

    1. I can’t reproduce this. The error indicates that one of the five required callbacks is missing from the plugin. Since the sample code implements all 5, I suspect the error either comes from some another plugin, or it’s caused by a modification you made to the code.

  2. Thank you for the reply.

    I didn’t touch any code in the sample, don’t have any other plugin installed, and the visual studio 2010 is a fresh install.

    I reproduced on another PC with all new fresh installs :
    – Visual Studio 2010 SP1 from MSDN
    – Latest Xplane11 version from Steam
    – An untouched Hello-World-SDK-3 project directly from your ZIP¨

    It compiles without any warning or errors and I deploy the generated (in release mode) win.xpl in the …/Resources/plugins/Hello-World-SDK-3/64/win.xpl
    and same result “Error Code = 127 : The specified procedure could not be found.” In the log.txt, so I assume it can be reproduced on many PCs.

    I suspect a linker or compiler option not set in your sample and that I didn’t notice in the documentation ?

      1. Hi,

        I know this is an old thread, but thought to drop my 2 cents:
        I won’t be surprised if you need to install redistributable visual studio 2010, you can found on in:

        But I will point out that in my opinion, it is better to use VS 2015/2017 since in most Win10/Win7 OSes users probably have one of these files as part of other application installation.
        LR team always use here the lowest common denominator, like X-Code 3.2 project. In todays OSX it is hard to find that old X-Code version. It will probably work well with X-Code-6 or 7 too.

      2. Having the same problem when doing a cross-compile from Linux. Build against XPLM 2.1: works perfectly. Build against XPLM 3.0: Error Code = 127 : The specified procedure could not be found
        I checked using dependency walker 2.2 and all 5 functions are definitely in the exported symbols list. I even checked to make absolutely 100% by manually prefixing __declspec(dllexport). Didn’t help either.

      3. I’ve done a bunch more digging and found that the problem exists in the import library XPLM_64.lib that you ship in the SDK. If I substitute the 3.0 import library into the 2.1 SDK and build against it (without using any 3.0 features), I still get the procedure not found error. This leads me to believe that there’s some subtle breakage in the exported symbol names between the import library and how XPLM_64.lib is assembled, leading to a symbol lookup error on load. Unfortunately, the error message in the log file doesn’t tell me which symbol is missing, only that “some” symbol is missing.
        Currently the only workaround I see is attempting to construct my own import library directly from XPLM_64.dll.

  3. Hi Philipp,
    The reason we used Visual Studio 2010 with your sample is because in the sample download title your mention “For Visual Studio 2010” and we wanted to use the sample the way you told us for a first test (It’s our first XPlane plugin, so we don’t know anything about your practices yet). We had to download Visual Studio 2010 from Microsoft MSDN because we don’t use it anymore for years

    To go on with our project, we downloaded the 64 bit version of the SDK (we had some difficulty to find the files, the links on your website seem dead).
    Now with Visual Studio 2017, our first plugin prototype is working well in Xplane11 linked to the 64 bits version of the 2.1.2 SDK.

    We will go on with this version of the SDK and come back when we are able to use the SDK 3.0 (may be more feedback from other users who reproduce the problem ?)

    In the meantime, thank you for your time.

  4. When attempting to compile in VS2010 I get many errors.

    At first it is this:

    1> Add directive to ‘StdAfx.h’ or rebuild precompiled header
    1>c:\users\sarah\documents\visual studio 2010\projects\hello world\hello world\hello world.cpp(114): fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add ‘#include “StdAfx.h”‘ to your source?

    when I add #include “StdAfx.h” to the top of the .cpp file I get many more errors all coming from the GL/gl.h file. Anyone else had similar issues?

  5. I copied the unzipped folder into the plugins folder and it does not work.
    It says fetching plugins in my log but does not fetch this one. Below is what is shown in my log:

    Fetching plugins for C:\Users/sarah/Desktop/X-Plane 11/Resources/plugins
    Loaded: C:\Users/name/Desktop/X-Plane 11/Resources/plugins/PluginAdmin/64/win.xpl (xpsdk.examples.pluginadmin).
    I found the following scenery packages (prioritized in this order):
    0 Custom Scenery/Global Airports/
    1 Custom Scenery/KLAS Las Vegas Mc Carran/

    1. Just unzipping the folder you download here is not enough—you’ll need to compile it first. See the “General Documentation” section here for some background on how the plugin system works.

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.