3

I have a DLL file that I have loaded and registered it in ArcGIS as a command icon. This icon launches a window where the user should do the following selections: an input file, a field name, select between 2 option buttons and an output file name. However, I need to run this DLL file via a VBA and ArcObjects code so as the user will not see the window of the DLL tool and the above selections will be given automatically by the code within a loop so as to take various output files. Is that possible? Please help. Thanks Demetris

Eventually I found a function that may be is approprite to call the DLL file. I declare it below and I try to call it via the Calldll() procedure. However, I receive the following message "Run-time error 13- Type mismatch". I think that the arguments have the appropriate data type. Could you please have a look in the code below to find what is going on? Thanks again Demetris

 Public Declare Function CreateParcelsShape Lib "C:\Program    Files\ArcGIS\CreatePoly.dll" (Centroids As IFeatureClass, Block As  IPolygon, pFDS As IFeatureDataset)

Public Sub CallDll()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

'Get the active map (data frame)
Dim pMap As IMap
Set pMap = pMxDoc.FocusMap

'Get the layers
Dim pLayers As IEnumLayer
Set pLayers = pMap.Layers

Dim pLayer1 As ILayer
Set pLayer1 = pLayers.Next


Do Until pLayer1 Is Nothing

  If pLayer1.Name = "Block12" Then
    Exit Do

  End If

Set pLayer1 = pLayers.Next
Loop


Dim pBlocks As IFeatureLayer
Set pBlocks = pLayer1

Dim pBlocksFC As IFeatureClass
Set pBlocksFC = pBlocks.FeatureClass


Dim pBlocksCursor As IFeatureCursor
Set pBlocksCursor = pBlocksFC.Search(Nothing, False)

Dim pBlockFeature As IFeature
Set pBlockFeature = pBlocksCursor.NextFeature

'Get the shape of the polygon (Block)
Dim polygon As IPolygon
Set polygon = pBlockFeature.Shape

Dim pLayers2 As IEnumLayer
Set pLayers2 = pMap.Layers

Dim pLayer2 As ILayer
Set pLayer2 = pLayers2.Next

Do Until pLayer2 Is Nothing


If pLayer2.Name = "CentroidsBlock12" Then
Exit Do

End If

Set pLayer2 = pLayers2.Next
Loop

Dim pCentroids As IFeatureLayer
Set pCentroids = pLayer2

Get the dataset
Dim pFDataSet As IFeatureDataset
Dim pFWorkspace As IFeatureWorkspace
Dim pAWFactory As IWorkspaceFactory

Set pAWFactory = New AccessWorkspaceFactory
Set pFWorkspace = pAWFactory.OpenFromFile("C:\LACONISS\GAPopulation.mdb", 0)
Set pFDataSet = pFWorkspace.OpenFeatureDataset("Polygons")

'Call the DLL function
CreateParcelsShape pCentroids, polygon, pFDataSet

End Sub
13
  • 1
    It sounds to be a question for StackOverflow.com
    – Jonas
    Commented Oct 2, 2011 at 20:51
  • 1
    I don't think I fully understand what you are trying to do. Could you clarify you question? Is this a library that you have developed and compiled in VS? Have you tried adding it to VBA references? Commented Oct 3, 2011 at 0:24
  • 2
    Without the source code or knowing the internal API, I think you will be a bit lost trying to manipulate a foreign binary DLL.
    – Mike T
    Commented Oct 3, 2011 at 6:48
  • 2
    Try contacting the author to see if it is possible to either call the library externally, or if it has a Component Object Model (COM) interface that can be registered and referenced
    – Mike T
    Commented Oct 3, 2011 at 9:09
  • 2
    It sounds like your real problem is "How can I create Thiessen Polygons without an Arcinfo license?", and I encourage you to ask just that in a seperate question, and leave this one to specifics of calling external DLLs from vba. Commented Oct 5, 2011 at 17:11

2 Answers 2

4
+25

It looks like CreateThiessenPoly.dll has a DllRegisterServer hook, so it is a DLL COM file, which means you can directly reference it from VBA. Note: I used Dependency Walker to determine that you may need msvbvm60.dll from vbrun60.cab (the module was programmed/compiled from Visual Basic 6.)

From the VBA development environment (I'm actually using Excel's, tested again on a Win32 computer with ArcInfo 9.3), you should go to: Tools > References..., and browse to CreateThiessenPoly.dll. This will add a reference to "TgisThPoly".

Tools, References

References

Unfortunately, I don't see anything too interesting in the module:

Object Browser

Furthermore, you can create an instance of the class, but it doesn't have any publicly accessible members, so there is nothing we can do with it. The following code runs from VBA in ArcInfo 9.3 without any errors:

Option Explicit
Sub test()
    Dim tp As New clsThPoly
    MsgBox "Nothing here, move along"
End Sub

Maybe you might see something different from another VBA environment (e.g., if registered/used from Visual Basic 6.0, or from ArcGIS 8.1). The DLL probably has many more private functions, which we cannot get to in any way.

Your best option is to find a different approach altogether, which would be best addressed in a separate question, e.g., as matt suggests: "How can I create Thiessen Polygons without an Arcinfo license?"

8
  • This dll was posted to arcscripts in 2003. If clsThPoly implements the ICommand interface from arcgis 8.1 or whatever, wouldn't this explain the behavior you're seeing if you don't have 8.1 installed? Commented Oct 5, 2011 at 13:12
  • Mike, thanks for the effort. However, it is still not clear the scene for me.Why I cannot find the clsThPoly in ESRI Object Browser? I cannot also find the Tools>Refernces in EXCEL or something similar in ArcGIS;and the conclusion is that I can use it or not? I found in this link forums.esri.com/… a function that it is supposed it runs the ThiessenPoly.DLL as I understood. As you may see above I note the code for running the function but I get a type mismatch error. What do you think? Kirk, I use 9.3 and I am not sure for your remark.
    – Demetris
    Commented Oct 5, 2011 at 15:49
  • 1
    Mike's answer is correct. The ESRI object browser will only show you objects that are registered in the right component category (did it come with a separate reg file???)Kirk's remark is very valid, too. You could be dealing with a pre-9 dll and it would not work since the object libraries got refactored for 9.0 My question to you is why are you trying to do this. If it is to create Thiessen polygons, this equivalent to driving from LA to Vegas, with a minor bathroom stop in Taiwan. Commented Oct 5, 2011 at 16:29
  • @Demetris nothing in the code in the linked thread references a DLL, it's all ArcObjects. Can you not use the function they provided instead of the DLL?
    – blah238
    Commented Oct 5, 2011 at 17:08
  • 1
    It does implement ICommand, but you cannot see its methods in the Object Browser because ICommand is not the default interface. VB Object Browser shows only members of the class' default interface, which is generated automatically for libraries written in VB and in this case this default interface has no members. Anyway, you can only execute the command and that's just about it. You have no way to alter the original code behavior to suit your needs.
    – Petr Krebs
    Commented Oct 5, 2011 at 20:05
1

If you have ArcGIS 10, with an ArcInfo license, you can run Analysis Tools, Proximity, Create Thiessen Polygons.

Or use the free OpenJump GIS to create Thiessen Polygons.

1
  • Thanks. I know what are you saying; however I need the code to incorporate it in my own program.
    – Demetris
    Commented Oct 5, 2011 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.