I've found the first thing in D that REALLY got on my nerves
Max Samuha
maxter at i.com.ua
Thu Sep 14 05:58:01 PDT 2006
On Fri, 08 Sep 2006 03:03:40 +0200, mike <vertex at gmx.at> wrote:
>Hi!
>
>Maybe you read my last posts about VST plugins ... just to clear that up,
>I don't want to leave wrong info here: They've got a C interface, so all
>my writing about linking C++ was bs. Just in case anybody wants to do some
>VST development in D. Go ahead, no problem with D either way (host or
>plugin - both works when one converts the SDK files to D). I'm already
>happily loading VST plugins and toying aroung with them.
>
>Anyway, I've found something annoying, nothing really bad, but just
>terribly annoying for a medium-level coder like me.
>
> From my code:
>
>' void *proc = GetProcAddress(hlib, toStringz("main"));
>' if(proc is null)
>' {
>' [snip]
>' }
>'
>' auto getNewPluginInstance = cast(mainFunc)proc;
>'
>' // get new instance
>' AEffect *newInstance = null;
>' newInstance = getNewPluginInstance(&audioMaster);
>
>That works. Why? Because:
>
>' extern (C)
>' {
>' typedef AEffect *function(audioMasterCallback) mainFunc;
>' [snip]
>' }
>
>There's something that didn't work (Access violation when calling
>getNewPluginInstance) and it cost me hours of debugging and trying out
>insanely unlogical things, until I had the idea to define mainFunc as a
>type. Good thing is I found a lot of bugs in advance. Well, that's how it
>originally was:
>
>' auto getNewPluginInstance = cast(AEffect
>*function(audioMasterCallback))proc;
>
>Without the typdef. Access violation, because getNewPluginInstance has D
>linkage. And there's no way to cast that void * pointer to a C function.
>Defining the mainFunc type solves this.
>
>Just wanted to point that out. After half a year with D - this was the
>first time I ever got angry at this language.
>
>' auto getNewPluginInstance = cast(extern (C) AEffect
>*function(audioMasterCallback))proc;
>
>That would be a logical and intuitive thing - at least for me. If you have
>a call-once-forget-afterwards function with C linkage you shouldn't be
>forced to define a type. I even had the whole module extern (C). Didn't
>work.
>
>-Mike
I can't beleive that anybody except me is trying to write a VST host
in D! :). I was thinking of a way to call the VST plugin from D
through the C function pointer and was going to ask the NG members for
help but mike was nice enough to do that for me! Isn't it a miracle?
More information about the Digitalmars-d
mailing list