Request assistance binding to Windows dsound.{lib, dll}
Andrew Edwards via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Fri May 27 10:37:38 PDT 2016
On Friday, 27 May 2016 at 16:08:27 UTC, Kagamin wrote:
> On Friday, 27 May 2016 at 15:28:42 UTC, Andrew Edwards wrote:
>>> 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.
>
> If you declare extern function with wrong calling convention,
> calling it can result in stack corruption.
Okay, that makes sense. Will remain mindful of that.
>> 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.
>
> This struct is called COM interface, D has built-in support for
> them: https://dlang.org/spec/interface.html#com-interfaces
So if I'm understanding correctly, I should be able to take this:
DECLARE_INTERFACE_(IDirectSound, IUnknown)
{
// IUnknown methods
STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID FAR
*) PURE;
STDMETHOD_(ULONG,AddRef) (THIS) PURE;
STDMETHOD_(ULONG,Release) (THIS) PURE;
// IDirectSound methods
STDMETHOD(CreateSoundBuffer) (THIS_ LPCDSBUFFERDESC,
LPDIRECTSOUNDBUFFER *, LPUNKNOWN) PURE;
STDMETHOD(GetCaps) (THIS_ LPDSCAPS) PURE;
STDMETHOD(DuplicateSoundBuffer) (THIS_
LPDIRECTSOUNDBUFFER, LPDIRECTSOUNDBUFFER *) PURE;
STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
STDMETHOD(Compact) (THIS) PURE;
STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
STDMETHOD(Initialize) (THIS_ LPGUID) PURE;
};
Convert it into this:
extern (C) class IDirectSound : IUnknown
{
// IUnknown methods
HRESULT QueryInterface(const(IID)*, void**);
uint AddRef();
uint Release();
// IDirectSound methods
HRESULT CreateSoundBuffer(LPCDSBUFFERDESC,
LPDIRECTSOUNDBUFFER*, LPUNKNOWN);
HRESULT GetCaps(LPDSCAPS);
HRESULT DuplicateSoundBuffer(LPDIRECTSOUNDBUFFER,
LPDIRECTSOUNDBUFFER*);
HRESULT SetCooperativeLevel(HWND, DWORD);
HRESULT Compact();
HRESULT GetSpeakerConfig(LPDWORD);
HRESULT SetSpeakerConfig(DWORD);
HRESULT Initialize(LPGUID);
}
Import the correct libraries:
import core.sys.windows.windows;
import core.sys.windows.com;
And finally link to the lib file and I should be golden!!!
Except I'm not :(
C:\Users\edwarac\work\sound\code>build
A subdirectory or file ..\..\build already exists.
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
__D8sound12IDirectSound17CreateÇàìBufferMWxPSÇï»DSBUFFERDESCPPCÇèÜ8Çî╔Çå╝C4core3sys7windows6unknwn8IU·ownZi at 12
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound16SetSpeakerConfigMWkZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound16GetSpeakerConfigMWPkZi at 4
sound.obj(sound)
Error 42: Symbol Undefined __D8sound12IDirectSound7CompactMWZi at 0
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound20DuplicateSoundBufferMWPC8sound18IDirectSoundBufferPPC8sound18IDirectSoundBufferZi at 8
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound19SetCooperativeLevelMWPvkZi at 8
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound10InitializeMWPS4core3sys7windows8basetyps4GUIDZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound7GetCapsMWPS8sound6DSCAPSZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer12GetFrequencyMWPkZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer6SetPanMWiZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer9GetFormatMWPS4core3sys7windows8mmsystem12WAVEFORMATEXkPkZi at 12
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer7RestoreMWZi at 0
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer6GetPanMWPiZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer4StopMWZi at 0
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer9GetStatusMWPkZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer4LockMWkkPPvPkPPvPkkZi at 28
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer7GetCapsMWPS8sound7DSBCAPSZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer12SetFrequencyMWkZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer9SetFormatMWPxS4core3sys7windows8mmsystem12WAVEFORMATEXZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer9SetVolumeMWiZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer18SetCurrentPositionMWkZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer9GetVolumeMWPiZi at 4
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer18GetCurrentPositionMWPkPkZi at 8
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer6UnlockMWPvkPvkZi at 16
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer4PlayMWkkkZi at 12
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer10InitializeMWPC8sound12IDirectSoundxPS8sound12DSBUFFERDESCZi at 8
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer7ReleaseMWZk at 0
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer6AddRefMWZk at 0
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound12IDirectSound14QueryInterfaceMWPxS4core3sys7windows8basetyps4GUIDPPvZi at 8
sound.obj(sound)
Error 42: Symbol Undefined __D8sound12IDirectSound7ReleaseMWZk at 0
sound.obj(sound)
Error 42: Symbol Undefined __D8sound12IDirectSound6AddRefMWZk at 0
sound.obj(sound)
Error 42: Symbol Undefined
__D8sound18IDirectSoundBuffer14QueryInterfaceMWPxS4core3sys7windows8basetyps4GUIDPPvZi at 8
--- errorlevel 32
More information about the Digitalmars-d-learn
mailing list