@@ -21,8 +21,9 @@ public class ScintillaControl : Control
21
21
{
22
22
private bool saveBOM ;
23
23
private Encoding encoding ;
24
- private int directPointer ;
25
- private IntPtr hwndScintilla ;
24
+ private IntPtr directPointer ;
25
+ private Perform _sciFunction ;
26
+ private IntPtr hwndScintilla ;
26
27
private bool hasHighlights = false ;
27
28
private bool ignoreAllKeys = false ;
28
29
private bool isBraceMatching = true ;
@@ -42,7 +43,8 @@ public class ScintillaControl : Control
42
43
43
44
#region Scintilla Main
44
45
45
- public ScintillaControl ( ) : this ( "SciLexer.dll" )
46
+ public ScintillaControl ( )
47
+ : this ( IntPtr . Size == 4 ? "SciLexer.dll" : "SciLexer64.dll" )
46
48
{
47
49
if ( Win32 . ShouldUseWin32 ( ) ) DragAcceptFiles ( this . Handle , 1 ) ;
48
50
}
@@ -55,7 +57,15 @@ public ScintillaControl(string fullpath)
55
57
{
56
58
IntPtr lib = LoadLibrary ( fullpath ) ;
57
59
hwndScintilla = CreateWindowEx ( 0 , "Scintilla" , "" , WS_CHILD_VISIBLE_TABSTOP , 0 , 0 , this . Width , this . Height , this . Handle , 0 , new IntPtr ( 0 ) , null ) ;
58
- directPointer = ( int ) SlowPerform ( 2185 , 0 , 0 ) ;
60
+ directPointer = ( IntPtr ) SlowPerform ( 2185 , 0 , 0 ) ;
61
+ IntPtr sciFunctionPointer = GetProcAddress ( new HandleRef ( null , lib ) , "Scintilla_DirectFunction" ) ;
62
+ /* if (sciFunctionPointer == IntPtr.Zero)
63
+ throw new Win32Exception(Resources.Exception_CannotCreateDirectFunction, new Win32Exception(Marshal.GetLastWin32Error()));
64
+ */
65
+ _sciFunction = ( Perform ) Marshal . GetDelegateForFunctionPointer (
66
+ sciFunctionPointer ,
67
+ typeof ( Perform ) ) ;
68
+
59
69
directPointer = DirectPointer ;
60
70
}
61
71
UpdateUI += new UpdateUIHandler ( OnUpdateUI ) ;
@@ -1549,11 +1559,11 @@ public int DirectFunction
1549
1559
/// Retrieve a pointer value to use as the first argument when calling
1550
1560
/// the function returned by GetDirectFunction.
1551
1561
/// </summary>
1552
- public int DirectPointer
1562
+ public IntPtr DirectPointer
1553
1563
{
1554
1564
get
1555
1565
{
1556
- return ( int ) SPerform ( 2185 , 0 , 0 ) ;
1566
+ return ( IntPtr ) SPerform ( 2185 , 0 , 0 ) ;
1557
1567
}
1558
1568
}
1559
1569
@@ -5034,6 +5044,9 @@ public ShortcutOverride(Keys keys, Action<ScintillaControl> action)
5034
5044
[ DllImport ( "user32.dll" ) ]
5035
5045
public static extern IntPtr CreateWindowEx ( uint dwExStyle , string lpClassName , string lpWindowName , uint dwStyle , int x , int y , int width , int height , IntPtr hWndParent , int hMenu , IntPtr hInstance , string lpParam ) ;
5036
5046
5047
+ [ DllImport ( "kernel32.dll" , CharSet = CharSet . Ansi , ExactSpelling = true , SetLastError = true ) ]
5048
+ public static extern IntPtr GetProcAddress ( HandleRef hModule , string lpProcName ) ;
5049
+
5037
5050
[ DllImport ( "user32.dll" ) ]
5038
5051
public static extern IntPtr SetFocus ( IntPtr hwnd ) ;
5039
5052
@@ -5055,20 +5068,23 @@ public ShortcutOverride(Keys keys, Action<ScintillaControl> action)
5055
5068
[ DllImport ( "shell32.dll" ) ]
5056
5069
public static extern void DragAcceptFiles ( IntPtr hwnd , int accept ) ;
5057
5070
5058
- [ DllImport ( "scilexer.dll" , EntryPoint = "Scintilla_DirectFunction" ) ]
5059
- public static extern int Perform ( int directPointer , UInt32 message , UInt32 wParam , UInt32 lParam ) ;
5071
+ public delegate IntPtr Perform (
5072
+ IntPtr sci ,
5073
+ int iMessage ,
5074
+ IntPtr wParam ,
5075
+ IntPtr lParam ) ;
5060
5076
5061
5077
public UInt32 SlowPerform ( UInt32 message , UInt32 wParam , UInt32 lParam )
5062
5078
{
5063
5079
return ( UInt32 ) SendMessage ( ( int ) hwndScintilla , message , ( int ) wParam , ( int ) lParam ) ;
5064
5080
}
5065
- public UInt32 SPerform ( UInt32 message , UInt32 wParam , UInt32 lParam )
5081
+ public UInt32 SPerform ( int message , UInt32 wParam , UInt32 lParam )
5066
5082
{
5067
- if ( Win32 . ShouldUseWin32 ( ) ) return ( UInt32 ) Perform ( directPointer , message , wParam , lParam ) ;
5083
+ if ( Win32 . ShouldUseWin32 ( ) ) return ( UInt32 ) _sciFunction ( directPointer , message , ( IntPtr ) wParam , ( IntPtr ) lParam ) ;
5068
5084
else return ( UInt32 ) Encoding . ASCII . CodePage ;
5069
5085
}
5070
5086
5071
- public override bool PreProcessMessage ( ref Message m )
5087
+ public override bool PreProcessMessage ( ref Message m )
5072
5088
{
5073
5089
switch ( m . Msg )
5074
5090
{
0 commit comments