Hi All,
I have written a DLL to be called by Excel or Labview to read data from sensors and return them to the spreadsheet or app. The problem is that it works everywhere reliably except in Excel. The first function sets everything up, opens communications (local COMM or Winsock), and gets the device details. Here is the code:
Subsequent functions read individual sensors and process the data. Everything works fine when called by VB6 or PowerBasic apps. It also works when called from the immediate window in the Excel VBA API. When called from VBA code in Excel it crashes Excel.
All of the other functions, including functions that return strings, work fine in Excel.
I have tried this function in various forms, returning a long or as a SUB leaving the string data to be collected by another finction. All of them get to the last step (the message box) and then crash the same way.
Does anyone have any ideas about what could be going on here?
Thanks in advance,
Rob
I have written a DLL to be called by Excel or Labview to read data from sensors and return them to the spreadsheet or app. The problem is that it works everywhere reliably except in Excel. The first function sets everything up, opens communications (local COMM or Winsock), and gets the device details. Here is the code:
Code:
FUNCTION thStartSession ALIAS "thStartSession"(BYVAL thPort AS LONG, BYVAL thIPaddr AS STRING) EXPORT AS STRING LOCAL i AS LONG LOCAL rStr, IPstr, fStr AS STRING REDIM CRC8tbl(255) REDIM CRC16tbl(1,255) REDIM rBytes(1) REDIM IBLlist(0) popCRC IF nComm = 0 THEN nComm = FREEFILE IBLcount = 0 ipstr = thipaddr ipstr = TRIM$(ipstr, ANY CHR$(0)) 'not sure if this is required IF LEN(ipstr) > 0 THEN UseSoc = 1 i = StartSoc(thport,ipstr) ELSE UseSoc = 0 i = StartComms(thPort) END IF IF i = %TRUE THEN 'if the port is correct and the device is found rStr = getlinkserno 'get the serial number and add it to the type IF LEN(rstr) > 0 THEN LinkType = LinkType & " - " & rstr END IF ELSE LinkType = "Port or Link not found" END IF MSGBOX linktype 'this is here for troubleshooting 'it gets this far before crashing Excel FUNCTION = linktype END FUNCTION
All of the other functions, including functions that return strings, work fine in Excel.
I have tried this function in various forms, returning a long or as a SUB leaving the string data to be collected by another finction. All of them get to the last step (the message box) and then crash the same way.
Does anyone have any ideas about what could be going on here?
Thanks in advance,
Rob
Comment