Skip to content

Commit

Permalink
Fix 64-bit version
Browse files Browse the repository at this point in the history
IntelliSenseServer v 0.0.9
  • Loading branch information
govert committed May 19, 2016
1 parent e8a5284 commit cd1c320
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion Source/ExcelDna.IntelliSense/IntelliSenseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ExcelDna.IntelliSense
// REMEMBER: COM events are not necessarily safe macro contexts.
public static class IntelliSenseServer
{
const string ServerVersion = "0.0.8"; // TODO: Define and manage this somewhere else
const string ServerVersion = "0.0.9"; // TODO: Define and manage this somewhere else

// NOTE: Do not change these constants in custom versions.
// They are part of the co-operative safety mechanism allowing different add-ins providing IntelliSense to work together safely.
Expand Down
31 changes: 17 additions & 14 deletions Source/ExcelDna.IntelliSense/LoaderNotification.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;

namespace ExcelDna.IntelliSense
Expand Down Expand Up @@ -32,9 +33,9 @@ static class UnicodeString

public static string ToString(IntPtr pUnicodeString)
{
short length = (short)Marshal.PtrToStructure(pUnicodeString, typeof(short));
IntPtr buffer = Marshal.ReadIntPtr(pUnicodeString, 4);
return Marshal.PtrToStringUni(buffer, length / 2);
short length = (short)Marshal.PtrToStructure(pUnicodeString, typeof(short));
IntPtr buffer = Marshal.ReadIntPtr(pUnicodeString, IntPtr.Size); // The offset is determined by the natural size for the struct packing
return Marshal.PtrToStringUni(buffer, length / 2);
}
}

Expand Down Expand Up @@ -80,10 +81,11 @@ enum NtStatus : uint
public LoaderNotification()
{
IntPtr context = IntPtr.Zero; // new IntPtr(12345);
_notificationDelegate = Notification;
_notificationDelegate = Notification; // To prevent GC of the delegate
var status = LdrRegisterDllNotification(0, _notificationDelegate, context, out _cookie);
if (status != 0)
{
Debug.Print($"@@@@ LoaderNotification Result: {status}");
throw new InvalidOperationException($"Error in LdrRegisterDlLNotification. Result: {status}");
}
}
Expand All @@ -92,15 +94,13 @@ public LoaderNotification()
// LoadNotification event handler must be very careful, not load any other managed library etc...
void Notification(Reason notificationReason, IntPtr pNotificationData, IntPtr context)
{
IntPtr pFullDllName = Marshal.ReadIntPtr(pNotificationData, 4);
string fullDllName = UnicodeString.ToString(pFullDllName);
NotificationEventArgs args = new NotificationEventArgs { Reason = notificationReason, FullDllName = fullDllName };
LoadNotification?.Invoke(this, args);

// Debug.Print($"@@@@ LdrNotification: {notificationReason} - {fullDllName}");
IntPtr pFullDllName = Marshal.ReadIntPtr(pNotificationData, IntPtr.Size); // The offset is determined by the natural size for the struct packing
string fullDllName = UnicodeString.ToString(pFullDllName);
NotificationEventArgs args = new NotificationEventArgs { Reason = notificationReason, FullDllName = fullDllName };
LoadNotification?.Invoke(this, args);
}

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

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

var status = LdrUnregisterDllNotification(_cookie);
Logger.Initialization.Verbose($"LoaderNotification LdrUnregisterDllNotification Result: {status}");
if (_cookie != IntPtr.Zero)
{
var status = LdrUnregisterDllNotification(_cookie);
Logger.Initialization.Verbose($"LoaderNotification LdrUnregisterDllNotification Result: {status}");
}
disposedValue = true;
}
}
Expand All @@ -132,7 +135,7 @@ public void Dispose()
Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
#endregion


/*
Expand Down

0 comments on commit cd1c320

Please sign in to comment.