ShelbySue Posted June 2, 2008 Share Posted June 2, 2008 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 More sharing options...
Richard Robertson Posted June 2, 2008 Share Posted June 2, 2008 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 More sharing options...
ProgAndy Posted June 2, 2008 Share Posted June 2, 2008 (edited) 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 June 2, 2008 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 More sharing options...
Richard Robertson Posted June 2, 2008 Share Posted June 2, 2008 I didn't think AutoIt would create the buffer. I've always felt more safe making buffers myself though. Years of having to has taught me that. My other arguments were sound though. Link to comment Share on other sites More sharing options...
ShelbySue Posted June 2, 2008 Author Share Posted June 2, 2008 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 More sharing options...
Richard Robertson Posted June 2, 2008 Share Posted June 2, 2008 I can only assume that ProgAndy downloaded the dll and viewed a dump of some manner. Link to comment Share on other sites More sharing options...
ptrex Posted June 2, 2008 Share Posted June 2, 2008 @allYou can create barcode in AU3 without external DLL files.Barcode in AU3regardsptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Richard Robertson Posted June 3, 2008 Share Posted June 3, 2008 I doubt the dll just makes a barcode. I'm sure there's some sort of processing involved, a lookup maybe. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now