Currently Being Moderated
Nov 13, 2007 6:08 PM
Specified structure is not the same error with primitive arrays
Hello,
i am trying to access Canon's new SDK from Java using JNI Wrapper. But i am stuck with the very beginning.
Here is the structures defined in 32 bit C code:
typedef struct{
unsigned short ModuleName[512];
unsigned short Version[32];
}prVerInfo;
typedef struct{
unsigned long Entry;
prVerInfo VerInfo[1];
}prDllsVerInfo;
i used JNI wrapper and created this Structures:
public class PrDllsVerInfo extends Structure {
private UInt32 Entry = new UInt32();
private PrimitiveArray VerInfo = new PrimitiveArray(PrVerInfo.class, 1);
...
}
public class PrVerInfo extends Structure {
private PrimitiveArray ModuleName = new PrimitiveArray(UInt16.class,512);
private PrimitiveArray Version = new PrimitiveArray(UInt16.class,32);
....
}
and call the method like this:
PrVerInfo version = new PrVerInfo();
UInt32 res = new UInt32();
UInt32 pBufferSize=new UInt32(20000);
Function function = _instance.getFunction("PR_GetDllsVersion");
function.invoke(res, new Pointer(pBufferSize), new Pointer(version ));
but i receive
Exception in thread "main" java.lang.IllegalArgumentException: Specified structure is not the same
at com.jniwrapper.Structure.initFrom(SourceFile:103)
at com.jniwrapper.Structure.clone(SourceFile:279)
at com.jniwrapper.PrimitiveArray.a(SourceFile:102)
at com.jniwrapper.PrimitiveArray.(PrDllsVerInfo.java:19)
from the primitive array description of private PrimitiveArray VerInfo = new PrimitiveArray(PrVerInfo.class, 1);
What can be the problem?
Here is the method definition:
unsigned long PR_GetDllsVersion(
unsigned long* pBufferSize,
prDllsVerInfo* pDllVersion
);
APi explanation:
Retrieves version information of each PS-ReC SDK module (DLL, etc.) currently used. Â
Parameters:
pBufferSize [in/out] Specifies the buffer size of the next parameter. If the function has been executed successfully, the data size stored in the buffer is set.
pDllVersion [out] Specifies the pointer indicating the buffer. The retrieved version information is stored in accordance with the structure type of prDllsVerInfo.
Return values:
prINVALID_PARAMETER The specified parameter is invalid.
prMEM_ALLOC_FAILED Insufficient memory error.
prINSUFFICIENT_BUFFER The buffer size specified by the parameter is smaller than the actual data size. Or, the buffer pointer is NULL.
Other Error value of GetLastError() in Win32 API.
Reference:
If the pDllVersion buffer size specified by the pBufSize parameter is smaller than the actual data size of the version information to be retrieved, the actual data size will be set in pBufSize and prINSUFFICIENT_BUFFER will be returned. The same applies when pDllVersion is a NULL pointer. If pBufSize is greater than the actual data size, all data will be stored in the buffer, and the stored data size will be set in pBufSize.
And here is how they use the API in the example code:
#define MY_BUFFER_SIZE 20480L
unsigned char Buffer[MY_BUFFER_SIZE];
unsigned long BufferSize = 0L
unsigned char VerInfoBuffer[MY_BUFFER_SIZE];
BufferSize = MY_BUFFER_SIZE;
memset(Buffer, 0, MY_BUFFER_SIZE);
err = PR_GetDllsVersion(&BufferSize, (prDllsVerInfo*)Buffer);
memset(VerInfoBuffer, 0, MY_BUFFER_SIZE);
memcpy(VerInfoBuffer, Buffer, BufferSize);
pVerInfoList = (prDllsVerInfo*)VerInfoBuffer;