View previous topic :: View next topic |
Author |
Message |
lkd85
Joined: 14 Jan 2005 Posts: 5
|
Posted: Fri Jan 14, 2005 5:59 pm Post subject: Creating a Class DLL and casting to void* |
|
|
Hi, I'm new to D (of course) I was wondering is it possible to make a DLL with classes in it? Also what is the best way of casting a struct into a void*?
Thanks |
|
Back to top |
|
|
csauls
Joined: 27 Mar 2004 Posts: 278
|
Posted: Sat Jan 15, 2005 4:03 pm Post subject: |
|
|
The question of classes in DLL's has come up a few times, you may want to run a search for it. The basic answer is yes and no. You can make a DLL with D classes in it by using the export attribute, but you can't directly access them from the DLL. You will need to provide a function for returning either an instance of the class or a delegate to a factory method on the class. For example:
Code: |
export class Foo {
public static Foo instance() { return new Foo; }
public this() {
}
}
export Foo createFoo() { return new Foo; }
export Foo delegate() FooFactory { return &(Foo.instance); }
|
As to casting structs to void*... you might actually want to use D's void[] type. Using the void-array rather than void-pointer means you get all the usual properties of arrays, such as bounds checking. And the expression to make the cast is simple:
Code: |
struct Abc {
// . . . contents . . .
}
Abc abc;
void[] raw = cast(void[]) abc;
|
_________________ Chris Nicholson-Sauls |
|
Back to top |
|
|
lkd85
Joined: 14 Jan 2005 Posts: 5
|
Posted: Sun Jan 16, 2005 12:35 am Post subject: |
|
|
Thanks for the reply. I suspect the void[] can be casted into a void* also for functions like file streaming and such. |
|
Back to top |
|
|
|