translation of "sizeof" for xojo?

Hi,

I am trying to write an app using a SDK.
A lot of the functions have as a parameter “sizeof” an other parameter of the function (see below)

tPvCameraInfoEx list; if(PvInitialize() == ePvErrSuccess) { while(PvCameraCount() == 0) Sleep(250); // wait for any camera PvCameraListEx(&list,1,NULL,sizeof(tPvCameraInfoEx)); /* ... */ } else printf("failed to initialize the API\ ");

How can I do “sizeof(tPvCameraInfoEx)” with xojo?

Thanks

Chris

It depends what what size you’re trying to get. If a Structure or MemoryBlock, you can use their Size properties. If something else, you’ll have to calculate it yourself.

There is no direct equivalent for sizeof

My problem is I have to call the function with declare, see below :

Declare Function PvCameraListEx Lib dylibLocation (tPvCameraInfoEx,1,1,?) as CFStringRef

And I don’t really know what they mean by “sizeof(tPvCameraInfoEx)”?
tPvCameraInfoEx is a pointer which should give me the list of camera but I don’t know how to know its size when there is only one camera?

[quote=91821:@Christophe Blanc]
tPvCameraInfoEx is a pointer which should give me the list of camera but I don’t know how to know its size when there is only one camera?[/quote]

A pointer is, that is, a pointer to a memory location. Since Xojo produce 32 bit executables then its size is 32bit.

Assuming this is the right API http://www.alliedvisiontec.com
However I don’t see where they give a header file so I can actually tell how big this is

Massimo, tPvCameraInfoEx is a structure of unknown size, not a pointer. :wink:

This changes, then. Christophe said it was a pointer.
Then you need the header to know more about the struct.

Or, make a simple C program which printf the sizeof(tPvCameraInfoEx). Sometimes I use this trick.

Sorry, I thought it was a pointer because I am supposed to get information out of it.
What is a structure and how can I retrieve information from it?
And also how can I get its size without “sizeof”?
thanks

By the way Norman, it is the right API

Thanks

Here is the link for the manual :
http://www.alliedvisiontec.com/fileadmin/content/PDF/Software/Prosilica_software/Prosilica_software_doc/PvAPI_SDK_Manual.pdf
And I am trying to resolve (for now :wink: the “PvCameraInfoEx” page 38 or PvCameraListEx page 42

thanks

[quote=91855:@Christophe Blanc]Sorry, I thought it was a pointer because I am supposed to get information out of it.
What is a structure and how can I retrieve information from it?
And also how can I get its size without “sizeof”?
thanks[/quote]
I just didn’t see a header file there so I have no idea what to post to answer your question
IF you have the header file then somewhere in there is buried a declaration of that type
And from that you can figure out how big it is (and it might be worthwhile to declare a structure that is laid out the same)

Do you need “PvAPI.h” or a sample “ListCameras.cpp”?
Thanks

Ok, seems to be :

//
// Camera interface type (i.e. firewire, ethernet):
//
typedef enum
{
    ePvInterfaceFirewire = 1,
    ePvInterfaceEthernet = 2,
    __ePvInterface_force_32 = 0xFFFFFFFF

} tPvInterface; //4 bytes


//
// Camera information type (extended)
//
typedef struct
{
    unsigned long StructVer;	// Version of this structure //4
    //---- Version 1 ----
    unsigned long UniqueId; // Unique value for each camera //4
    char CameraName[32]; // People-friendly camera name (usually part name) //32
    char ModelName[32]; // Name of camera part //32
    char PartNumber[32]; // Manufacturer's part number //32
    char SerialNumber[32]; // Camera's serial number //32
    char FirmwareVersion[32]; // Camera's firmware version //32
    unsigned long PermittedAccess; // A combination of tPvAccessFlags //4
    unsigned long InterfaceId; // Unique value for each interface or bus //4
    tPvInterface InterfaceType; // Interface type; see tPvInterface //4

} tPvCameraInfoEx;

sizeof(tPvCameraInfoEx) seems to be 180.

How should I write the code ?
I tried this but I am getting a syntax error?

Declare Function PvCameraListEx Lib dylibLocation (pList,0,pConnectedNum,180) as Ptr

You mixed declaring with calling.
pList is a pointer to that structure of 180 bytes. 0 is not a definition of a parameter, and so on.

http://documentation.xojo.com/index.php/Declare

You need to declare the function before you can call the function.
So you need to do:

Declare Function PvCameraListEx Lib dylibLocation (parameters) as ptr
dim result as ptr = PvCameraListEx(pList, 0, pConnectedNum, 180)

I’ll leave the parameters in the declaration to you.

Since the call is

unsigned long PvCameraListEx ( tPvCameraInfoEx* pList, unsigned long ListLength, unsigned long* pConnectedNum, unsigned long Size );
with notes
• pList Array of tPvCameraInfoEx, allocated by the caller. The camera list is returned in this array.
• ListLength Length of pList array.
• pConnectedNum The number of cameras found is returned here. This may be greater than ListLength. Null pointer is allowed.
• Size Size of the tPvCameraInfoEx structure

Declare Function PvCameraListEx Lib dylibLocation (tPvCameraInfoEx as ptr, ListLength as integer, byref pConnectedNum as integer, size as integer ) as integer
You might actually call this twice in a row

  1. to see how many are returned
  2. then to get the actual list

since YOU have to figure out how big to make the buffer to hold the list

If you do something like

[code]Declare Function PvCameraListEx Lib dylibLocation (tPvCameraInfoEx as ptr, ListLength as integer, byref pConnectedNum as integer, size as integer ) as integer

dim cameraInfo as memoryBlock
dim listlength as integer
dim connected as integer
dim size as integer = 180
dim result as integer

result = PvCameraListEx (cameraInfo, ListLength, connected, size )
// assuming no error happened (HUGE ASSUMPTION!!!)
// connected should have the number of cameras connected

cameraInfo = new memory block (connected * 180)
result = PvCameraListEx (cameraInfo, connected, connected, size )
// assuming no error happened (HUGE ASSUMPTION!!!)
// camera info should have all the buttes of info about however many cameras were attached
[/code]