Jump to content

Use new DLL - IM Barcodes


Recommended Posts

I have the following sample C code calling this dll (attached) and can't figure out about sending and getting parameters. This looks like pointers and I am not sure how that translates to AU code. I have my sample code below. I am getting a blank $return - the same as I am sending:

char TrackString[21]; /* Input parameter Track String + 1 null*/
char RouteString[12]; /* Input parameter Route String + 1 null*/
char BarString[66]; /* Output parameter Bar String + 1 null */

int RetCode; /* Return code from the usps4cb encoder */

int USPS4CB( char *TrackPtr, char *RoutePtr, char *BarPtr);

memcpy(TrackString,"01234567094987654321",20);
TrackString[20] = '\0';

memcpy(RouteString,"01234567891",11);
RouteString[11] = '\0';

memset(BarString, ' ', sizeof(BarString)); /* Prime with blanks! */
BarString[65] = '\0'; 

RetCode = USPS4CB(TrackString,RouteString,BarString);

printf("Outputs are:\n"); /* Print the outputs */
printf("USPS4CB RetCode is: %i\n",RetCode);
printf("Encoded Bar String is: %s\n",BarString);

AU3 Test Code:( $return2 = 0 means it worked and translated the the barcode data)

#include <String.au3>

$Result = _StringRepeat(" ",65)
$start= '82205455868913559972'
$next = '01234567891'

$dll = dllopen("usps4cb.dll")


$result2 = dllcall($dll,'str',$start,'str',$next, 'str', $Result )
msgbox(0,"Call Result",$result2)
msgbox(0,"Barcode Response","[" & $result & "] Length=" & StringLen($result) )

usps4cb.dll

Link to comment
Share on other sites

Well, first off, you forgot to list the function name in your DllCall. How do you expect it to call the function that it doesn't have the name for?

DllCall ( "dll", "return type", "function" [, "type1", param1 [, "type n", param n]] )

Also remember, DllCall returns an array.

If the function call fails then @error is set to 1. Otherwise an array is returned that contains the function return value and a copy of all the parameters (including parameters that the function may have modified when passed by reference).

$return[0] = function return value

$return[1] = param1

$return[2] = param2

...

$return[n] = paramn

Also, you have to declare a buffer ahead of time, for the function to fill in.

Try this instead and see if it works.

#include <String.au3>

$Result = DllStructCreate('char[66]')
DllStructSetData($Result, 1, _StringRepeat(' ', 65))
$start= '82205455868913559972'
$next = '01234567891'

$dll = dllopen("usps4cb.dll")

$result2 = dllcall($dll, 'int', 'USPS4CB', 'str', $start, 'str', $next, 'ptr', $Result)
msgbox(0, "Call Result", $result2[0])
msgbox(0, "Barcode Response", "[" & $Result & "] Length=" & StringLen($Result))
Link to comment
Share on other sites

You don't need to create the Buffer. AutoIt does that for you, but the Stringis only changed in the Returned Array, not in the Parameter-Variable. The Dll needs cdecl, too: -> Retrun type: "int:cdecl"

So you have to call the DLL this way:

CODE
#include <String.au3>

$Result = _StringRepeat(" ",65)

$start= '82205455868913559972'

$next = '01234567891'

$result2 = dllcall("usps4cb.dll","int:cdecl","USPS4CB",'str',$start,'str',$next, 'str', $Result )

If @error Then

MsgBox(0, "Dllcall Error:", @error)

Else

; The Parameters are returned in the Return-array, so use $result2[3] for third parameter :)

msgbox(0,"Call Result",$result2[0])

msgbox(0,"Barcode Response","[" & $result2[3] & "] Length=" & StringLen($result2[3]) )

EndIf

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

BINGO - DINGO!

Thanks guys - the addition of int:cdecl made the call and returned the correct (changed) data in the $result2[3] location.

How did you know the int:cdecl was needed instead of just int ?

I can't believe I forgot the function! This is my first attempt at utilizing a dll that has not already been used by someone on the forum and, when it didn't work the first few tries, I freaked out and came to the forum.

But, then, that is what this community is for?

Thanks again.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...