New topic: Declare with unsigned char * array as a parameter
<http://forums.realsoftware.com/viewtopic.php?t=41320> Page 1 of 1 [ 1 post ] Previous topic | Next topic Author Message pascale Post subject: Declare with unsigned char * array as a parameterPosted: Fri Nov 04, 2011 8:00 pm Joined: Fri Nov 04, 2011 7:15 pm Posts: 1 Hello, I have a problem to adapt an API call to a library. One of the parameters is an unsigned char * array (or string). This data type does not exist in RealBasic. I tried using a memory block to replicate the unsigned char * string. ------------------------------------------- C Function definition: This function is designed to set a device to prescribed parameters. Proper settings can only be confirmed by another API call. Before this function is called, I have no problem in initializing the device and getting a Handle with other functions of the same DLL, so communication is possible. As defined in the API HTML doc: Quote:FuncStatus SetDeviceParameters ( unsigned int dsetn, unsigned int dsubn, unsigned char * productParam ) The same function as defined in the API Header (.h) file: Quote:PDEC FuncStatus SetDeviceParameters(unsigned int dsetn,unsigned int dsubn,unsigned char* productParam); Function Parameters: dsetn: Device setting number dsubn: Device sub-setting number productParam: Product parameters to set the device FuncStatus is the return status of the function call; it is an Integer that can be Positive or Negative. A returned zero value means that the function succeeded. Note: PDEC is a C extension module. I do not know if this has some importance for RealBasic adaptation. ------------------------------------------- Here are two C code examples given by the library designer. They probably are designed for different compilers, since the second example terminates the unsigned char by a "0", as in a CString. C code example #1: Code:unsigned char ucParam[] = { 0xA1,0x1B,0x41,0xFF,0x49,0x8D,0x22,0x8D }; SetDeviceParameters(NULL,NULL,ucParam); C code example #2: Code:unsigned char ucParam[] = {0xA1,0x1B,0x41,0xFF,0x49,0x8D,0x22,0x8D,0}; SetDeviceParameters(NULL,NULL, ucParam ); ------------------------------------------- // RealBasic adaptation: // RealStudio 2011 Release 3 (Windows) Code:Dim FuncStatus As Integer Dim mbParam As MemoryBlock Soft Declare Function SetDeviceParameters Lib LibraryName _ (dsetn As UInt64, _ dsubn As UInt64, _ productParam As Ptr) As Integer mbParam = New MemoryBlock(8) // as in C code example #1 'mbParam = New MemoryBlock(9) // as in C code example #2, commented to replicate example 1 mbParam.UInt8Value(0)=161 // i.e. 0xA1 mbParam.UInt8Value(1)=27 // i.e. 0x1B mbParam.UInt8Value(2)=65 // i.e. 0x41 mbParam.UInt8Value(3)=255 // i.e. 0xFF mbParam.UInt8Value(4)=73 // i.e. 0x49 mbParam.UInt8Value(5)=141 // i.e. 0x8D mbParam.UInt8Value(6)=34 // i.e. 0x22 mbParam.UInt8Value(7)=141 // i.e. 0x8D 'mbParam.UInt8Value(8)=0 // as in C code example #2, commented to replicate example 1 FuncStatus = SetDeviceParameters(0, 0, mbParam) // Proper settings can only be verified with another API call afterwards. The check fails with the above code! Notes: 1- NULL in the C example are replaced by "0". This is also recommended by the library designer. 2- I understand that the "*" in "unsigned char *" indicates that a pointer is expected. 3- MY HYPOTHESIS: The mbParam values are the decimal equivalent of the hexadecimal parameters. 4- Although the API defines SetDeviceParameters as a FUNCTION, the C code examples show it as a SUB. We tested it as a SUB also in RealBasic; the results are the same. Code:Soft Declare Sub SetDeviceParameters Lib LibraryName _ (dsetn As UInt64, _ dsubn As UInt64, _ productParam As Ptr) 5- RealBasic compiles and the program does not hang or crash when executing the function. Calling another API function afterwards indicates that SetDeviceParameters DID NOT work! 6- It was checked, during code execution, that the mbParam memoryblock was filled as: A11B41FF498D228D // when replicating C code example #1 or A11B41FF498D228D00 // when replicating C code example #2 (with and without a terminating Null character defined by mbParam.UInt8Value(8)=0) These are my equivalents to the unsigned char * arrays in the C code examples. 7- Research seems to confirm that dsetn and dsbn are 64-bit unsigned; assigning an Integer type instead did not change the result. ------------------------------------------- FuncStatus is returned as "0" for SetDeviceParameters. However, this may not be relevant since testing the function as a sub also worked (which means that the returned value may always be zero whether the function call succeeded or not). When checking the settings afterwards with another API call, the check fails, indicating that the settings were NOT accepted. It is as if the parameters are received by the API but not understood/formatted correctly. Does my interpretation of the parameter string (productParam) correspond to what a C program expects as an unsigned char * array ? Expressed otherwise, how do we deal with unsigned char * array parameters in a Declare? Any help/suggestion appreciated! Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 1 post ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
