C# aaApi_MonikersToStrings not working PW address to folder

I have a stand alone C# application that performs some things at a folder location. I am updating it to now work for a projectwise folder location.

the user hits a search button in the application window which brings up a folder select dialog. after selecting the folder the folder path to placed in a label in the application.

I was able to up the application to bring up a projectwise select project dialog. I then use the aaApi_GetProjectMonikers and aaApi_MonikersToStrings api calls to take the returned folderID to get the full PW address to the file but I'm having some trouble with the aaApi_MonikersToStrings call. Even though both aaApi_GetProjectMonikers and aaApi_MonikersToStrings return true the out variable in the aaApi_MonikersToStrings stays null. heres the code after getting the folderID

//get project moniker
                        int[] array = new int[1];
                        int[] moniker = new int[1];
                        array[0] = MyGlobals.selectedProjID;
                        GCHandle handle = GCHandle.Alloc(array, GCHandleType.Pinned);
                        GCHandle handle2 = GCHandle.Alloc(moniker, GCHandleType.Pinned);
                        try
                        {
                            StringBuilder[] ProjString = new StringBuilder[1];
                            IntPtr pointer = handle.AddrOfPinnedObject();
                            IntPtr pointer2 = handle2.AddrOfPinnedObject();
                            bool gotProjMoniker = PWWrappers.aaApi_GetProjectMonikers(1, pointer, pointer2);
                            uint flags = 0x00000001;
                            bool gotProjString = PWWrappers.aaApi_MonikersToStrings(1, pointer2, ProjString, flags);
                            //string projString = Marshal.PtrToStringAnsi(Projptr);
                        }
                        finally
                        {
                            if (handle.IsAllocated)
                            {
                                handle.Free();
                            }
                            if (handle2.IsAllocated)
                            {
                                handle2.Free();
                            }
                            PWWrappers.aaApi_Free(null);
                        }

here are my wrappers

        [DllImport("c:\\Program Files\\Bentley\\ProjectWise\\bin\\dmawin.dll", CharSet = CharSet.Unicode)]
        public static extern int aaApi_SelectProjectDlg(IntPtr hWndParent, StringBuilder lpctstrTitle, int lProjectID);
        
        [DllImport("c:\\Program Files\\Bentley\\ProjectWise\\bin\\dmscli.dll")]
        public static extern bool aaApi_GetProjectMonikers(int lItemCount, IntPtr projectIds, IntPtr pMonikers);
        
        [DllImport("c:\\Program Files\\Bentley\\ProjectWise\\bin\\dmscli.dll", CharSet = CharSet.Unicode)]
        public static extern bool aaApi_MonikersToStrings(int monikerCount, IntPtr monikers, StringBuilder[] strings, uint flags);

I must be doing something wrong. Still don't understand why its so hard to get the full path to folder.

Parents
  • I've never really had a fun time interacting with the moniker functions in C#. I'd suggest using some different functions to achieve the same (though arguably easier and cleaner) results.

    StringBuilder folderPath = new StringBuilder(1024);
    StringBuilder datasource = new StringBuilder(1024);
    aaApi_GetProjectNamePath2(folderId, false, '\\', folderPath, folderPath.Capacity);
    aaApi_GetActiveDatasourceName(datasource, datasource.Capacity);
    String pwPath = $@"pw:\\{datasource}\Documents\{folderPath}\"; //the path to your folder will be stored here

    Wrapped functions:

    [DllImport(@"C:\Program Files\Bentley\ProjectWise\bin\dmscli.dll", CharSet = CharSet.Unicode)]
    public static extern bool aaApi_GetActiveDatasourceName(StringBuilder lptstrName, int lNameSize);
    
    [DllImport(@"C:\Program Files\Bentley\ProjectWise\bin\dmscli.dll", CharSet = CharSet.Unicode)]
    public static extern bool aaApi_GetProjectNamePath2(int lProjectId, bool bUseDesc, char tchSeparator, StringBuilder lptstrBuffer, int lBufferLen);

    Hope this helps!

  • That's actually what I have been using. but I cant make the assumption that the first folder inside the datasource is called Documents. As I have seen it named differently. For now I'm just putting /../ instead of Documents since this path isn't used for anything except letting the user see what they selected it doesn't cause any problems.

    thanks though

    really would love to know if anyone has gotten the moniker approach to work for getting the full address.

Reply
  • That's actually what I have been using. but I cant make the assumption that the first folder inside the datasource is called Documents. As I have seen it named differently. For now I'm just putting /../ instead of Documents since this path isn't used for anything except letting the user see what they selected it doesn't cause any problems.

    thanks though

    really would love to know if anyone has gotten the moniker approach to work for getting the full address.

Children
No Data