05-04-2012 02:17 AM
My labview is Labview 2009 64 bit, I use PostLVUserEvent to post message with cluster data to labview. The following is the struct in dll:
typedef struct {
int32 dimSize;
uInt8 elt[1];
} TD1DINT8;
typedef TD1DINT8 **TD1DINT8Hdl;
typedef struct{
int32 interruptSource;
TD1DINT8Hdl portData;
}DIInterruptData, *PDIInterruptData, **HDIInterruptData;
In labview, the DIInterruptData corresponds to a cluster, in which there are a int32 integer and a uint8 array.
It works well in labview 32bit. But in labview 64bit, unhanlded exception occured. why?
05-04-2012 02:31 AM
Hi,
please attach the VI you have tried.Then it will be more easy to suggest a solution.
05-04-2012 03:04 AM
Thank you very much for your rapid answer. The attachment is the vi.
05-04-2012 03:07 AM
The following is c++ code which calls PostLVUserEvent.
void BDAQCALL DiInterruptHandler::DiSnapEvent(void * sender, DiSnapEventArgs * args)
{
PDIInterruptData eventData;
Int32 startPort = m_owner->GetStartPort();
Int32 portCount = m_owner->GetPortCount();
//Allocate cluster pointer
eventData = (PDIInterruptData)DSNewPtr(sizeof(DIInterruptData));
eventData->interruptSource = args->SrcNum;
//Allocate 1D array handle
eventData->portData = (TD1DINT8Hdl)DSNewHandle(sizeof((*(eventData->portData))->dimSize) + portCount
* sizeof((*(eventData->portData))->elt[0]));
(*(eventData->portData))->dimSize = portCount;
for (Int32 i = 0; i < portCount; ++i )
{
(*(eventData->portData))->elt[i] = args->PortData[(i + startPort) % args->Length];
}
PostLVUserEvent(*m_eventRef, (void*)eventData);
//Clear array handle and cluster pointer
DSDisposeHandle(eventData->portData);
DSDisposePtr(eventData);
}
05-28-2014 04:17 PM
Most likely the problem is alignment!
When declaring the data structures you should use the LabVIEW macros like this and make sure that you leave the alignment in the project settings to be the compiler default ones:
...... #include "lv_prolog.h" typedef struct { int32 dimSize; uInt8 elt[1]; } TD1DINT8; typedef TD1DINT8 **TD1DINT8Hdl; typedef struct{ int32 interruptSource; TD1DINT8Hdl portData; }DIInterruptData, *PDIInterruptData, **HDIInterruptData; #include "lv_epilog.h" ........
And the callback code could be somewhat improved in this way:
void BDAQCALL DiInterruptHandler::smileyvery-happy:iSnapEvent(void * sender, DiSnapEventArgs * args) { DIInterruptData eventData; Int32 startPort = m_owner->GetStartPort(); Int32 portCount = m_owner->GetPortCount(); eventData.interruptSource = args->SrcNum; //Allocate 1D array handle eventData.portData = (TD1DINT8Hdl)DSNewHandle(sizeof(int32) + portCount); (*(eventData.portData))->dimSize = portCount; for (Int32 i = 0; i < portCount; ++i ) { (*(eventData.portData))->elt[i] = args->PortData[(i + startPort) % args->Length]; } PostLVUserEvent(*m_eventRef, &eventData); //Clear array handle DSDisposeHandle(eventData.portData); }