Request assistance binding to Windows dsound.{lib, dll}

Andrew Edwards via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri May 27 08:28:42 PDT 2016


On Friday, 27 May 2016 at 12:30:50 UTC, Guillaume Piolat wrote:
> On Friday, 27 May 2016 at 12:26:19 UTC, Andrew Edwards wrote:
>>
>>     OPTLINK (R) for Win32  Release 8.00.17
>>     Copyright (C) Digital Mars 1989-2013  All rights reserved.
>>     http://www.digitalmars.com/ctg/optlink.html
>>     sound.obj(sound)
>>      Error 42: Symbol Undefined _DirectSoundCreate at 12
>>     --- errorlevel 1
>>
>
> Have you tried with extern(C) yet?
> extern(C) is for undecorated symbold
> extern(Windows) adds the _ and @12 decorations (would be 
> __stdcall on C/C++ side)

The thought never crossed my mind. Tried it and it works like a 
charm. Thanks to everyone who responded.

notna: It is not really necessary to put the lib in the libs 
folder since it's being passed on the command line and available 
in the build directory. I will place it there eventually though.

On other issue remains that I could not sort out:

Once DirectSoundCreate() returns successfully, I need to call one 
of the function pointers in the struct but am at a loss of how to 
define it based on the interface presented.

According the code, SetCooperativeLevel() can be called one of 
two ways, either via a template[1] or directly through the second 
parameter provided to and modified by SetCooperativeLevel().

I tried the two approaches below both inside and outside the 
struct but neither worked.

     // first approach
     struct IDirectSound
     {
         extern(C) HRESULT SetCooperativeLevel(HWND, DWORD);
     }

     // second approach
     alias setCooperativeLevel = HRESULT function(HWND, DWORD);
     setCooperativeLevel SetCooperativeLevel;

It seemed pointless trying to recreate the template since above 
attempts did not expose the function signature which is necessary 
to get the template working. Any ideas?

[1] 
https://gist.github.com/AndrewEdwards/560601a62ea890842ecac90bb41896a8#file-dsound-h-L248


More information about the Digitalmars-d-learn mailing list