Another GUI alternative?
clayasaurus
clayasaurus at gmail.com
Mon Apr 17 12:37:34 PDT 2006
Nilo wrote:
> In article <e20mc9$bc5$1 at digitaldaemon.com>, clayasaurus says...
>> Nilo wrote:
>>> My question is: has someone tried to use fox from D? Would be possible for D
>>> call a library written in C++?
>> Yes.
>>
>> If it is possible, what sould I do to port that
>>> library in a D's usable manner?
>> Create a C wrapper for it, then call the C wrapper from D.
>
> What are the steps involved in creating a wrapper from C++? Is there a simple
> tutorial or how-to? Or samples?
>
> I've done a search but could not find...
>
> I would like to start these port. Maybe I can do it... ;-)
>
> TIA
>
> Nilo
>
#1) First compile a foktk.lib of this library with DMC.
#2) The 'C' wrapper will be done in C++, but is called the C wrapper
because you wrap the classes into C functions. First you have to locate
the important classes in the library, and then you must create wrappers
for them. It may go something like...
------------------------------------------------
#include "foxtk.h"
Window *window;
void window_Start(char[] title, int x, int y)
{
window = new Window("Title", x,y);
}
void window_Close()
{
window.close();
delete window;
}
------------------------------------------------
Compile this with DMC as well, we'll name it foxtkglue.lib.
#3) The D interface. You can so something like...
module window;
// pretty it up
void start() { window_Start() }
void close() { window_Close() }
// C-functions
extern(C)
{
void window_Start(...);
void window_Close(...);
}
#4) Using
Compile your D code with your two .lib's, and do something like...
import window;
main()
{
window.start(..,..,..);
window.close(..,..,..);
}
----------------------------
Here's a C interface example I created with RakNet.
http://www.dsource.org/projects/bindings/browser/trunk/raknet/rakglue
Goodluck.
~ Clay
More information about the Digitalmars-d
mailing list