public static T[] NetServerEnum <T>(ServerTypes serverTypes = ServerTypes.Workstation | ServerTypes.Server, string domain = null, int level = 0) where T : struct { if (level == 0) { level = int.Parse(System.Text.RegularExpressions.Regex.Replace(typeof(T).Name, @"[^\d]", "")); } IntPtr bufptr = IntPtr.Zero; try { int entriesRead, totalEntries; IntPtr resumeHandle = IntPtr.Zero; int ret = NetServerEnum(null, level, out bufptr, MAX_PREFERRED_LENGTH, out entriesRead, out totalEntries, serverTypes, domain, resumeHandle); if (ret == 0) { return(InteropUtil.ToArray <T>(bufptr, entriesRead)); } throw new System.ComponentModel.Win32Exception(ret); } finally { NetApiBufferFree(bufptr); } }
/// <summary> /// Récupère les données d'une répétition d'un champ. /// Les champs et répétitions sont stocké(e)s à partir de l'indice 0 mais une base 1 est utilisée pour les accès. /// </summary> /// <param name="numField">Numéro du champ.</param> /// <param name="numRepetition">Numéro de la répétition.</param> /// <returns></returns> public IType GetField(int numField, int numRepetition) { if (numField <= 0) { throw new SegmentException("L'accès à un champ doit être réalisé à partir de l'index 1."); } if (numField > this._fields.Count) { throw new SegmentException($"Le champ {InteropUtil.ConstructFieldNumber(this.SegmentName, numField)} n'existe pas."); } if (numRepetition <= 0) { throw new SegmentException($"L'accès à une répétition du champ {InteropUtil.ConstructFieldNumber(this.SegmentName, numField)} doit être réalisé à partir de l'index 1."); } int currentRep = this._fields[numField - 1].Repetitions.Count; // Création d'une répétition si nécessaire et si limite maximale non atteinte if (numRepetition > currentRep) { if (numRepetition > this._fields[numField - 1].MaxRepetitions) { throw new SegmentException($"Impossible d'ajouter la répétition {InteropUtil.ConstructFieldNumber(this.SegmentName, numField, numRepetition)} : le nombre maximal autorisé de répétitions est de {this._fields[numField - 1].MaxRepetitions}."); } else { this._fields[numField - 1].Repetitions.Add(this.CreateNewSegmentItem(numField)); } } return(this._fields[numField - 1][numRepetition]); }
public LVCOLUMN(ListViewColumMask mask) { this.mask = mask; if (mask.IsFlagSet(ListViewColumMask.Text)) { InteropUtil.AllocString(ref pszText, ref cchTextMax); } }
public HDITEM(HeaderItemMask mask = HeaderItemMask.All) { if (mask.IsFlagSet(HeaderItemMask.Text)) { cchTextMax = 1024; InteropUtil.AllocString(ref pszText, ref cchTextMax); } }
public void Dispose() { InteropUtil.FreeString(ref pszText, ref cchTextMax); if (mask.IsFlagSet(HeaderItemMask.Filter) && (type == 0 || type == 2)) { Marshal.FreeHGlobal(pvFilter); } }
/// <summary> /// Encodes a provided message into a byte array. /// </summary> /// <param name="message">The message to be encoded.</param> /// <returns>The encoded message as byte array.</returns> public static byte[] EncodeMessage(Message message) { var encoder = new Encoder(null); AlternativeCompositeByteBuf buf = AlternativeCompositeByteBuf.CompBuffer(); encoder.Write(buf, message, null); return(InteropUtil.ExtractBytes(buf)); }
public LVBKIMAGE(ListViewBkImageFlag flags) { ulFlags = flags; if (ulFlags.IsFlagSet(ListViewBkImageFlag.SourceUrl)) { cchImageMax = 1024; InteropUtil.AllocString(ref pszImage, ref cchImageMax); } }
public void Dispose() { InteropUtil.FreeString(ref pszHeader, ref cchHeader); InteropUtil.FreeString(ref pszFooter, ref cchFooter); InteropUtil.FreeString(ref pszSubtitle, ref cchSubtitle); InteropUtil.FreeString(ref pszTask, ref cchTask); InteropUtil.FreeString(ref pszDescriptionBottom, ref cchDescriptionBottom); InteropUtil.FreeString(ref pszDescriptionTop, ref cchDescriptionTop); }
public LVITEM(int item, int subitem = 0, ListViewItemMask mask = ListViewItemMask.All, ListViewItemState stateMask = ListViewItemState.None) { if (mask.IsFlagSet(ListViewItemMask.Text)) { cchTextMax = 1024; InteropUtil.AllocString(ref pszText, ref cchTextMax); } iItem = item; iSubItem = subitem; this.stateMask = stateMask; }
public void TestEncodeByte() { var buffer = AlternativeCompositeByteBuf.CompBuffer(); // Java byte is signed for (int i = sbyte.MinValue; i <= sbyte.MaxValue; i++) // -128 ... 127 { buffer.WriteByte((sbyte)i); } var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
/// <summary> /// Encode un segment. /// </summary> /// <param name="segment">Segment à encoder.</param> /// <param name="encChars">Caractères d'encodage utilisés.</param> /// <returns></returns> public static string Encode(ISegment segment, EncodingCharacters encChars) { StringBuilder retSegment = new StringBuilder(); // Code du segment et premier séparateur de champ retSegment.Append(segment.SegmentName); retSegment.Append(encChars.FieldSeparator); // Si segment MSH : position de départ sur MSH-2 car MSH-1 correspond au séparateur de champ int startPos = InteropUtil.IsSegmentDefDelimiters(segment.SegmentName) ? 2 : 1; // Parcours des champs for (int i = startPos; i <= segment.Fields.Count; i++) { try { // Parcours des répétitions IType[] repetitions = segment.GetField(i); for (int j = 0; j < repetitions.Length; j++) { string repValue = PipeParser.Encode(repetitions[j], encChars); // Si MSH-2 : il faut annuler l'échappement des caractères réservés if (InteropUtil.IsSegmentDefDelimiters(segment.SegmentName) && i == 2) { repValue = EscapeCharacterUtil.Unescape(repValue, encChars); } retSegment.Append(repValue); if (j < repetitions.Length - 1) { retSegment.Append(encChars.RepetitionSeparator); } } } catch { throw; } retSegment.Append(encChars.FieldSeparator); } return(InteropUtil.RemoveExtraDelimiters(retSegment.ToString(), encChars.FieldSeparator)); }
private int DefViewSubClass ( IntPtr hWnd, uint uMsg, IntPtr wParam, IntPtr lParam, IntPtr uIdSubclass, uint dwRefData ) { if (uMsg == InteropUtil.WM_NOTIFY) { InteropUtil.NMHDR header = (InteropUtil.NMHDR)Marshal.PtrToStructure(lParam, typeof(InteropUtil.NMHDR)); if (header.code == InteropUtil.LVN_ITEMCHANGED && header.hwndFrom != IntPtr.Zero && header.idFrom == 1) { InteropUtil.NMLISTVIEW nmListView = (InteropUtil.NMLISTVIEW)Marshal.PtrToStructure(lParam, typeof(InteropUtil.NMLISTVIEW)); bool oldSelected = (nmListView.uOldState & InteropUtil.LVIS_SELECTED) != 0; bool newSelected = (nmListView.uNewState & InteropUtil.LVIS_SELECTED) != 0; if (!oldSelected && newSelected) { if (!m_suppressSelectionChange) { //the item went from not selected to being selected //so we want to look and see if the selected item is a folder, and if so //change the text of the item box to be the item on the folder. But, before we do that //we want to make sure that the box isn't currently focused. IntPtr hParent = hWnd.GetParent(); IntPtr hFNCombo = hParent.GetDlgItem(InteropUtil.ID_FileNameCombo); IntPtr hFNEditBox = hParent.GetDlgItem(InteropUtil.ID_FileNameTextBox); IntPtr hFocus = InteropUtil.GetFocus(); if ( (hFNCombo == IntPtr.Zero || hFNCombo != hFocus) && (hFNEditBox == IntPtr.Zero || hFNEditBox != hFocus) ) { SetFileNameToSelectedItem(header.hwndFrom, hFNCombo, nmListView.iItem); } } m_suppressSelectionChange = false; } } } return(hWnd.DefSubclassProc(uMsg, wParam, lParam)); }
/// <summary> /// Récupère les donnés d'un champ. /// Les champs sont stockés à partir de l'indice 0 mais une base 1 est utilisée pour les accès. /// </summary> /// <param name="numField">Numéro du champ.</param> /// <returns>Tableau de longueur 1 pour les champs non répétables, et > 1 pour les champs répétables.</returns> public IType[] GetField(int numField) { try { if (numField > 0) { return(this._fields[numField - 1].ConvertRepetitionsToITypeArray); } else { throw new SegmentException("L'accès à un champ doit être réalisé à partir de l'index 1."); } } catch (ArgumentOutOfRangeException) { throw new SegmentException($"Le champ {InteropUtil.ConstructFieldNumber(this.SegmentName, numField)} n'existe pas."); } }
/// <summary> /// Encode du type de données. /// </summary> /// <param name="type">Type de données à encoder.</param> /// <param name="encChars">Caractères d'encodage utilisés.</param> /// <param name="subComponent">Indique si l'on encode un sous-composant.</param> /// <returns></returns> public static string Encode(IType type, EncodingCharacters encChars, bool subComponent = false) { StringBuilder retType = new StringBuilder(); if (type is ITypePrimitive) { ITypePrimitive primitive = type as ITypePrimitive; if (primitive == null) { throw new EncodingException("Une erreur s'est produite à la conversion de 'IType' vers 'ITypePrimitive'."); } else { retType.Append(PipeParser.Encode(primitive, encChars)); } } else { ITypeComposite composite = type as ITypeComposite; if (composite == null) { throw new EncodingException("Une erreur s'est produite à la conversion de 'IType' vers 'ITypeComposite'."); } else { StringBuilder retComp = new StringBuilder(); char compDelimiter = subComponent ? encChars.SubComponentSeparator : encChars.ComponentSeparator; for (int i = 0; i < composite.Components.Length; i++) { retComp.Append(PipeParser.Encode(composite.Components[i], encChars, true)); if (i < composite.Components.Length - 1) { retComp.Append(compDelimiter); } } retType.Append(InteropUtil.RemoveExtraDelimiters(retComp.ToString(), compDelimiter)); } } return(retType.ToString()); }
public void TestEncodeBytes() { AlternativeCompositeByteBuf buffer = AlternativeCompositeByteBuf.CompBuffer(); // Java byte is signed sbyte[] byteArray = new sbyte[256]; for (int i = 0, b = sbyte.MinValue; b <= sbyte.MaxValue; i++, b++) // -128 ... 127 { byteArray[i] = (sbyte)b; } buffer.WriteBytes(byteArray); var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
/*public LVGROUP(ListViewGroupEx grp) * { * this.cbSize = Marshal.SizeOf(this); * this.Header = grp.Header; * this.ID = grp.ID; * this.SetAlignment(grp.HeaderAlignment, grp.FooterAlignment); * this.Footer = grp.Footer; * this.DescriptionBottom = grp.DescriptionBottom; * this.DescriptionTop = grp.DescriptionTop; * this.Subtitle = grp.Subtitle; * this.Task = grp.Task; * if (grp.TitleImageIndex > 0) * { * this.iTitleImage = grp.TitleImageIndex; * this.mask |= ListViewGroupMask.TitleImage; * } * ListViewGroupState s, m; * grp.GetSetState(out m, out s); * if (s != ListViewGroupState.Normal) * { * this.stateMask = m; * this.state = s; * this.mask |= ListViewGroupMask.State; * } * }*/ public LVGROUP(ListViewGroupMask mask = ListViewGroupMask.None, string header = null) { cbSize = Marshal.SizeOf(this); this.mask = mask; if (header != null) { this.Header = header; } else if ((mask & ListViewGroupMask.Header) != 0) { InteropUtil.AllocString(ref pszHeader, ref cchHeader); } if ((mask & ListViewGroupMask.Footer) != 0) { InteropUtil.AllocString(ref pszFooter, ref cchFooter); } if ((mask & ListViewGroupMask.Subtitle) != 0) { InteropUtil.AllocString(ref pszSubtitle, ref cchSubtitle); } if ((mask & ListViewGroupMask.Task) != 0) { InteropUtil.AllocString(ref pszTask, ref cchTask); } if ((mask & ListViewGroupMask.DescriptionBottom) != 0) { InteropUtil.AllocString(ref pszDescriptionBottom, ref cchDescriptionBottom); } if ((mask & ListViewGroupMask.DescriptionTop) != 0) { InteropUtil.AllocString(ref pszDescriptionTop, ref cchDescriptionTop); } }
public void TestEncodeInt() { AlternativeCompositeByteBuf buffer = AlternativeCompositeByteBuf.CompBuffer(); buffer.WriteInt(int.MinValue); //-2147483648 buffer.WriteInt(-256); buffer.WriteInt(-255); buffer.WriteInt(-128); buffer.WriteInt(-127); buffer.WriteInt(-1); buffer.WriteInt(0); buffer.WriteInt(1); buffer.WriteInt(127); buffer.WriteInt(128); buffer.WriteInt(255); buffer.WriteInt(256); buffer.WriteInt(int.MaxValue); // 2147483647 var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
private void ResizeCustomControl(IntPtr hWnd, InteropUtil.RECT rect, params IntPtr[] buttons) { DialogBrowsingUtilities.Assume(buttons != null && buttons.Length > 0); hWnd.AssumeNonZero(); InteropUtil.WINDOWPLACEMENT wndLoc = hWnd.GetWindowPlacement(); wndLoc.Right = rect.right; hWnd.SetWindowPlacement(ref wndLoc); foreach (IntPtr hBtn in buttons) { m_calcPosMap[hBtn.GetDlgCtrlID()](this, rect.right, out int btnRight, out int btnWidth); PositionButton(hBtn, btnRight, btnWidth); } IntPtr hRgn = InteropUtil.CreateRectRgnIndirect(ref rect); try { if (hWnd.SetWindowRgn(hRgn, true) == 0) { //setting the region failed, so we need to delete the region we created above. hRgn.DeleteObject(); } } catch { if (hRgn != IntPtr.Zero) { hRgn.DeleteObject(); } } }
public void TestEncodeLong() { AlternativeCompositeByteBuf buffer = AlternativeCompositeByteBuf.CompBuffer(); buffer.WriteLong(long.MinValue); //-923372036854775808 buffer.WriteLong(-256); buffer.WriteLong(-255); buffer.WriteLong(-128); buffer.WriteLong(-127); buffer.WriteLong(-1); buffer.WriteLong(0); buffer.WriteLong(1); buffer.WriteLong(127); buffer.WriteLong(128); buffer.WriteLong(255); buffer.WriteLong(256); buffer.WriteLong(long.MaxValue); // 923372036854775807 var bytes = InteropUtil.ExtractBytes(buffer); bool interopResult = JarRunner.WriteBytesAndTestInterop(bytes); Assert.IsTrue(interopResult); }
public HDLAYOUT(ref RECT rc) { prc = InteropUtil.StructureToPtr(rc); pwpos = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(WINDOWPOS))); }
private int ProcessNotifyMessage(IntPtr hWnd, InteropUtil.OFNOTIFY notifyData) { switch (notifyData.hdr_code) { case InteropUtil.CDN_FOLDERCHANGE: { //CDM_GETFOLDERPATH returns garbage for some standard folders like 'Libraries' //var newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)), // InteropUtil.CDM_GETFOLDERPATH); var newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)), InteropUtil.CDM_GETFILEPATH); /* if (m_currentFolder != null && newFolder != null && Util.PathContains(newFolder, m_currentFolder)) { m_suppressSelectionChange = true; } */ m_currentFolder = newFolder; var fileNameCombo = InteropUtil.AssumeNonZero( InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)), InteropUtil.ID_FileNameCombo)); if (m_hasDirChangeFired) { InteropUtil.SetWindowTextW(fileNameCombo, ""); } m_hasDirChangeFired = true; //refresh the file list to make sure that the extension is shown properly var hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)); SetForegroundWindow(hParent); SendKeys.SendWait("{F5}"); break; } case InteropUtil.CDN_FILEOK: { if (!AcceptFiles) { return 1; } var hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)); ProcessSelection(hParent, false); break; } case InteropUtil.CDN_INITDONE: { var hParent = InteropUtil.GetParent(hWnd); var hFile = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(hParent), InteropUtil.ID_FileNameCombo)); InteropUtil.SetFocus(hFile); break; } } return 0; }
/// <summary> /// Constructeur. /// </summary> /// <param name="countryCode">Code pays exporté sur les champs <see cref="MSH.VersionId"/> (MSH-12) et <see cref="MSH.CountryCode/> (MSH-17).</param> /// <param name="version">Version de la norme exportée sur le champ <see cref="MSH.VersionId"/> (MSH-12).</param> /// <param name="exportPaths">Chemins d'export des fichiers.</param> /// <param name="encChars">Caractères d'encodage à utiliser.</param> /// <param name="fileExtension">Extension des fichiers générés.</param> /// <param name="validationFileExtension">Extension des fichiers de validation.</param> /// <param name="msgControlIdInMilliseconds">Indique si le champ <see cref="MSH.MessageControlId"/> (MSH-10) est généré en millisecondes.</param> /// <param name="createValidationFile">Indique si un fichier de validation doit être créé pour chaque fichier généré.</param> public EncodingOptions(string countryCode, string version, List <string> exportPaths, EncodingCharacters encChars = null, string fileExtension = null, string validationFileExtension = null, bool msgControlIdInMilliseconds = true, bool createValidationFile = true) { if (string.IsNullOrWhiteSpace(countryCode)) { throw new EncodingException($"Le code pays à exporter sur les champs {InteropUtil.ConstructFieldNumber("MSH", 12)} et {InteropUtil.ConstructFieldNumber("MSH", 17)} n'a pas été renseignée."); } if (!Structure.Table.CountryCode.Description.ContainsKey(countryCode)) { throw new EncodingException($"Le code pays à exporter sur les champs {InteropUtil.ConstructFieldNumber("MSH", 12)} et {InteropUtil.ConstructFieldNumber("MSH", 17)} n'est pas valide."); } if (string.IsNullOrWhiteSpace(version)) { throw new EncodingException($"La version de la norme à exporter sur le champ {InteropUtil.ConstructFieldNumber("MSH", 12)} n'a pas été renseignée."); } if (!VersionID.Description.ContainsKey(version)) { throw new EncodingException($"La version de la norme à exporter sur le champ {InteropUtil.ConstructFieldNumber("MSH", 12)} n'est pas valide."); } if (exportPaths == null || !exportPaths.Any()) { throw new EncodingException("Aucun chemin d'export n'a été renseigné."); } if (encChars == null) { this._encChars = new EncodingCharacters(); } else { this._encChars = encChars; } if (string.IsNullOrWhiteSpace(fileExtension)) { this._fileExtension = EncoderContainer.CSTS_DEFAULT_EXTENSION_HL7; } else { this._fileExtension = fileExtension; } if (string.IsNullOrWhiteSpace(validationFileExtension)) { this._validationFileExtension = EncoderContainer.CSTS_DEFAULT_EXTENSION_VALIDATION; } else { this._validationFileExtension = validationFileExtension; } this._msgControlIdInMilliseconds = msgControlIdInMilliseconds; this._version = version; this._countryCode = countryCode; this._exportPaths = exportPaths; this._createValidationFile = createValidationFile; }
private int ProcessNotifyMessage(IntPtr hWnd, InteropUtil.OFNOTIFY notifyData) { switch (notifyData.hdr_code) { case InteropUtil.CDN_FOLDERCHANGE: { //CDM_GETFOLDERPATH returns garbage for some standard folders like 'Libraries' //var newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)), // InteropUtil.CDM_GETFOLDERPATH); string newFolder = GetTextFromCommonDialog(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)), InteropUtil.CDM_GETFILEPATH); /* if (m_currentFolder != null && newFolder != null && Util.PathContains(newFolder, m_currentFolder)) { m_suppressSelectionChange = true; } */ m_currentFolder = newFolder; /* #5841 On Windows XP when changing the folder 'newFolder' contains the selected directory twice (e.g. c:\temp\i386\i386) HACK */ if (!Directory.Exists(newFolder)) { try { String lastPart = System.IO.Path.GetFileName(newFolder); String parent = Directory.GetParent(newFolder).FullName; String parentFile = System.IO.Path.GetFileName(parent); if (lastPart.Equals(parentFile)) { m_currentFolder = parent; } } catch (Exception) { //ignore } } IntPtr fileNameCombo = InteropUtil.AssumeNonZero( InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)), InteropUtil.ID_FileNameCombo)); if (m_hasDirChangeFired) { InteropUtil.SetWindowTextW(fileNameCombo, String.Empty); } m_hasDirChangeFired = true; //refresh the file list to make sure that the extension is shown properly IntPtr hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)); SetForegroundWindow(hParent); SendKeys.SendWait("{F5}"); break; } case InteropUtil.CDN_FILEOK: { if (!AcceptFiles) { return 1; } IntPtr hParent = InteropUtil.AssumeNonZero(InteropUtil.GetParent(hWnd)); ProcessSelection(hParent, false); break; } case InteropUtil.CDN_INITDONE: { IntPtr hParent = InteropUtil.GetParent(hWnd); IntPtr hFile = InteropUtil.AssumeNonZero(InteropUtil.GetDlgItem(InteropUtil.AssumeNonZero(hParent), InteropUtil.ID_FileNameCombo)); InteropUtil.SetFocus(hFile); break; } } return 0; }
private void ResizeCustomControl(IntPtr hWnd, InteropUtil.RECT rect, params IntPtr[] buttons) { InteropUtil.Assume(buttons != null && buttons.Length > 0); InteropUtil.AssumeNonZero(hWnd); InteropUtil.WINDOWPLACEMENT wndLoc = InteropUtil.GetWindowPlacement(hWnd); wndLoc.Right = rect.right; InteropUtil.SetWindowPlacement(hWnd, ref wndLoc); foreach (IntPtr hBtn in buttons) { int btnRight, btnWidth; m_calcPosMap[InteropUtil.GetDlgCtrlID(hBtn)](this, rect.right, out btnRight, out btnWidth); PositionButton(hBtn, btnRight, btnWidth); } //see bug # 844 //We clip hWnd to only draw in the rectangle around our custom buttons. //When we supply a custom dialog template to GetOpenFileName(), it adds //an extra HWND to the open file dialog, and then sticks all the controls //in the dialog //template inside the HWND. It then resizes the control //to stretch from the top of the open file dialog to the bottom of the //window, extending the bottom of the window large enough to include the //additional height of the dialog template. This ends up sticking our custom //buttons at the bottom of the window, which is what we want. // //However, the fact that the parent window extends from the top of the open //file dialog was causing some painting problems on Windows XP SP 3 systems. //Basically, because the window was covering the predefined controls on the //open file dialog, they were not getting painted. This results in a blank //window. I tried setting an extended WS_EX_TRANSPARENT style on the dialog, //but that didn't help. // //So, to fix the problem I setup a window region for the synthetic HWND. //This clips the drawing of the window to only within the region containing //the custom buttons, and thus avoids the problem. // //I'm not sure why this wasn't an issue on Vista. IntPtr hRgn = InteropUtil.CreateRectRgnIndirect(ref rect); try { if (InteropUtil.SetWindowRgn(hWnd, hRgn, true) == 0) { //setting the region failed, so we need to delete the region we created above. InteropUtil.DeleteObject(hRgn); } } catch { if (hRgn != IntPtr.Zero) { InteropUtil.DeleteObject(hRgn); } } }
void IDisposable.Dispose() { InteropUtil.FreeString(ref pszText, ref cchTextMax); }
protected override bool RunDialog(IntPtr hwndOwner) { DialogBrowsingUtilities.Assume(Marshal.SystemDefaultCharSize == 2, "The character size should be 2"); IntPtr nativeBuffer = Marshal.AllocCoTaskMem(InteropUtil.NumberOfFileChars * 2); IntPtr filterBuffer = IntPtr.Zero; try { InteropUtil.OpenFileName openFileName = new InteropUtil.OpenFileName(); openFileName.Initialize(); openFileName.hwndOwner = hwndOwner; char[] chars = new char[InteropUtil.NumberOfFileChars]; try { if (File.Exists(Path)) { if (AcceptFiles) { string fileName = System.IO.Path.GetFileName(Path); int length = Math.Min(fileName.Length, InteropUtil.NumberOfFileChars); fileName.CopyTo(0, chars, 0, length); openFileName.lpstrInitialDir = System.IO.Path.GetDirectoryName(Path); } else { openFileName.lpstrInitialDir = System.IO.Path.GetDirectoryName(Path); } } else if (Directory.Exists(Path)) { openFileName.lpstrInitialDir = Path; } else { InitializePathDNE(Path, out openFileName.lpstrInitialDir, out string pathToShow); pathToShow = pathToShow ?? ""; int length = Math.Min(pathToShow.Length, InteropUtil.NumberOfFileChars); pathToShow.CopyTo(0, chars, 0, length); } } catch { } Marshal.Copy(chars, 0, nativeBuffer, chars.Length); openFileName.lpstrFile = nativeBuffer; if (!AcceptFiles) { string str = string.Format("Folders\0*.{0}-{1}\0\0", Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")); filterBuffer = openFileName.lpstrFilter = Marshal.StringToCoTaskMemUni(str); } else { openFileName.lpstrFilter = IntPtr.Zero; } openFileName.nMaxCustFilter = 0; openFileName.nFilterIndex = 0; openFileName.nMaxFile = InteropUtil.NumberOfFileChars; openFileName.nMaxFileTitle = 0; openFileName.lpstrTitle = Title; openFileName.lpfnHook = m_hookDelegate; openFileName.templateID = InteropUtil.IDD_CustomOpenDialog; openFileName.hInstance = Marshal.GetHINSTANCE(typeof(OpenFileOrFolderDialog).Module); openFileName.Flags = InteropUtil.OFN_DONTADDTORECENT | InteropUtil.OFN_ENABLEHOOK | InteropUtil.OFN_ENABLESIZING | InteropUtil.OFN_NOTESTFILECREATE | InteropUtil.OFN_EXPLORER | InteropUtil.OFN_FILEMUSTEXIST | InteropUtil.OFN_PATHMUSTEXIST | InteropUtil.OFN_NODEREFERENCELINKS | InteropUtil.OFN_ENABLETEMPLATE | (ShowReadOnly ? 0 : InteropUtil.OFN_HIDEREADONLY); m_useCurrentDir = false; bool ret = InteropUtil.GetOpenFileNameW(ref openFileName); //var extErrpr = InteropUtil.CommDlgExtendedError(); //InteropUtil.CheckForWin32Error(); if (m_useCurrentDir) { Path = m_currentFolder; return(true); } else if (ret) { Marshal.Copy(nativeBuffer, chars, 0, chars.Length); int firstZeroTerm = ((IList)chars).IndexOf('\0'); if (firstZeroTerm >= 0 && firstZeroTerm <= chars.Length - 1) { Path = new string(chars, 0, firstZeroTerm); } } return(ret); } finally { Marshal.FreeCoTaskMem(nativeBuffer); if (filterBuffer != IntPtr.Zero) { Marshal.FreeCoTaskMem(filterBuffer); } } }
void IDisposable.Dispose() { InteropUtil.FreeString(ref pszImage, ref cchImageMax); }
private static void InternalRenderAlphaNumDevice(DeviceInstance device, NumericalLayout numericalLayout, IntPtr seg_data, IntPtr seg_data2) { device.DmdDevice.RenderAlphaNumeric(numericalLayout, InteropUtil.ReadUInt16Array(seg_data, 64), InteropUtil.ReadUInt16Array(seg_data2, 64)); }
public static void RenderAlphaNum(NumericalLayout numericalLayout, IntPtr seg_data, IntPtr seg_data2) { _dmdDevice.RenderAlphaNumeric(numericalLayout, InteropUtil.ReadUInt16Array(seg_data, 64), InteropUtil.ReadUInt16Array(seg_data2, 64)); }