5 messages in net.java.dev.jna.users[jna-users] Using ByReference correctly
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:[jna-users] Using ByReference correctlyActions...
From:Daniel Thornhill (Dani@validsoft.com)
Date:Dec 15, 2008 5:51:54 am
List:net.java.dev.jna.users

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; }

url: www.validsoft.com<http://www.validsoft.com/>

ValidSoft Ltd is a Private Limited Company. ValidSoft Ltd, Castle Buildings, Tara Street, Tullamore, Co Offaly, Ireland. Registration Number: 377068 Registered in Dublin.