Call a DLL script from VBA and ArcObjects code

1940
8
10-02-2011 02:02 AM
DemetrisDemetriou
New Contributor
I have a DLL script that launches a window where the user should may 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 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 within a loop so as to take various output files. Is that possible? Please help.
Thanks Demetris
Reply
0 Kudos
8 Replies
NeilClemmons
Regular Contributor III
If the code inside the dll displays a window then simply calling it from VBA will not change that.  What you can and can't do all depends on what is in the dll.  If the dll contains object classes then you can use those classes by referencing the dll in the VBA project.  If the dll contains public methods then you can call those methods by adding a Declare statement for each method inside your VBA project.
Reply
0 Kudos
DemetrisDemetriou
New Contributor
Thanks for the information. I note the following relevant details that may help:

I try to use the Thiessen Polygon 3.0 DLL downloaded from the link arcscripts.esri.com/details.asp?dbid=11958. This DLL creates Thiessen polygons. I have already placed this DLL in a toolbar that works fine. However, I need to incorporate it within a loop of the VBA code and I do not know any functions, procedures included in the DLL. However, I found a  relevant function from archives postings  http://forums.esri.com/Thread.asp?c=93&f=992&t=107377 and I used it as shown in code below. In particular, I declare it and I try to call it via the Calldll() procedure and I receive the following message "Run-time error 13- Type mismatch". I think that the arguments of the function match with the appropriate data type provided. Could you please have a look in the code below to find what is going on?
Any more help, will be appreciate it.



  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
Reply
0 Kudos
NeilClemmons
Regular Contributor III
In your Declare statement the first parameter is of type IFeatureClass.  When you call the method in your code the first parameter you're passing in is of type IFeatureLayer.  That's a type mismatch - IFeatureClass and IFeatureLayer are not the same type.
Reply
0 Kudos
DemetrisDemetriou
New Contributor
Neil,
Thanks you are right. However, I have a new message now : "Run-time error 453-Can't find DLL entry point in C:\....*.DLL. I think that this acttually means that this function cannot run the DLL. Is that right? How can I find the so called "Entry point"?
Thanks
Reply
0 Kudos
NeilClemmons
Regular Contributor III
I downloaded the dll and looked at it in the Visual Studio object browser.  It appears to contain a single class - the command class that you can use in ArcMap.  It doesn't appear to have any public methods exposed other than those on the ICommand interface.  It looks like what you are trying to do is not possible with this dll.
Reply
0 Kudos
DemetrisDemetriou
New Contributor
Thanks Neil.
So, I can use this DLL only as a command icon within ArcGIS? In this case, how can I find its GUID so as to run it through VBA using the Execute method of the ICommandItem interface?
Reply
0 Kudos
NeilClemmons
Regular Contributor III
If the dll has been registered on your machine you can look it up in the registry.  You can also use the ProgId of the command instead of the GUID.  The ProgId is the library name and the class name separated by a period (i.e. esriCarto.FeatureLayer).  You can find these names by adding the dll as a reference to your VBA project and using the object browser.
Reply
0 Kudos
DemetrisDemetriou
New Contributor
Ok. Thanks.
Reply
0 Kudos