1
1
// NPP plugin platform for .Net v0.94.00 by Kasper B. Graversen etc.
2
2
using System ;
3
3
using System . Collections . Generic ;
4
+ using System . Reflection ;
4
5
using System . Runtime . InteropServices ;
6
+ using System . Windows . Forms ;
5
7
6
8
namespace Kbg . NppPluginNET . PluginInfrastructure
7
9
{
@@ -18,10 +20,10 @@ public ClikeStringArray(int num, int stringCapacity)
18
20
for ( int i = 0 ; i < num ; i ++ )
19
21
{
20
22
IntPtr item = Marshal . AllocHGlobal ( stringCapacity ) ;
21
- Marshal . WriteIntPtr ( ( IntPtr ) ( ( int ) _nativeArray + ( i * IntPtr . Size ) ) , item ) ;
23
+ Marshal . WriteIntPtr ( _nativeArray + ( i * IntPtr . Size ) , item ) ;
22
24
_nativeItems . Add ( item ) ;
23
25
}
24
- Marshal . WriteIntPtr ( ( IntPtr ) ( ( int ) _nativeArray + ( num * IntPtr . Size ) ) , IntPtr . Zero ) ;
26
+ Marshal . WriteIntPtr ( _nativeArray + ( num * IntPtr . Size ) , IntPtr . Zero ) ;
25
27
}
26
28
public ClikeStringArray ( List < string > lstStrings )
27
29
{
@@ -30,10 +32,10 @@ public ClikeStringArray(List<string> lstStrings)
30
32
for ( int i = 0 ; i < lstStrings . Count ; i ++ )
31
33
{
32
34
IntPtr item = Marshal . StringToHGlobalUni ( lstStrings [ i ] ) ;
33
- Marshal . WriteIntPtr ( ( IntPtr ) ( ( int ) _nativeArray + ( i * IntPtr . Size ) ) , item ) ;
35
+ Marshal . WriteIntPtr ( _nativeArray + ( i * IntPtr . Size ) , item ) ;
34
36
_nativeItems . Add ( item ) ;
35
37
}
36
- Marshal . WriteIntPtr ( ( IntPtr ) ( ( int ) _nativeArray + ( lstStrings . Count * IntPtr . Size ) ) , IntPtr . Zero ) ;
38
+ Marshal . WriteIntPtr ( _nativeArray + ( lstStrings . Count * IntPtr . Size ) , IntPtr . Zero ) ;
37
39
}
38
40
39
41
public IntPtr NativePointer { get { return _nativeArray ; } }
@@ -52,12 +54,19 @@ List<string> _getManagedItems(bool unicode)
52
54
53
55
public void Dispose ( )
54
56
{
55
- if ( ! _disposed )
57
+ try
56
58
{
57
- for ( int i = 0 ; i < _nativeItems . Count ; i ++ )
58
- if ( _nativeItems [ i ] != IntPtr . Zero ) Marshal . FreeHGlobal ( _nativeItems [ i ] ) ;
59
- if ( _nativeArray != IntPtr . Zero ) Marshal . FreeHGlobal ( _nativeArray ) ;
60
- _disposed = true ;
59
+ if ( ! _disposed )
60
+ {
61
+ for ( int i = 0 ; i < _nativeItems . Count ; i ++ )
62
+ if ( _nativeItems [ i ] != IntPtr . Zero ) Marshal . FreeHGlobal ( _nativeItems [ i ] ) ;
63
+ if ( _nativeArray != IntPtr . Zero ) Marshal . FreeHGlobal ( _nativeArray ) ;
64
+ _disposed = true ;
65
+ }
66
+ }
67
+ catch ( Exception e )
68
+ {
69
+ MessageBox . Show ( MethodBase . GetCurrentMethod ( ) . ToString ( ) + ": " + e . Message , this . GetType ( ) . Name ) ;
61
70
}
62
71
}
63
72
~ ClikeStringArray ( )
0 commit comments