dadreamer Posted May 29, 2022 Report Share Posted May 29, 2022 (edited) https://stackoverflow.com/questions/10599940/module-unsafe-for-safeseh-image-c Quote Is it okay if safesh is disabled? For this project - yes. Quote This linker option is intended to protect exception handler records on the stack from being overwritten. Edited May 29, 2022 by dadreamer Quote Link to comment
alvise Posted May 29, 2022 Author Report Share Posted May 29, 2022 Is it safe to disable it? Quote Link to comment
dadreamer Posted May 29, 2022 Report Share Posted May 29, 2022 There are literally zero chances that someone would hack you through callback DLL, that will be loaded into LabVIEW address space. 😃 Quote Link to comment
alvise Posted May 29, 2022 Author Report Share Posted May 29, 2022 I needed to make sure the code wouldn't hijack my computer I guess I need to implement them. step 1: step 2:Do you need to choose stdcall? Quote Link to comment
dadreamer Posted May 29, 2022 Report Share Posted May 29, 2022 All you need is to disable option "Image has Safe Exception Handlers" in Project properties -> Configuration Properties -> Linker -> Advanced tab. Why are you trying to adjust Debug config, when you're on Release one? Quote Link to comment
alvise Posted May 29, 2022 Author Report Share Posted May 29, 2022 (edited) 17 minutes ago, dadreamer said: All you need is to disable option "Image has Safe Exception Handlers" in Project properties -> Configuration Properties -> Linker -> Advanced tab. Why are you trying to adjust Debug config, when you're on Release one? After selecting it as a release again, I built it. I just missed it. I fixed it. ok. now .dll file has been created. Edited May 29, 2022 by alvise Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 Is it normal for the dll file's functions to look like this? Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 These four functions should be there, they are "service" functions for LabVIEW core. But your functions did not get exported at all for some reason. Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 I also made the following settings for export, but still the same Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 To export functions like here, it is necessary to make changes in the code, right? Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 (edited) 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? Edited May 30, 2022 by dadreamer Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 I checked and it looks like below. Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 I don't see the functions prototypes declared anywhere in the source. Maybe this is the reason. Try to add them right after the last #include directive. Callback(void) DataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer, DWORD dwBufSize, DWORD dwUser); And LibAPI(BOOL) InstallStandardCallback(LONG lRealHandle, LVUserEventRef *refnum); Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 While building, the output is something like this. There is no problem here, is there? Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 (edited) 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); Edited May 30, 2022 by dadreamer Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 after editing no errors or warnings as below. When you call the dll file from the debug file here, it has function names as follows. Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 You may trash down Release folder and rebuild the project in Release config. Or leave it as is. But when you will distribute your app onto another machines without Visual Studio installed, your library will ask for the debug version of MSVC Runtime. Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 (edited) Upon your suggestion, I deleted the folder named release and created it again. I can see the labview DataCallBack and InstallStandardCallback functions. I guess this is the next step. Edited May 30, 2022 by alvise Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 (edited) You better rework Rolf's example a bit to not reinvent the wheel. 1. Remove this as no longer needed. 2. Remove this Case Structure and that VI Ref terminal. Pass NULL (0) as hPlayWnd. 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. 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. Edited May 30, 2022 by dadreamer Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 (edited) According to what you said step by step, I made a fix as follows, but if I press the start button, the labview crashes. Hikvision-labviewSDK-Test-v1.0.0.rar Edited May 30, 2022 by alvise Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 (edited) Don't pass Event Registration Refnum to the DLL! Pass Event Refnum. 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. Edited May 30, 2022 by dadreamer Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 (edited) Taking your suggestions into account, I updated the VI as follows. Currently there is no problem, at least the labview does not crash and I get some values as output. Of course, I don't know if there are errors. What is the reason why the Handle value is sometimes flickering on the screen? Preview CAM-1.vi Edited May 30, 2022 by alvise Quote Link to comment
dadreamer Posted May 30, 2022 Report Share Posted May 30, 2022 10 minutes ago, alvise said: What is the reason why the Handle value is sometimes flickering on the screen? Maybe because on each event a new handle is allocated? Now you're gonna have some fun with MoveBlock thingy 😉 Does your loop manage to process events in time? Quote Link to comment
alvise Posted May 30, 2022 Author Report Share Posted May 30, 2022 10 minutes ago, dadreamer said: Maybe because on each event a new handle is allocated? Now you're gonna have some fun with MoveBlock thingy 😉 Does your loop manage to process events in time? yes, I guess it allocates a new handle to each event. I'm not playing with something dangerous, am I ? Does your loop manage to process events in time? - I've included a few photos of the test below, although I don't quite understand what you're saying here. I think there is an unstable situation. Sometimes when I run the VI the values refresh like crazy, Other times if I stop the VI and run it again nothing is read. Quote Link to comment
dadreamer Posted May 31, 2022 Report Share Posted May 31, 2022 (edited) I see two main issues here. 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. 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. Edited May 31, 2022 by dadreamer Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.