

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
5 messages in net.java.dev.jna.usersRe: [jna-users] Using ByReference cor...| From | Sent On | Attachments |
|---|---|---|
| Daniel Thornhill | Dec 15, 2008 5:51 am | |
| Timothy Wall | Dec 15, 2008 6:08 am | |
| Daniel Thornhill | Dec 15, 2008 6:17 am | |
| Daniel Thornhill | Dec 15, 2008 6:20 am | |
| Timothy Wall | Dec 15, 2008 6:37 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Re: [jna-users] Using ByReference correctly | Actions... |
|---|---|---|
| From: | Timothy Wall (twal...@dev.java.net) | |
| Date: | Dec 15, 2008 6:37:07 am | |
| List: | net.java.dev.jna.users | |
So you can use these structure types directly in your callback method signature. JNA will automatically create the Java structure, and base it on the native pointer passed to the callback.
If the argument is a pointer to a contiguous array of these structures, you can use Structure.toArray() to access those beyond the first.
On Dec 15, 2008, at 9:20 AM, Daniel Thornhill wrote:
Sorry...and the inParams & outParams structure are:
typedef struct { DivaCallHandle hdCall; DivaIdDescriptor Identifier; DivaAPSendAudio pfnSendAudio; DivaAPStopSendAudio pfnStopSendAudio; DivaAPSetRecordFormat pfnSetRecordAudio; DivaAPCloseAudio pfnCloseAudio; DivaAPPassEvent pfnPassEvent; // Reserved, must be NULL DivaAPSetVolume pfnSetVolume; } DivaAPNotifyCallInParams;
typedef struct { AppCallHandle hAPCall; DivaAPNotifyCallClose pfnNotifyCallClose; DivaAPNotifyReceiveAudio pfnNotifyReceiveAudio; DivaAPConfirmAudioSend pfnConfirmSend; DivaAPGetEventDetails pfnGetEventDetails; // Reserved, must be NULL DivaAudioFormat Format; } DivaAPNotifyCallOutParams;
with each of those being a 'typedef' except DivaCallHandle & AppCallHandle which are type HANDLE, and DivaIdDescriptor which is a struct.
Cheers.
-----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; }







