Autor Beitrag
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 04.07.17 19:10 
- Nachträglich durch die Entwickler-Ecke gelöscht -
Ralf Jansen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 4700
Erhaltene Danke: 991


VS2010 Pro, VS2012 Pro, VS2013 Pro, VS2015 Pro, Delphi 7 Pro
BeitragVerfasst: Di 04.07.17 20:23 
Anhand eines Beispiels ist das denke ich am einfachsten zu verstehen. Ich schreib mir sonst die Hände fusselig für eine eigentlich eher simple Sache :wink:
Ich nehme mal Pseudocode lose orientiert an deinem frDrive Code.

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
// Benutzung ohne IntPtr oder Alias davon
using (var volume = Drive.GetVolume('c'))
{
    volume.Eject();
}


ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
public static class Drive
{
    public static IVolume GetVolume(char volume)
    {    
        return new Volume(volume);
    }
  
    internal class Volume : IVolume
    {
        private readonly IntPtr handle;
     
        public Volume(char volume)
        {
            this.handle = myLovelyApiMethodForGettingAVolume(volume);
        }
    
        public bool Eject()
        {
            return myLovelyApiMethodForEjectingAVolume(handle);
        }
    
        public void Close()
        {
            myLovelyApiMethodForClosingAVolume(handle);
        }
    
        public void Dispose()
        {
            Close();
        }
    }
}

public interface IVolume : IDisposable
{
    bool Eject();
    void Close();
}
Frühlingsrolle
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Di 04.07.17 21:37 
- Nachträglich durch die Entwickler-Ecke gelöscht -