Simple VBA app for accessing ProjectWise

I took a sample application from the Bentley Developer Network and stripped it down to a very simple test application to make sure I could connect to ProjectWise from VBA (code below).  There is no error checking going on here and I usually run it while debugging to validate the return values but someone may find this useful.  Note that you would have to change the user name and password information.  My test is setup for single sign-on.

I do have a question that I'm hoping someone can help me with.  If MicroStation SS3 gets launched by opening a file from ProjectWise Explorer then this test app runs fine.  If I just launch MicroStation and then try and run this app I get a "File not found: dmscli.dll" error message.  I thought maybe I needed to go to Tools, References and add dmscli.dll as a reference but I get a "Can't add a reference to the specified file" message.

I've looked thru the ProjectWise SDK documents and searched on-line for dmscli.dll and didn't find an answer.  Anyone know what I need to add or change to get it to find dmscli.dll everytime?

Thanks,

Mike

 

Option Explicit

Public Declare Function aaApi_Initialize Lib "dmscli.dll" (ByVal ulModule As Long) As Integer
Public Declare Function aaApi_Login Lib "dmscli.dll" (lDSType As Long, ByVal lptstrDataSource As String, ByVal lpctstrUsername As String, ByVal lpctstrPassword As String, ByVal lpctstrSchema As String) As Long
Public Declare Function aaApi_DmsDataBufferSelect Lib "dmscli.dll" (ByVal lDmsBufferType As Long) As Long
Public Declare Sub aaApi_DmsDataBufferFree Lib "dmscli.dll" (ByVal lDataBuffer As Long) ' $$$ CRITICAL that this is ByVal, if not it crashes MicroStation badly

Public Enum DataSourceTypes
    AAAPIDB_UNKNOWN = 0
End Enum

Const AAMODULE_ALL As Long = 0
Const AADMSBUFFER_PROJECT As Long = 18

Public Sub Login(lngDataSourceType As DataSourceTypes, strLoginDataSourceName As String, strLoginUserName As String, strLoginPassword As String)
    Dim lOK As Long

    lOK = aaApi_Login(lngDataSourceType, StrConv(strLoginDataSourceName, vbUnicode), StrConv(strLoginUserName, vbUnicode), StrConv(strLoginPassword, vbUnicode), "")
End Sub

Sub BDNzineCheckOutAndProcessFiles()
    Dim status  As Long
    Dim projectDatabuffer As Long
   
    ' Initialze ProjectWise connection
    status = aaApi_Initialize(AAMODULE_ALL)
       
    ' User Name and password blank for Windows single sign-on
    Login AAAPIDB_UNKNOWN, "projectwise:projectwise", "", "" ' <<< Must change user and password

    ' Load buffer with project info
    projectDatabuffer = aaApi_DmsDataBufferSelect(AADMSBUFFER_PROJECT)
   
    ' Free the buffer just allocated
    aaApi_DmsDataBufferFree projectDatabuffer
End Sub

 

  • Mike, try putting the path to the ProjectWise bin folder in your system PATH variable.  This has helped me with a similar issue in the past.

  • Thanks Dean.  

    I did get this working and meant to come back here and document it.  Since I was having touble with VBA I ended up writing a C++ DLL to call ProjectWise and then called my DLL from ProjectWise.  I had trouble with this running as well.  

    What fixed the DLL problem was I added $(PWBIN) to the MS_LIBRARY_PATH configuration variable via Workspace, Configuration.

    After I made that change the VBA program ran the next time I tried it.  It's possible some other change I made was the cure but I think it was the configuration variable change that allowed the VBA program to run.

    This solution is very similar to yours only I change a MicroStation variable rather than a system settings.

    Mike

  • I've problem with aaApi_DmsDataBufferSelect(AADMSBUFFER_PROJECT). It always returns 0. The login is successful.
  • FWIW, I don't encourage the practice of not testing for valid return values which the above code for a "simple VBA app" does not have. The author mentions that this is lacking because the posted code was only intended for "testing". The author also mentions that he launches this code in two different ways, and "surprisingly", it behaves in two different ways. You don't mention how you are running your code.

    You should always check for "bad" data and invalid results and respond accordingly. The documentation explains that the "specific error code can be retrieved using aaApi_GetLastErrorId()". You can also use aaApi_GetLastErrorMessage() and aaApi_GetLastErrorDetail() to get meaningful information on why the call did not return a valid handle. That should give you a clue on why you aren't getting the results that you expected.

    Since you didn't post any code, I'll assume that you are trying to "run" the posted code for "simple VBA app". There are several problems with that app as posted. First of all, you need to initialize the APIs before you use them, the code has a routine to login and in another routine, it initializes the APIs, and tries to copy a buffer that my not yet be populated. Depending upon how the code is being called (after starting MicroStation outside of ProjectWise or after launching MicroStation from within ProjectWise), you may or may not need to call aaApi_Initialize() (as it may have already been called), but I suspect that either way, you can't copy a buffer that doesn't exist yet.

    If you are trying to learn how to use the ProjectWise SDK, starting with VBA probably isn't the best approach. You really need to understand how the APIs work, in order to use them from VBA. Trying to make them work from VBA without understanding how they work or their dependencies, is going to be a bit frustrating. Depending upon what you are trying to do, you might find the ProjectWise PowerShell Cmdlets a bit easier to use, but they don't support all the functionality of the ProjectWise SDK.