Whats the proper way to use an external DLL?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    Whats the proper way to use an external DLL?

    I have been asked to try and get my access database to "speak" with an external third party application, ProjectWise.

    This involves using a dll, that comes with projectwise, dmactrl.dll.

    However its not one I can simply register as a reference and use, but I can use with the following syntax:

    Code:
    Public Declare Function aaApi_MessageBox _
                            Lib "dmactrl.dll" ( _
                            ByVal strText As String, _
                            ByVal lPRojectID As Long) _
                            As Long
    My problem is the following: When I try to use(run) the aaApi_MessageBo x function i get an error:
    Run Time Error 53
    File Not Found: dmactrl.dll
    If I try to the dll as a reference by Tools->References and browse for it, i get the error (When adding ref):
    Can't add a reference to the specified file
    The odd part is that if I run my code now, it will work without the previously mentioned error 53.


    I have no experience working with external dlls, and I really have no idea why one is working and why one isn't, and even worse, I have no idea how to be able to fix it into a version I can actually present to the client, I.E. a solution that does not involve having to try and fail to register the dll each time.

    Can anyone shed some light on the behavior explained, and hopefully on how to proceed from here?
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    1. Is your Declaration in a Standard Code Module?
    2. How, exactly, are you 'Calling' the Function?
    3. Where, exactly, is the .dll (dmactrl.dll) physically located?

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32645

      #3
      I would expect your code to work if either :
      1. dmactrl.dll were in a default folder for libraries.
      2. You give the full path for dmactrl.dll.


      Let us know how you get on with that Smiley.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32645

        #4
        It may be a good idea to check with ProjectWise either for some documentation or advice (depending on what's available) on how the software should be installed. Sometimes such libraries will work by just being found available, but nevertheless the correct procedure is to run an installation package. Such a package aught to ensure the file is placed in a workable folder.

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Here are a couple of additional thoughts:
          1. Not all .DLLs are Self Registering. Have you tried to manually Register dmactrl.dll?
            Code:
            Regsvr32 "<PATH to dmactrl.dll>"
          2. Have you tried doing multiple searches for dmactrl.dll in the Registry? There should be multiple References to it, including its PATH, such as:
            Code:
            %SystemRoot%\System32\dmactrl.dll

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            @ Post #2:
            1) Yes its in a standard module
            2) An example of calling the function:
            Code:
            Public Declare Function aaApi_MessageBox _
                                    Lib "dmactrl.dll" ( _
                                    ByVal strText As String, _
                                    ByVal lPRojectID As Long) _
                                    As Long
            
            Public Sub testMsgBox()
                Dim lngReply As Long
                lngReply = aaApi_MessageBox(StrConv("Testing", vbUnicode), 1)
                MsgBox "User pressed: " & lngReply
            End Sub
            Now this will fail as mentioned earlier, but succeed if I have first tried and failed to register it as a reference by Tools->Reference->Browse
            3) Its standard location is the PW SDK folder:
            C:\Program Files\Bentley\P rojectWise V8i\bin\dmactrl .dll
            I have also tried to place it in the access folder where the mdb is, as well in C:\Windows\Syst em32


            @ Post #3:
            1) I don't know what the default library is/should be, but I have tried the locations mentioned above
            2) I have tried to use the declare where I included the full path, but it still says "File Not found"


            @ Post #4:
            I have installed the PW SDK but frankly the documention on PW makes the access help files look like a verbose Written for Dummies guide, and there is very little help in the form of forums like Bytes to help a newbie getting started. That said I have started a thread on their webforum as well, but with no results so far.


            @ Post #5:

            First off, I don't know all that much about the system registry.
            1) I have tried to register it using:
            Code:
            regsvr32 "C:\Program Files\Bentley\ProjectWise V8i\bin\dmactrl.dll"
            and get this message back, which sadly doesn't mean a whole lot to me:
            C:\Program Files\Bentley\P rojectWise V8i\bin\dmactrl .dll was loaded but the DllRegisterServ er entry point was not found.
            This file can not be registered.
            2) I will try that.




            Hope I managed to answer all your points, and thank you very much for your keen input.

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              @TheSmileyCoder :
              1. Have you recently Rebooted your PC, if not, do so since there may be a corrupt Version of dmactrl.dll in Memory.
              2. Have you tried to Register this .dll while logged on with an Administrative Account, with full Privileges? You probably will need to be an Administrator to properly Register the .dll.
              3. I cannot locate dmactrl.dll on the Web to download, can you Upload us a Copy? This would make things much easier on our end.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32645

                #8
                Nice response Smiley :-)

                Always nice to work with a pro.

                Comment

                • heiderstadtrg
                  New Member
                  • Aug 2013
                  • 1

                  #9
                  The function will fail unless the ProjectWise SDK is initialized prior to use.

                  Try this:
                  Code:
                  Public Const AAMODULE_TOOLS As Int32 = &H100L
                  Public Declare Function aaApi_Initialize Lib "dmscli.dll" (ByVal ulModule As Int32) As Boolean
                  and then:
                  Code:
                  bRet = aaApi_Initialize(AAMODULE_TOOLS)
                  If you execute the aaApi_MessageBo x function now, it should work correctly.
                  Last edited by zmbd; Aug 7 '13, 08:09 PM. Reason: [z{placed code tags}]

                  Comment

                  • TheSmileyCoder
                    Recognized Expert Moderator Top Contributor
                    • Dec 2009
                    • 2322

                    #10
                    Hi, thank you for your post. I will give it a try. :)

                    Comment

                    • TheSmileyCoder
                      Recognized Expert Moderator Top Contributor
                      • Dec 2009
                      • 2322

                      #11
                      Hi. So I tried to modify your suggestion to work with VBA, making it look like so:
                      Code:
                      Public Const AAMODULE_TOOLS As Long = 256
                      Public Declare Function aaApi_Initialize Lib "C:\Program Files (x86)\Bentley\ProjectWise\bin\dmscli.dll" (ByVal ulModule As Long) As Boolean
                      
                      Public Sub Test()
                         Dim bRet As Long
                         bRet = aaApi_Initialize(AAMODULE_TOOLS)
                         Debug.Print "bret:" & bRet
                      End Sub
                      It returns with an Error 53 - File not found. I recall someone having a similar error on another unrelated project, and the cause being not having Visual Studio installed while the DLL using dynamic linking (I believe so, its been a while, and I am not used to working with dlls)

                      Comment

                      • ianadd
                        New Member
                        • Nov 2013
                        • 2

                        #12
                        where to put DLL

                        Did you resolve this? I have a very similar issue.
                        Ian
                        Last edited by zmbd; Nov 26 '13, 11:09 PM. Reason: [z{no edit: Perhaps you will start a new thread with your question?}]

                        Comment

                        • TheSmileyCoder
                          Recognized Expert Moderator Top Contributor
                          • Dec 2009
                          • 2322

                          #13
                          No I never got Projectwise to work in a satisfying manner. In the end I was able to get limited success from going directly to the SQL server on which projectwise runs, but I never got satisfying results from projectwise.

                          Comment

                          Working...