Jump to content

How do autoit3 dllcall function of the shapelib.dll


firewzy
 Share

Recommended Posts

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.rar

shapelib_vc7.1_.rar

Edited by firewzy
Link to comment
Share on other sites

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

DBFAddField 
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 by FreeSiker
Link to comment
Share on other sites

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.

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.

Edited 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

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:

post-27637-1197783919_thumb.jpg

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

  • Moderators

ding

I'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

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

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

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 by firewzy
Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...

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 Pickard

http://arcscripts.esri.com/details.asp?dbid=11810

Link to comment
Share on other sites

  • 1 year later...

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,

Guoyuan

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 Pickard

http://arcscripts.esri.com/details.asp?dbid=11810

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...