Page 1 of 1
					
				Import question
				Posted: Fri Aug 04, 2006 3:41 pm
				by cseymour
				Hello all,
I have a lib that has a function that from the header file returns the following:
Returns:    UINT16_T    ver_info    High byte is major version number
                                       Low byte is minor version number
A couple of questions:
If this function takes no parametes, what would the declare look like (I am trying to use Import .. EndImport?
What type would I use for the return value and how would I be able to get the high byte vs the low byte?
Thanks.
Chris
			 
			
					
				Re: Import question
				Posted: Fri Aug 04, 2006 4:23 pm
				by inc.
				cseymour wrote:Hello all,
I have a lib that has a function that from the header file returns the following:
Returns:    UINT16_T    ver_info    High byte is major version number
                                       Low byte is minor version number
You might post that piece of code please?
UINT16 means an unsigned 16bit variable. 16bit Variables in PB are 'word' ones, but as in PB variables are handled as signed ones in general you can use a 'long' as receiving following by an "& $FFFF" to receive the unsigned word value.
So in the C/C++ Code
Code: Select all
UINT16 ver_info(void) {
    return versNumber;
}
you can use the function after importing like this.
(as you only need the high/low-bytes (8bits each) its enough to use a PB 'word' .w)
UnsignedLowByte.w = ver_info() & $FF
UnsignedHighByte.w =  ver_info() >> 8  & $FF
 
			 
			
					
				
				Posted: Fri Aug 04, 2006 4:35 pm
				by cseymour
				Here is the code from the header file:
/****************************************************************************
   tkcmdsetUSB_get_dll_version()
   Returns the current version number of this software.
   Inputs:     None
   Outputs:    None
   
   Returns:    UINT16_T    ver_info    High byte is major version number
                                       Low byte is minor version number
****************************************************************************/
PM3USB_API UINT16_T tkcmdsetUSB_get_dll_version(void);
I have this in my PB code:
ImportC  "RPPM3USB.lib"
  tkcmdsetUSB_get_dll_version.l()
EndImport
LonVar.l = tkcmdsetUSB_get_dll_version() & $FFFF
MessageRequester("Test","DLL version is " + Str(LonVar.l))
Am I on the right track?
Thanks.
Chris
			 
			
					
				
				Posted: Fri Aug 04, 2006 4:48 pm
				by inc.
				This above is not a codesniplet but a Library API descripton 
As its a lib - if needed do also link with the msvcrt library:
Code: Select all
Import "msvcrt.ib"
Endimport
ImportC "RPPM3USB.lib"
  tkcmdsetUSB_get_dll_version.l()
EndImport 
result.w = tkcmdsetUSB_get_dll_version() ; // store 'unsigned 16bit' integer in 'result.w'
minorVersNumber.w = result & $FF
majorVersNumber.w = result >> 8 & $FF
Both minor and major numbers are shown in their unsigned values.
onVar.l = tkcmdsetUSB_get_dll_version() & $FFFF
Nope, not right on track in your case as using '& $FFFF' on a Long (in PB a signed 32bit integer) will give you the unsigned lowWord, but you need the low and the high bytes from the resulting unsigned 16bit integer 

 
			 
			
					
				
				Posted: Fri Aug 04, 2006 4:56 pm
				by cseymour
				Thanks inc.
Appreciate you taking the time to show me.  I have some research to do to figure the code out but atleast I am on the right track now.
Much appreciated.
Chris
			 
			
					
				
				Posted: Fri Aug 04, 2006 5:25 pm
				by inc.
				
			 
			
					
				
				Posted: Tue Aug 15, 2006 1:06 am
				by mskuma
				inc. wrote:As its a lib - if needed do also link with the msvcrt library
inc. I salute you - you're a genius 

 . That tip helped me alot (to avoid some unresolved external linker error with a 3rd party lib). Thank you very much.