I need to set the environment on a new folder using C#, but I get an invalid parameter error.
I assume I have defined the _AADMSPROJITEM structure wrong, or confused variables with pointers or similar.
I hoped that Dave Brumbaugh had done this already, but it is not in his PWWrapper.
// define C style _AADMSPROJITEM structure [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct _AADMSPROJITEM { public ulong ulFlags; // This member is the bit mask specifying which of the structure members contains valid information. public long lProjectId; // Specifies the project Id. public long lEnvironmentId; //Specifies the environment the project belongs to. public long lParentId; // Specifies the parent project identifier. public long lStorageId; // Specifies the default storage of the project. public long lManagerId; //Specifies the project manager's Id. public long lTypeId; //Specifies project's type. public long lWorkflowId; //Specifies the workflow identifier assigned to the project. public IntPtr lptstrName; //Pointer to a null-terminated string specifying the project name. LPWSTR public IntPtr lptstrDesc; //Pointer to a null-terminated string specifying the project description. LPWSTR public long lManagerType; //Specifies the type of project manager. public long lWorkspaceProfileId; // Specifies the type of project workspace profile. public GUID guidVault; //Specifies the GUID of project. public long lComponentClassId; //Specifies the class id of the ODS instance holding rich project properties. public long lComponentInstanceId; // Specifies the instance id of the ODS instance holding rich project properties. public ulong projFlagMask; // Specifies the valid bits in the member projFlags. public ulong projFlags; // Specifies the project flags to set or reset. }
public static Boolean SetProjectEnvironment(int projectID, int environmentenvID) { _AADMSPROJITEM pProject = new _AADMSPROJITEM(); pProject.lProjectId = projectID; pProject.lEnvironmentId = environmentenvID;; return aaApi_ModifyProject2( pProject); }
[DllImport("c:\\Program Files\\Bentley\\ProjectWise\\bin\\dmscli.dll")]public static extern Boolean aaApi_ModifyProject2(_AADMSPROJITEM lpProject);
The SDK documentation lists _AADMSPROJITEM not AADMSPROJITEM and this has the 4 extra fields.
However it seems that the shorter definition Dan gives works as follows:
const int AADMSPROJF_PROJECTID = 0x00000001; // If set, lProjectId member contains valid information. const int AADMSPROJF_ENVID = 0x00000002; // If set, lEnvironmentId member contains valid information. AADMSPROJITEM pProject = new AADMSPROJITEM(); pProject.lProjectId = projectID; // Specifies the project Id. pProject.lEnvironmentId = environmentenvID; ; // Specifies the environment the project belongs to. pProject.ulFlags = AADMSPROJF_PROJECTID | AADMSPROJF_ENVID; // Specifies the project flags to set or reset. if( PW.aaAPI.aaApi_ModifyProject2(pProject) ) { ... it worked ....
I didn't find the code in MostOfDavesClasses because I had forgotten that Vaults were the same as folders.
I'm happy to hear that you got it working! Yeah, the documentation can be hard to interpret at times ("words get in the way"), but if you can find it in Dave's code, then it is very likely to be the way it works since over the years, he put things in that he needed to use, so it had to be right, at least at the time he added it!