Skip to content

Commit cd1c320

Browse files
committed
Fix 64-bit version
IntelliSenseServer v 0.0.9
1 parent e8a5284 commit cd1c320

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace ExcelDna.IntelliSense
4747
// REMEMBER: COM events are not necessarily safe macro contexts.
4848
public static class IntelliSenseServer
4949
{
50-
const string ServerVersion = "0.0.8"; // TODO: Define and manage this somewhere else
50+
const string ServerVersion = "0.0.9"; // TODO: Define and manage this somewhere else
5151

5252
// NOTE: Do not change these constants in custom versions.
5353
// They are part of the co-operative safety mechanism allowing different add-ins providing IntelliSense to work together safely.

Source/ExcelDna.IntelliSense/LoaderNotification.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Runtime.InteropServices;
34

45
namespace ExcelDna.IntelliSense
@@ -32,9 +33,9 @@ static class UnicodeString
3233

3334
public static string ToString(IntPtr pUnicodeString)
3435
{
35-
short length = (short)Marshal.PtrToStructure(pUnicodeString, typeof(short));
36-
IntPtr buffer = Marshal.ReadIntPtr(pUnicodeString, 4);
37-
return Marshal.PtrToStringUni(buffer, length / 2);
36+
short length = (short)Marshal.PtrToStructure(pUnicodeString, typeof(short));
37+
IntPtr buffer = Marshal.ReadIntPtr(pUnicodeString, IntPtr.Size); // The offset is determined by the natural size for the struct packing
38+
return Marshal.PtrToStringUni(buffer, length / 2);
3839
}
3940
}
4041

@@ -80,10 +81,11 @@ enum NtStatus : uint
8081
public LoaderNotification()
8182
{
8283
IntPtr context = IntPtr.Zero; // new IntPtr(12345);
83-
_notificationDelegate = Notification;
84+
_notificationDelegate = Notification; // To prevent GC of the delegate
8485
var status = LdrRegisterDllNotification(0, _notificationDelegate, context, out _cookie);
8586
if (status != 0)
8687
{
88+
Debug.Print($"@@@@ LoaderNotification Result: {status}");
8789
throw new InvalidOperationException($"Error in LdrRegisterDlLNotification. Result: {status}");
8890
}
8991
}
@@ -92,15 +94,13 @@ public LoaderNotification()
9294
// LoadNotification event handler must be very careful, not load any other managed library etc...
9395
void Notification(Reason notificationReason, IntPtr pNotificationData, IntPtr context)
9496
{
95-
IntPtr pFullDllName = Marshal.ReadIntPtr(pNotificationData, 4);
96-
string fullDllName = UnicodeString.ToString(pFullDllName);
97-
NotificationEventArgs args = new NotificationEventArgs { Reason = notificationReason, FullDllName = fullDllName };
98-
LoadNotification?.Invoke(this, args);
99-
100-
// Debug.Print($"@@@@ LdrNotification: {notificationReason} - {fullDllName}");
97+
IntPtr pFullDllName = Marshal.ReadIntPtr(pNotificationData, IntPtr.Size); // The offset is determined by the natural size for the struct packing
98+
string fullDllName = UnicodeString.ToString(pFullDllName);
99+
NotificationEventArgs args = new NotificationEventArgs { Reason = notificationReason, FullDllName = fullDllName };
100+
LoadNotification?.Invoke(this, args);
101101
}
102102

103-
#region IDisposable Support
103+
#region IDisposable Support
104104
// CONSIDER: We might not need the finalizer support ...
105105
private bool disposedValue = false; // To detect redundant calls
106106

@@ -113,8 +113,11 @@ protected virtual void Dispose(bool disposing)
113113
// TODO: dispose managed state (managed objects).
114114
}
115115

116-
var status = LdrUnregisterDllNotification(_cookie);
117-
Logger.Initialization.Verbose($"LoaderNotification LdrUnregisterDllNotification Result: {status}");
116+
if (_cookie != IntPtr.Zero)
117+
{
118+
var status = LdrUnregisterDllNotification(_cookie);
119+
Logger.Initialization.Verbose($"LoaderNotification LdrUnregisterDllNotification Result: {status}");
120+
}
118121
disposedValue = true;
119122
}
120123
}
@@ -132,7 +135,7 @@ public void Dispose()
132135
Dispose(true);
133136
GC.SuppressFinalize(this);
134137
}
135-
#endregion
138+
#endregion
136139

137140

138141
/*

0 commit comments

Comments
 (0)