Hello,
I need to use AAAPI_IMPORTACCESSCONTROL in C#.
In the wrapper I did this...
[DllImport("dmawin.dll", CharSet = CharSet.Unicode)]public static extern int aaApi_ImportAccessControl ( Guid iguid, string ifilename, int iformat, int ilevels, int iflags);
In the function using the wrap, I use the folder GUID as a GUID, 2 for CSV, 0 for all Levels, and 0 for flags.
The GUID is correct and the CSV is a valid CSV file previously exported from folder Access Control in Project Wise Explorer.
Error: Attempted to read or write protected memory.
What is incorrect or missing?
Thanks for your patience.
Kevin.
I have had more success using the following structure in place of System.Guid
/// <summary> /// C style GUID structure /// </summary> [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct GUID { /// unsigned int public uint Data1; /// unsigned short public ushort Data2; /// unsigned short public ushort Data3; /// unsigned char[8] [MarshalAs(UnmanagedType.ByValArray, SizeConst = 8)] public byte[] Data4; }
and in the wrapper class for the ProjectWise Functions I have the following helper functions to convert between System.Guid and GUID
public static class PWNative { // ... ProjectWise Function wrappers e.g. [DllImport(@"dmscli.dll", CharSet = CharSet.Unicode, EntryPoint = "aaApi_GUIDSelectDocumentDataBuffer")] public static extern IntPtr aaApi_GUIDSelectDocumentDataBuffer(ref GUID pDocGuid); //--------------------------------------------------------------------- // Helper functions //--------------------------------------------------------------------- #region Helper functions /// <summary> /// Retrieves a System.Guid from a pointer to a GUID structure. /// </summary> /// <param name="pointer">A pointer to a GUID return value</param> /// <returns> /// <list type="definition"><item> /// <term>Empty System.Guid</term><description>If pointer is IntPtr.Zero</description> /// </item><item> /// <term>Otherwise</term><description>The value pointed to as a System.Guid</description> /// </item></list> /// </returns> public static Guid GetGuidFromPointer(IntPtr pointer) { if (pointer != IntPtr.Zero) { try { var guid = (GUID) Marshal.PtrToStructure(pointer, typeof (GUID)); return FromGUID(guid); } catch (Exception) { return Guid.Empty; } } return Guid.Empty; } /// <summary> /// Converts a C style GUID to a System.Guid /// </summary> /// <param name="value">The C style GUID</param> /// <returns>A System.Guid equivalent</returns> public static Guid FromGUID(GUID value) { return new Guid((Int32)value.Data1, (Int16)value.Data2, (Int16)value.Data3, value.Data4); } /// <summary> /// Converts a System.Guid to a C style GUID structure /// </summary> /// <param name="value">The System.Guid to convert</param> /// <returns>A C style GUID equivalent of the System.Guid</returns> public static GUID ToGUID(Guid value) { GUID result = new GUID(); byte[] bytes = value.ToByteArray(); result.Data1 = BitConverter.ToUInt32(bytes, 0); result.Data2 = BitConverter.ToUInt16(bytes, 4); result.Data3 = BitConverter.ToUInt16(bytes, 6); result.Data4 = new byte[8]; for (int i = 8; i < bytes.Length; i++) { result.Data4[i - 8] = bytes[i]; } return result; } /// <summary> /// Gets a string representation f a C style GUID structure /// </summary> /// <param name="guidStructure">The C style GUID structure</param> /// <returns>A string representation of the GUID</returns> public static string StringFromGUID(GUID guidStructure) { Guid guid = FromGUID(guidStructure); return guid.ToString("D"); } #endregion }