CallbackOnCollectedDelegate was detected on Walther MFS100 Check Scanner

I am trying to program the interface for the Walther Mfs100 Check scanner, but after scanning I found a "CallbackOnCollectedDelegate" error. How can I fix this. I am using .net 2.0 with C #

[DllImport("mflib.dll.stdcall")]
        public static extern int mfScanFeeder(int mode, int font, int timeout);

 retval = modMFS100.mfScanFeeder(0, 2,5000);
+3
source share
2 answers

This is not the specific API call that is the source of the problem. The API is too obscure and too poorly documented to give a direct answer, but look for an initialization style function that allows you to set a callback. This callback is the cause of the exception. You must create a delegate object and save it in the field of your class. Thus, the garbage collector sees a link to it and will not collect garbage.

, :

void SetupScanner() {
    mfInitialize(something, myCallback);
}

:

SomeDelegateType callback;

void SetupScanner() {
    callback = new SomeDelegateType(myCallback);
    mfInitialize(something, callback);
}

, .

+3

Source: https://habr.com/ru/post/1793070/


All Articles