FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Creating a Class DLL and casting to void*

 
Post new topic   Reply to topic     Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
lkd85



Joined: 14 Jan 2005
Posts: 5

PostPosted: Fri Jan 14, 2005 5:59 pm    Post subject: Creating a Class DLL and casting to void* Reply with quote

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
View user's profile Send private message
csauls



Joined: 27 Mar 2004
Posts: 278

PostPosted: Sat Jan 15, 2005 4:03 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address Yahoo Messenger
lkd85



Joined: 14 Jan 2005
Posts: 5

PostPosted: Sun Jan 16, 2005 12:35 am    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Tutorials All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group