C# Dllimport - pointer to a pointer receiving array -
i trying dllimport function simxgetobjects
remoteapi.dll
of v-rep software. here link function description: http://www.coppeliarobotics.com/helpfiles/en/remoteapifunctions.htm#simxgetobjects
and here brief description function above link:
description: retrieves object handles of given type, or of types (i.e. object handles)
c synopsis: simxint simxgetobjects(simxint clientid,simxint objecttype,simxint* objectcount,simxint** objecthandles,simxint operationmode)
c parameters:
clientid: client id. refer simxstart.
objecttype: object type (sim_object_shape_type, sim_object_joint_type, etc., or sim_handle_all type of object
objectcount: pointer value receive number of retrieved handles
objecthandles: pointer pointer receive object handle array. array remains valid until next remote api function called. operationmode: remote api function operation mode. recommended operation mode function simx_opmode_oneshot_wait
here way importing (simxgetobjects
function):
[dllimport("remoteapi.dll", callingconvention = callingconvention.cdecl)] public static extern int simxgetobjects(int clientid, string objecttype, intptr objectcount, ref intptr objecthandles, string operationmode);
and here how calling it:
int intclientid = simxstart("127.0.0.1", 19999, true, true, 5000, 5); intptr intptrobjectcount = intptr.zero; intptr intptrobjecthandles = intptr.zero; simxgetobjects(intclientid, "sim_handle_all", intptrobjectcount, ref intptrobjecthandles, "simx_opmode_oneshot_wait");
it not show error, both intptrobjectcount , intptrobjecthandles variables zero.
i appreciate if can me on this.
try this:
[dllimport("remoteapi.dll", callingconvention = callingconvention.cdecl)] public static extern int simxgetobjects( int clientid, int objecttype, out int objectcount, out intptr objecthandles, int operationmode ); int objectcount; intptr objecthandles; int result = simxgetobjects( clientid, objecttype, out objectcount, out objecthandles, operationmode ); if( result == 0 && objecthandles != intptr.zero ) { for( int index = 0; index < objectcount; index++ ) { intptr handle = (intptr)((int)objecthandles + index*4); // handle } }
Comments
Post a Comment