Jump to content

dadreamer

Members
  • Posts

    361
  • Joined

  • Last visited

  • Days Won

    36

Posts posted by dadreamer

  1. I see two main issues here.

    1. Too many events coming - your program just can't handle them all at once (you were already warned about that). How can you deal with it? You decide. I often use a boolean variable switch for that. You may consider something else.
    2. You want to have UninstallStandardCallback function to stop posting into LV, when the loop finishes or no matter what. Now your DLL seems to be trying to post even when the main VI finishes plus the event queue is full with unprocessed events. Try to implement that function on your own, it's not that complex.
  2. Don't pass Event Registration Refnum to the DLL! Pass Event Refnum.

    2022-05-30_21-21-00.jpg.14123817a2e2e69c31a2c671387132ba.jpg

    Also you need to pass this wire through all the frames of the structure, because when the loop will be stopped, Destroy User Event VI will be confused getting invalid refnum. Or wire it around the loop instead. Oh, first do unregister, second do destroy, in that order.

    Moreover your calling convention is wrong!

    Plus you didn't insert an User Event frame where you're going to catch your events.

    ! Reg Events, Unregister and Destroy should be either outside the loop completely or inside the "Start" (for Reg Events) and "Stop" (for Unregister and Destroy) frames ! Otherwise the UE will be created and freed on each iteration.

  3. You better rework Rolf's example a bit to not reinvent the wheel.

    1. Remove this as no longer needed.

    2022-05-30_17-39-26.jpg.b50b1db30f05158a0e76a0f31591136a.jpg

    2. Remove this Case Structure and that VI Ref terminal. Pass NULL (0) as hPlayWnd.

    2022-05-30_17-40-46.jpg.7af936e80d64a4f473dcf2aad847fe44.jpg

    3. Before the While loop create User Event of cluster type, containing these three fields:

    typedef struct
    {
    	LONG realHandle;
    	DWORD dataType;
    	LVByteArrayHdl handle;
    } LVEventData;

    You should set handle type as U32, if you're working in 32-bit LabVIEW only, or U64 in all other cases.

    4. In "Start" frame of the Event Structure right after Start.vi put CLFN with InstallStandardCallback function call, set it properly and pass two parameters to it - lSession from Start.vi and your fresh UE reference.

    2022-05-30_17-57-20.jpg.b21f18075f7cd71e13e31fc22f79a994.jpg

    5. Activate Dynamic Events terminals on your Event Structure and set it to accept your User Event. Also here register for events and pass the event refnum to the right terminal.

    6. In "Stop" frame of the Event Structure unregister for events.

    7. After the loop destroy the UE.

    Now after running your program and pressing "Connect" + "Start" buttons you should receive some events (if no mistakes made). Check Event Inspector window to make sure.

  4. 10 minutes ago, alvise said:

    There is no problem here, is there?

    There is! Alter the function declarations and add these prototypes.

    extern "C" __declspec(dllexport) void __stdcall DataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, DWORD dwUser);
    extern "C" __declspec(dllexport) BOOL __cdecl InstallStandardCallback(LONG lRealHandle, LVUserEventRef *refnum);
  5. 11 minutes ago, alvise said:

    To export functions like here, it is necessary to make changes in the code, right?

    Yes. Your code does already have all that necessary stuff for export:

    #define LibAPI(retval)       __declspec(dllexport) EXTERNC retval __cdecl
    #define Callback(retval)     __declspec(dllexport) EXTERNC retval __stdcall
    // ...
    Callback(void) DataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, DWORD dwUser)
    {
    // ...
    }
    
    LibAPI(BOOL) InstallStandardCallback(LONG lRealHandle, LVUserEventRef *refnum)
    {
    // ...
    }

    Hence it's rather odd that nothing is exported. As you're using __declspec(dllexport), no need to use .def file - you may disable it in the settings.

    Maybe your functions are exported, but have decorated names... In this case LabVIEW won't show them. Could you check full export table with some tool like Dependency Walker or similar?

  6. Looks to me like some headers conflict... Try to #include "pch.h" as the first header file (before any other headers). Also you may remove all that C:\Program Files\... stuff from the #include directives and leave header names only, as you already specified cintools path in the project settings. If that doesn't help, disable precompiled headers to see, what happens.

    Besides, those %28 and %29 characters on your screenshots look odd to me, because I had not noticed before that Visual Studio escapes some symbols in path names. Do they get added automatically?

  7. 18 minutes ago, alvise said:

    You mentioned earlier a method that can be done without using callback. What method is this?

    Callback is still needed. I said that PostLVUserEvent call may be omitted.

    On 5/27/2022 at 5:00 PM, dadreamer said:

    There exists an easier callback variation, that doesn't involve calling PostLVUserEvent.

    If you don't know C even at very basic level and can't compile DLLs, I'm afraid I can't help here. There are many example on making C/C++ DLLs on the net. My advice is to learn them carefully and only after that go to callback things.

  8. 27 minutes ago, alvise said:

    It must always have two images on the screen and the Picturebox must always be in the middle of the screen, right?

    Since BitBlt is used, your PictureBox object should be visible and on screen completely, because when it's not, then black areas are captured. PrintWindow on the other side should deal with (partially) hidden windows better, but I have no idea why it doesn't work in your case.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.