Unfortunately, nothing I have tried works.
This is how the header file looks like:
#include "extcode.h" #pragma pack(push) #pragma pack(1)
#ifdef __cplusplus extern "C" { #endif typedef struct { LVBoolean status; int32_t code; LStrHandle source; } TD1;
void __cdecl LCDColor(LVRefNum *VISAIN, uint16_t LCDColor2, TD1 *errorInNoError, LVRefNum *VISAOUT, char OutputString[], TD1 *errorOut, int32_t len);
long __cdecl LVDLLStatus(char *errStr, int errStrLen, void *module);
#ifdef __cplusplus } // extern "C" #endif
#pragma pack(pop)
Also ffrom this DLL developer I learned that inside Labview code it uses name "COM1" as a string for the Com Port under VISAIN and VISAOUT parameter, also that parameters errorIn,OutputStr, errorOut, len are optional.
I have tried several ways to declare and call it in VB.NET:
1.
DeclareAutoFunction LCDColor Lib"..LabVIEWdllsLCD Color.dll" (ByVal ComPortIn AsString, ByVal color As Int16, ByRef errIn As Int32, ByVal ComPortOut AsString, ByRef outPutStr AsString, ByRef errOut As Int32, ByRef len As Int32) AsInt32
Call as
LCDColor("COM1", color, errorIn,"COM1", OutputStr, errorOut, len)
2.
DeclareAutoFunction LCDColor Lib"..LabVIEWdllsLCD Color.dll" (ByVal ComPortIn As Int32, ByVal color As Int16, ByRef errIn As Int32, ByVal ComPortOut As Int32, ByRef outPutStr AsString, ByRef errOut As Int32, ByRef len As Int32) As Int32
call as
LCDColor(1, color, errorIn, 1, OutputStr, errorOut, len)
3.DeclareAutoFunction LCDColor Lib"..LabVIEWdllsLCD Color.dll" (ByVal ComPortIn As IntPtr, ByVal color As Int16, ByRef errIn As Int32, ByVal ComPortOut As IntPtr, ByRef outPutStr AsString, ByRef errOut As Int32, ByRef len As Int32) As Int32
call as
Dim ComPort AsString = "COM3"
Dim ptrCom As IntPtr = Marshal.StringToHGlobalAnsi(ComPort)
LCDColor(ptrCom, color, errorIn, ptrCom, OutputStr, errorOut, len)
In all cases I get the same error: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
I need to have it done.
Thanks for any suggestions.