static FreeImageEngine() { // Check if FreeImage.dll is present and cancel setting the callback function if not if (!IsAvailable) { return; } // Create a delegate (function pointer) to 'OnMessage' outputMessageFunction = new OutputMessageFunction(OnMessage); // Set the callback FreeImage.SetOutputMessage(outputMessageFunction); }
static FreeImageEngine() { // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not if (!IsAvailable) { return; } // Create a delegate (function pointer) to 'OnMessage' outputMessageFunction = new OutputMessageFunction(OnMessage); // Set the callback FreeImage.SetOutputMessage(outputMessageFunction); }
/// <summary> /// Internal callback /// </summary> private static void OnMessage(FREE_IMAGE_FORMAT fif, string message) { // Get a local copy of the multicast-delegate OutputMessageFunction m = Message; // Check the local copy instead of the static instance // to prevent a second thread from setting the delegate // to null, which would cause a null reference exception if (m != null) { // Invoke the multicast-delegate m.Invoke(fif, message); } }
private static void InitializeMessage() { if (null == outputMessageFunction) { lock (outputMessageFunctionLock) { if (null == outputMessageFunction) { FreeImage.ValidateAvailability(); try { // Create a delegate (function pointer) to 'OnMessage' outputMessageFunction = delegate(FREE_IMAGE_FORMAT fif, string message) { LastErrorMessage = message; // Get a local copy of the multicast-delegate OutputMessageFunction m = FreeImageEngine.message; // Check the local copy instead of the static instance // to prevent a second thread from setting the delegate // to null, which would cause a nullreference exception if (m != null) { // Invoke the multicast-delegate m.Invoke(fif, message); } }; // Set the callback FreeImage.SetOutputMessage(outputMessageFunction); } catch { outputMessageFunction = null; throw; } } } } }
internal static extern void SetOutputMessage(OutputMessageFunction omf);
internal static extern void SetOutputMessage(OutputMessageFunction outputMessageFunction);
static FreeImage() { // Check if FreeImage.dll is present and cancel setting the callbackfuntion if not if (!IsAvailable()) { return; } // Create a delegate (function pointer) to 'OnMessage' outputMessageFunction = new OutputMessageFunction(OnMessage); // Pin the object so the garbage collector does not move it around in memory outputMessageHandle = GCHandle.Alloc(outputMessageFunction, GCHandleType.Normal); // Set the callback SetOutputMessage(outputMessageFunction); }