Robin Fauser
Robin Fauser

Reputation: 121

LabVIEW + C-DLL: Access violation (0xC0000005) at EIP = 0x00000000

Information: LabVIEW: 2019 Version: 19.0.1 (32-bit) Operating system: Windows 64-bit

Labview crashes completely after an indefinite time. I call three functions of the C-DLL. I loop through all the functions of the DLL over and over again. After about 2 minutes to an hour Labview crashes without reason. VI

Calling of OpenConnection(): OpenConnection

Calling of QueryOpenConnectionStatus(): QueryOpenConnectionStatus

Calling of CloseConnection(): CloseConnection

Type definition of TConnectionResult

TConnectionResult

Follow the given Headerfile.h

#ifndef __epMCOMLib_h_
#define __epMCOMLib_h_
#include <stdint.h>
#include <stddef.h>
#define DLLIMPORT __declspec(dllimport) 
#pragma pack (push,1)


typedef struct {
  uint16_t DLLFailureCode;
  uint8_t ConnectionStatus;
  uint32_t SystemFailureCode;
} TConnectionResult;
                                                                                         
#pragma pack (pop)


#ifdef __cplusplus
extern "C" {
#endif

DLLIMPORT uint16_t __cdecl OpenConnection(uint8_t            PortType, 
                                          char *             PortName, 
                                          uint32_t OnConnectSucces,
                                          uint32_t *         Handle);
                                          
DLLIMPORT void __cdecl QueryOpenConnectionStatus(uint32_t Handle,
                                                 TConnectionResult * Result); 

DLLIMPORT uint16_t __cdecl CloseConnection(uint32_t Handle);

                                                     
#ifdef __cplusplus
} // extern "C"
#endif

#endif //#ifndef __epMCOMLib_h_

The DLL works perfectly. For this I integrated the DLL in Python ,LabWindows/CVI, C++ and Delphi. There is no crash in these programming languages!

Can anyone give me any useful tips on how to further isolate or eliminate the error. Even if a function of the DLL has been executed and the DLL is then closed, it still causes a crash. As if it's still in memory. It feels like looking for a needle in a haystack.

Screenshot of error

Upvotes: 0

Views: 1901

Answers (2)

Robin Fauser
Robin Fauser

Reputation: 121

Run the thread on the UI thread instead of any thread!

Call DLL in UI-Thread

Call external Lib

In the log file of the DLL I could see that the thread is attached and detached. I suspect this is causing a memory violation. Since Labview is shot down by its called DLL. Thread attached and detach

Upvotes: 1

Fourier
Fourier

Reputation: 111

In my experience, sometimes DLL called with LabVIEW causes this kind of problems and with no specific reasons and solutions (even for the NI technical support). Try to launch your LabVIEW applicatin with Administrator privilegies. In some cases, this solves the problem.

Upvotes: 0

Related Questions