firewzy Posted December 15, 2007 Share Posted December 15, 2007 (edited) Every master, I have a shapelib.dll with c compiled. Through I study its vb code of making dbf files, I have try my best to use dllcall function of autoit to create a .dbf file, however, I always failed. Please give me a hand. The attachment is all files including vb code, shapelib.dll and my test.au3. I hope someone will be able to make it and let me free my brain. In mShapeLib.bas there are many function declares with vb. It works but I transfer these codes to au3 code that doesn't work well. I think that the failure is the bug of autoit3 or the lastest autoit3 isn't able to make it. ------------------------mShapeLib.bas-------------------------- Public Declare Function DBFAddField Lib "shapelib.dll" (ByVal hDBF As Long, ByVal pszFieldName As String, ByVal eType As DBFFieldType, ByVal nWidth As Long, ByVal nDecimals As Long) As Long Public Declare Function DBFCreate Lib "shapelib.dll" (ByVal pszDBFFile As String) As Long Public Declare Sub DBFClose Lib "shapelib.dll" (ByVal hDBF As Long) -------------------------------------Form1.frm------------------------ Dim hDBF As Long Dim lRet As Long Dim i As Long Dim sPath As String sPath = "test" hDBF = DBFCreate(ByVal sPath) lRet = DBFAddField(ByVal hDBF, ByVal sPath, 1, 5, 0) DBFClose ByVal hDBF -----------------------------autoit3------------------------------- $dll = DllOpen("shapelib.dll") Dim $lRet Dim $sPath Dim $hDBF $sPath = @ScriptDir & "\test" $hDBF = DllCall($dll, "dword", "DBFCreate", "str", $sPath) $lRet = DllCall($dll, "int", "DBFAddField", "dword", $hDBF, "str", "name", "int", 1, "int", 10, "int", 0) DllCall($dll, "int", "DBFWriteIntegerAttribute","dword", $hDBF, "int", 0, "int", 0, "int", 10) DllCall($dll, "none", "DBFClose", "dword", $hDBF) DllClose($dll) ---------------------------------------------------------------------------- I felt that my au3 code is correct, but it didn't work well. I have studied it for some days though no answer. Cheers!vb6toAu3.rarshapelib_vc7.1_.rar Edited December 16, 2007 by firewzy Link to comment Share on other sites More sharing options...
JustinReno Posted December 16, 2007 Share Posted December 16, 2007 No one help me!Ok, no one will help you then. Link to comment Share on other sites More sharing options...
FreeSiker Posted December 16, 2007 Share Posted December 16, 2007 (edited) I'm sorry but i don't know how to manage dbf file but your dll have many fonctions i recomand the use of dll_export_viewer http://www.nirsoft.net/utils/dll_export_viewer.html http://shapelib.maptools.org/dbf_api.html expandcollapse popupDBFAddField DBFCloneEmpty DBFClose DBFCreate DBFGetFieldCount DBFGetFieldIndex DBFGetFieldInfo DBFGetNativeFieldType DBFGetRecordCount DBFIsAttributeNULL DBFOpen DBFReadDateAttribute DBFReadDoubleAttribute DBFReadIntegerAttribute DBFReadLogicalAttribute DBFReadStringAttribute DBFReadTuple DBFWriteAttributeDirectly DBFWriteDateAttribute DBFWriteDoubleAttribute DBFWriteIntegerAttribute DBFWriteLogicalAttribute DBFWriteNULLAttribute DBFWriteStringAttribute DBFWriteTuple SHPCheckBoundsOverlap SHPClose SHPComputeExtents SHPCreate SHPCreateObject SHPCreateSimpleObject SHPCreateTree SHPDestroyObject SHPDestroyTree SHPGetInfo SHPOpen SHPPartTypeName SHPReadObject SHPTreeAddShapeId SHPTreeFindLikelyShapes SHPTreeTrimExtraNodes SHPTypeName SHPWriteObject Every master, I have a shapelib.dll with c compiled. Through I study its vb code of making dbf files, I have try my best to use dllcall function of autoit to create a .dbf file, however, I always failed. Please give me a hand. The attachment is all files including vb code, shapelib.dll and my test.au3. I hope someone will be able to make it and let me free my brain. Cheers! Edited December 16, 2007 by FreeSiker Link to comment Share on other sites More sharing options...
GaryFrost Posted December 16, 2007 Share Posted December 16, 2007 (edited) In mShapeLib.bas there are many function declares with vb. It works but I transfer these codes to au3 code that doesn't work well.I think that the failure is the bug of autoit3 or the lastest autoit3 isn't able to make it.------------------------mShapeLib.bas--------------------------Public Declare Function DBFAddField Lib "shapelib.dll" (ByVal hDBF As Long, ByVal pszFieldName As String, ByVal eType As DBFFieldType, ByVal nWidth As Long, ByVal nDecimals As Long) As LongPublic Declare Function DBFCreate Lib "shapelib.dll" (ByVal pszDBFFile As String) As LongPublic Declare Sub DBFClose Lib "shapelib.dll" (ByVal hDBF As Long)-------------------------------------Form1.frm------------------------Dim hDBF As LongDim lRet As LongDim i As LongDim sPath As StringsPath = "test"hDBF = DBFCreate(ByVal sPath)lRet = DBFAddField(ByVal hDBF, ByVal sPath, 1, 5, 0)DBFClose ByVal hDBF-----------------------------autoit3-------------------------------$dll = DllOpen("shapelib.dll")Dim $lRetDim $sPathDim $hDBF$sPath = @ScriptDir & "\test"$hDBF = DllCall($dll, "dword", "DBFCreate", "str", $sPath)$lRet = DllCall($dll, "int", "DBFAddField", "dword*", $hDBF, "str", "name", "int", 1, "int", 10, "int", 0)DllCall($dll, "int", "DBFWriteIntegerAttribute","dword*", $hDBF, "int", 0, "int", 0, "int", 10)DllCall($dll, "none", "DBFClose", "dword*", $hDBF)DllClose($dll)----------------------------------------------------------------------------I felt that my au3 code is correct, but it didn't work well. I have studied it for some days though no answer.No your au3 code is not correct, look at http://shapelib.maptools.org/dbf_api.htmlDBFCreate returns a handle, in au3 that would be "hwnd" not "dword"every place your using "dword*" for the handle should be "hwnd"you should be able to figure it out from there. Edited December 16, 2007 by GaryFrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
firewzy Posted December 16, 2007 Author Share Posted December 16, 2007 No your au3 code is not correct, look at http://shapelib.maptools.org/dbf_api.html DBFCreate returns a handle, in au3 that would be "hwnd" not "dword" every place your using "dword*" for the handle should be "hwnd" you should be able to figure it out from there. I have tried all return type and param_type including your reminds. However, it don't work yet. Poping up an error window as downlist: In the mShapeLib.bas of vb code the dllcall is "Public Declare Function DBFCreate Lib "shapelib.dll" (ByVal pszDBFFile As String) As Long" that function return type is "long", instead I transfer it to the au3 code as "DllCall($dll, "long", "DBFCreate", "str", $sPath)". I think my au3 code is correct, but it don't work well. Link to comment Share on other sites More sharing options...
GaryFrost Posted December 16, 2007 Share Posted December 16, 2007 have you tried :cdecl after the type? look at the dllcall function in the help SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
firewzy Posted December 16, 2007 Author Share Posted December 16, 2007 have you tried :cdecl after the type? look at the dllcall function in the helpI have tyied it, no works. And I study the shapelib source code that use all stdcall type. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 16, 2007 Moderators Share Posted December 16, 2007 dingI'm going to assume by "ding" you mean that cdecl did in fact work.Only because I know you're aren't bumping a thread after 45 minutes... right? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
piccaso Posted December 16, 2007 Share Posted December 16, 2007 DllCall returns an Array (your first post doesn't look like you realised that) try this: $dll = DllOpen("shapelib.dll") Dim $lRet,$sPath,$hDBF $sPath = @ScriptDir & "\test" $hDBF = DllCall($dll, "ptr", "DBFCreate", "str", $sPath) $lRet = DllCall($dll, "int", "DBFAddField", "ptr", $hDBF[0], "str", "name", "int", 1, "int", 10, "int", 0) DllCall($dll, "int", "DBFWriteIntegerAttribute","ptr", $hDBF[0], "int", 0, "int", 0, "int", 10) DllCall($dll, "none", "DBFClose", "ptr", $hDBF[0]) DllClose($dll) CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
GaryFrost Posted December 16, 2007 Share Posted December 16, 2007 DllCall returns an Array (your first post doesn't look like you realised that) try this: $dll = DllOpen("shapelib.dll") Dim $lRet,$sPath,$hDBF $sPath = @ScriptDir & "\test" $hDBF = DllCall($dll, "ptr", "DBFCreate", "str", $sPath) $lRet = DllCall($dll, "int", "DBFAddField", "ptr", $hDBF[0], "str", "name", "int", 1, "int", 10, "int", 0) DllCall($dll, "int", "DBFWriteIntegerAttribute","ptr", $hDBF[0], "int", 0, "int", 0, "int", 10) DllCall($dll, "none", "DBFClose", "ptr", $hDBF[0]) DllClose($dll) Missed pointing that out last night, was tired, still I think it should be "hwnd" according to the documentation it returns a handle. SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference.  Link to comment Share on other sites More sharing options...
piccaso Posted December 16, 2007 Share Posted December 16, 2007 looks like a pointer to me... typedef DBFInfo * DBFHandle; But we're both right From AutoIt's point of view and the new underlying code hwnd is identical to ptr... CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map Link to comment Share on other sites More sharing options...
firewzy Posted December 16, 2007 Author Share Posted December 16, 2007 (edited) Thanks a lot. The problem has solved by piccaso's idea. Thank Piccaso and Garyfrost, and thank all man having helped me for the problem. ---------------------------------------AU3-------------------------------------------- $dll = DllOpen("shapelib.dll") Dim $lRet Dim $i = 100.15 Dim $sPath Dim $hDBF Dim $return = $i $sPath = @ScriptDir & "\test" $hDBF = DllCall($dll, "ptr", "DBFCreate", "str", $sPath) $lRet = DllCall($dll, "long", "DBFAddField", "ptr", $hDBF[0], "str", "name", "byte", 2, "int", 10, "int", 1) DllCall($dll, "long", "DBFWriteAttributeDirectly","ptr", $hDBF[0], "int", 0, "int", 0, "str", $i) DllCall($dll, "none", "DBFClose", "ptr", $hDBF[0]) DllClose($dll) Edited December 16, 2007 by firewzy Link to comment Share on other sites More sharing options...
sensalim Posted February 7, 2008 Share Posted February 7, 2008 How do I obtain this dll file?I went tohttp://dl.maptools.org/dl/shapelib/do I have to compile or something? Link to comment Share on other sites More sharing options...
sensalim Posted February 7, 2008 Share Posted February 7, 2008 DllCall($dll, "long", "DBFWriteAttributeDirectly","ptr", $hDBF[0], "int", 0, "int", 0, "str", $i) I can't find this function anywhere in the original documentation (html file). Did you make the function yourself (a custom function)? Link to comment Share on other sites More sharing options...
sensalim Posted February 7, 2008 Share Posted February 7, 2008 Um, I'm guessing this dll is not meant for reading and writing DBF files... if so, how do you make new column? Thanks. Link to comment Share on other sites More sharing options...
kmanager Posted June 13, 2008 Share Posted June 13, 2008 An alternative is to use this OCX that is designed to read/write shapefile geometry and the dbf table. You can add/remove fields, add/remove geometry, add/remove records. It has a few query methods as well. I believe the OCX handles Date fields too. This OCX is very easy to use and is free. The included help file has many examples.ShapeFile Read/Write OCX - written by Ross Pickardhttp://arcscripts.esri.com/details.asp?dbid=11810 Link to comment Share on other sites More sharing options...
Lgy Posted April 4, 2010 Share Posted April 4, 2010 Hi kmanager,I am very interested in your method. I have downloaded .dll from ESRI and tried quite a while, but still could not figure out how to use them. could you please provide a very simple example to use them with AutoIT, like creating a simple shape file?Many thanks,GuoyuanAn alternative is to use this OCX that is designed to read/write shapefile geometry and the dbf table. You can add/remove fields, add/remove geometry, add/remove records. It has a few query methods as well. I believe the OCX handles Date fields too. This OCX is very easy to use and is free. The included help file has many examples.ShapeFile Read/Write OCX - written by Ross Pickardhttp://arcscripts.esri.com/details.asp?dbid=11810 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