5 messages in net.java.dev.jna.usersRE: [jna-users] Using ByReference cor...
FromSent OnAttachments
Daniel ThornhillDec 15, 2008 5:51 am 
Timothy WallDec 15, 2008 6:08 am 
Daniel ThornhillDec 15, 2008 6:17 am 
Daniel ThornhillDec 15, 2008 6:20 am 
Timothy WallDec 15, 2008 6:37 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] Using ByReference correctlyActions...
From:Daniel Thornhill (Dani@validsoft.com)
Date:Dec 15, 2008 6:17:28 am
List:net.java.dev.jna.users

Thanks, I will try that.

The signature of the c callback is:

typedef BOOL (*DivaAPNotifyCall) ( DivaAppHandle hApp, DivaAPNotifyCallInParams* pInParams, DivaAPNotifyCallOutParams* pOutParams );

which I have mapped to,

public interface DivaNotifyCallCallbackHandler extends Callback { public boolean callback(Pointer audioProviderApplicationHandle,
Pointer inParams, Pointer outParams); }

Thanks again.

-----Original Message----- From: Timothy Wall [mailto:twal@dev.java.net] Sent: 15 December 2008 14:08 To: use@jna.dev.java.net Subject: Re: [jna-users] Using ByReference correctly

What's the C signature for the callback? what are inParams and outParams in native code?

Structure.toArray() lets you auto-allocate or auto-map a contiguous block of structures in memory. It does *not* create an array of "sruct*".

Structure.ByReference forces use of "struct*" semantics in situations that would otherwise use "struct", primarily as a field in a Structure. It has no effect with function arguments or return values, which default to using "struct *" (Structure.ByValue serves a complementary function).

If you want to extract an array of pointers (struct * or otherwise), use Pointer.getPointerArray() (assuming you have the base address of the array).

On Dec 15, 2008, at 8:52 AM, Daniel Thornhill wrote:

Hi, Wondering if you could help me again! I am struggling with accessing a data structure which should be returned as part of a Callback. I am fairly new to C++ so...there is a good chance this is me doing something wrong.

Essentially what I am trying to do is connect to an 'Audio Provider' which then make a Callback to a callback object registered earlier (shown below - NotifyCallCallbackHandler). The code I do this with is just below.

final DivaIdDescriptorByReference idDescriptor = new DivaIdDescriptor.DivaIdDescriptorByReference(); idDescriptor.Id[0] = 4; idDescriptor.Id[1] = 2; DivaReturnCode returnCode = mapDivaReturnCode(

DivaNativeLibrary .instance .DivaConnectAudioProvider(call.getDivaCallHandle().getValue(), AUDIO_PROVIDER_NAME, idDescriptor, DivaAudioProviderMode.MODE_AUDIO_RECEIVE.getDivaValue()));

When the Callback gets made I am trying to reference the data values I set above - e.g. idDescriptor.Id[0] = 4 and idDescriptor.Id[1] = 2;. However, these are always returned as 0 - or a newly initalised array. Am I doing something incorrectly whereby I cannot initialise the Structre DivaIdDescriptor from the structure in navtive memory?

All the code I am using (or the relevant bits) are below.

Thanks again for your help.

Cheers, Dan

typedef struct { DWORD IdFormat; unsigned char Id[100]; } DivaIdDescriptor;

public class DivaIdDescriptor extends Structure { public static class DivaIdDescriptorByReference extends DivaIdDescriptor implements Structure.ByReference { }

public int IdFormat; public byte[] Id = new byte[100]; }

DIVA_SERVER_API DWORD DivaConnectAudioProvider ( DivaCallHandle hSDKCall, char* Providername, DivaIdDescriptor* pDeviceId, DivaAPMode WhatToConnect );

public int DivaConnectAudioProvider(Pointer divaCallHandle, String name, DivaIdDescriptorByReference idDescriptor, int streamingDirection);

public class NotifyCallCallbackHandler implements DivaNotifyCallCallbackHandler {

public NotifyCallCallbackHandler() { }

public boolean callback(Pointer audioProviderApplicationHandle, Pointer inParams, Pointer outParams) {

System.out.println("NotifyCallCallbackHandler.callback():: " + audioProviderApplicationHandle.hashCode()); DivaNotifyCallInParams tmp = new DivaNotifyCallInParams(inParams); Structure[] s = tmp.toArray(1); DivaNotifyCallInParams tmp1 = (DivaNotifyCallInParams)s[0]; System.out.println("NotifyCallCallbackHandler.callback():: " + tmp1.Identifier.Id[1]); return false; }

}

public class DivaNotifyCallInParams extends Structure { public DivaNotifyCallInParams(Pointer pointer) { super.useMemory(pointer); }

public Pointer hdCall; public DivaIdDescriptor Identifier; public DivaSendAudioCallbackHandler pfnSendAudio; public DivaStopSendAudioCallbackHandler pfnStopSendAudio; public DivaSetRecordFormatCallbackHandler pfnSetRecordAudio; public DivaCloseAudioCallbackHandler pfnCloseAudio; public DivaPassEventCallbackHandler pfnPassEvent; // Reserved, must be NULL public DivaSetVolumeCallbackHandler pfnSetVolume; }