2 messages in net.java.dev.jna.usersRe: [jna-users] JNA mappings for dsound
FromSent OnAttachments
Damian MinkovSep 10, 2007 1:33 am 
Timothy WallSep 10, 2007 5:35 am 
Actions with this message:
Paste this link in email or IM:
Paste this link in email or IM:
Atom feed for this thread
Paste this URL into your reader:
Subject:Re: [jna-users] JNA mappings for dsoundActions...
From:Timothy Wall (twal@dev.java.net)
Date:Sep 10, 2007 5:35:29 am
List:net.java.dev.jna.users

Use StdCallLibrary for the library interface and StdCallCallback for the callback interface. WINAPI is a macro which expands to "__stdcall".

On Sep 10, 2007, at 4:33 AM, Damian Minkov wrote:

Hi all, I am new to JNA and I'm not c++ guru. These days I'm trying to use dsound on windows (dsound.dll) from JNA but I have problems start mapping the functions from it. Can you give me some starting point, starting examples here are the parts from the header file I'm wondering how to map and use

You need to scan through the w32 header files to see what the definition of each of the types is. Most LPXXX can be represented by Pointer (at least to start with).

struct IDirectSound;

DEFINE_GUID(IID_IDirectSound, 0x279AFA83, 0x4981, 0x11CE, 0xA5, 0x21, 0x00, 0x20, 0xAF, 0x0B, 0xE5, 0x60);

#define INTERFACE IDirectSound

DECLARE_INTERFACE_(IDirectSound, IUnknown) { ........... STDMETHOD(Initialize) (THIS_ LPCGUID pcGuidDevice) PURE; ........... };

typedef struct IDirectSound *LPDIRECTSOUND;

If you're going to invoke members of the COM structure, make sure you use the most recent JNA code from source control. If you define the function callbacks within the IDispatch structure ("Initialize", above), JNA will generate Java proxies for you that you can then invoke, provided you've got a pointer to the COM object.

I've made this : //C++ code typedef BOOL (CALLBACK *LPDSENUMCALLBACKA)(LPGUID, LPCSTR, LPCSTR, LPVOID); extern HRESULT WINAPI DirectSoundEnumerateA(LPDSENUMCALLBACKA pDSEnumCallback, LPVOID pContext);

// Java public static class GUID extends Structure { public long Data1; public short Data2; public short Data3; public byte[] Data4;

public GUID(){ Data4 = new byte[4]; allocateMemory(); } }

interface DirectSoundEnum extends Callback { boolean callback(GUID guid, String description, String module, int index); }

The last argument should technically be a Pointer, but if you're passing in an integer as the user data, I suppose it'd work. Use StdCallCallback, not Callback (CALLBACK is a macro for __stdcall).

public void DirectSoundEnumerateA(DirectSoundEnum callback);

If in the end you need to use a COM object with a lot of COM arguments, you'll want to look at JACOB (http://jacob- project.sf.net), which can generate Java interfaces for COM objects. It also is set up to handle all the different VARIANT types that COM often uses.