www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Interfacing to C++ / Fltk

reply "Michael" <pr m1xa.com> writes:
Hi,

I have C++ code:
-----
#define dllExport __declspec(dllexport)


namespace fltk = fltk3;

class dllExport FltkWindow : public fltk::Window
{
	public:
			FltkWindow(int w, int h, const char* title = 
nullptr):fltk::Window(w, h, title) { }

};



dllExport FltkWindow* get_Win(int w, int h, const char * title = 
nullptr)
{
	FltkWindow * win = new FltkWindow(w, h, title);

	if(win)
	{
		cout<<"not null win";
		return win;
	}

	cout<<"null win";
	return 0;
};
-----

And D code:

-----
extern (C++)
{
	interface FltkWindow
	{
		void show();
	}

	FltkWindow get_Win(int, int, const char*);
}

class FliWindow
{
	private FltkWindow _win;

	public this(int w, int h, string label = "Fli_Window")
	{
		_win = get_Win(w, h, label.ptr);
		writeln(label);
	}

	public void ShowMe(string[] args)
	{
		writeln("ShowMe");
		_win.show();

	}
}
-----
int main(string[] args)
{
     FliWindow w = new FliWindow(300, 200);
     w.ShowMe(args);
     return Fltk.Run();
}

-----
And output:
-----
Fli_Window
ShowMe
not null win
-----

Why not "not null win -> Fli_Window -> ShowMe"?

P.S.: Win 7 64bit, Dmd 2.060, Dmc 8.52, Fltk 3.0.
Aug 19 2012
parent "Kagamin" <spam here.lot> writes:
Try printf at C++ side.
Aug 19 2012