Import question

Just starting out? Need help? Post your questions and find answers here.
cseymour
User
User
Posts: 29
Joined: Fri Jun 02, 2006 6:39 pm

Import question

Post 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
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Re: Import question

Post 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
Last edited by inc. on Fri Aug 04, 2006 4:40 pm, edited 1 time in total.
Check out OOP support for PB here!
cseymour
User
User
Posts: 29
Joined: Fri Jun 02, 2006 6:39 pm

Post 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
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post 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 ;)
Check out OOP support for PB here!
cseymour
User
User
Posts: 29
Joined: Fri Jun 02, 2006 6:39 pm

Post 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
inc.
Enthusiast
Enthusiast
Posts: 406
Joined: Thu May 06, 2004 4:28 pm
Location: Cologne/GER

Post by inc. »

:)
Check out OOP support for PB here!
mskuma
Enthusiast
Enthusiast
Posts: 573
Joined: Sat Dec 03, 2005 1:31 am
Location: Australia

Post 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 :D . That tip helped me alot (to avoid some unresolved external linker error with a 3rd party lib). Thank you very much.
Post Reply