Trying to get a user definable function instead of what is in an API library. This works no problem in Linux GCC but cannot figure out what to do for Visual Studio. The library is a .dll and everything is the same on the .so in linux.
Header:
typedef struct _usb_can_packet_ {
uint8_t size;
uint8_t cmd;
uint8_t port;
uint8_t misc;
uint32_t extendedStatus;
union {
MCAN_OPEN openInfo;
MCAN_RX_PACKET rxPacket;
MCAN_TX_PACKET txPacket;
MCAN_TX_DONE txEvent;
} u;
} VL_USB_CAN_XFER;
void user_CANRxCallBackFunction(VL_USB_CAN_XFER* pRxPacket, int txStatus);
DLL:
// User Defined function called when a packet is recieved.
void user_CANRxCallBackFunction(VL_USB_CAN_XFER* pRxPacket, int status)
{
/* ***** Declarations. ***** */
/* ************************* */
/* ***** Initializations. ***** */
/* **************************** */
/* ***** Construct the packet. ***** */
if (gCallBackInfo.rxFlag)
{
if (gAPIDebugLevel >= VL_DEBUG_1)
{
printf("Entering user_CANRxCallBackFunction() with an eventn");
}
gCallBackInfo.rxFlag = 1; // Reset the flag for next packet.
if (gAPIDebugLevel >= VL_DEBUG_1)
printf("Leaving user_CANRxCallBackFunction()n");
}
/* ********************************* */
}
void rxCallBack(struct libusb_transfer* pXfer)
{
/* ***** Declarations. ***** */
VL_USB_CAN_XFER* pRxPacket;
/* ************************* */
// We are here.
if (gAPIDebugLevel >= VL_DEBUG_2)
printf("Entering rxCallBack()n");
gRxPacketCount++;
if (LIBUSB_TRANSFER_COMPLETED == pXfer->status)
{
if (gAPIDebugLevel >= VL_DEBUG_2)
{
printf("Status complete;n");
printf(" usb->flags=0x%xn", pXfer->flags);
printf(" usb->actual_length=0x%xn", pXfer->actual_length);
}
gCallBackInfo.rxFlag = 1;
gCallBackInfo.rxSts = (int)pXfer->flags;
gCallBackInfo.rxLength = (int)pXfer->actual_length;
memcpy(gCallBackInfo.pRxBuf, pXfer->buffer, pXfer->actual_length);
gRxTimeOutCount = 0;
// For ease of reference, create a CAN packet.
pRxPacket = (VL_USB_CAN_XFER*)gCallBackInfo.pRxBuf;
// Filter out certain packets.
switch (pRxPacket->cmd)
{
case USB_CAN_CMD_OPEN:
case USB_CAN_CMD_CLOSE:
case USB_CAN_CMD_ID:
case USB_CAN_CMD_MAX:
case USB_CAN_CMD_UNDEFINED:
break; // Do nothing for these.
case USB_CAN_CMD_TX:
if (gAPIDebugLevel >= VL_DEBUG_2)
{
VSL_CANPrintPktHeader("rxCallBack():", pRxPacket);
}
break;
case USB_CAN_CMD_STS:
gCANPortStatus = pRxPacket->misc;
break;
case USB_CAN_CMD_MCU_FW_VER:
gMCUFwReceived = pRxPacket->extendedStatus;
break;
case USB_CAN_CMD_MCU_REG_VAL:
gMCURegValReceived = pRxPacket->extendedStatus;
gMCURegId = pRxPacket->misc;
if (gAPIDebugLevel >= VL_DEBUG_2)
{
printf("trxCallBack(): reg 0x%d val = 0x%08xn",
gMCURegId, gMCURegValReceived);
}
break;
case USB_CAN_CMD_RX:
if (gAPIDebugLevel >= VL_DEBUG_2)
{
VSL_CANPrintPktHeader("rxCallBack(): RX", pRxPacket);
mydumpData((uint8_t*)&(pRxPacket->u.rxPacket.mcanRxData), 8);
}
break;
default:
break;
}
}
else if (LIBUSB_TRANSFER_TIMED_OUT == pXfer->status) {
if (gAPIDebugLevel >= VL_DEBUG_1)
{
if (gAPIDebugLevel >= VL_DEBUG_2)
printf("Status timed_out;n");
}
gRxTimeOutExit = true;
gRxTimeOutCount++;
}
else if (LIBUSB_TRANSFER_CANCELLED == pXfer->status) {
if (gAPIDebugLevel >= VL_DEBUG_2)
printf("Status cancelled;n");
gRxCancelled = true;
gRxTimeOutCount = 0;
}
else
{
if (gAPIDebugLevel >= VL_DEBUG_2)
printf("UNKNOWN STATUS (%d);n", pXfer->status);
}
// Call a user defined function.
(void)user_CANRxCallBackFunction(pRxPacket, pXfer->status);
libusb_submit_transfer(pXfer);
if (gAPIDebugLevel >= VL_DEBUG_2)
printf("Leaving rxCallBack(rxPacketCount=%d; rxTimeOutCount=%d);n",
gRxPacketCount, gRxTimeOutCount);
return;
}
Application (outside of main):
// User Defined function called when a packet is recieved.
void user_CANRxCallBackFunction(VL_USB_CAN_XFER* pRxPacket, int txStatus)
{
/* ***** Declarations. ***** */
/* ************************* */
/* ***** Initializations. ***** */
/* **************************** */
/* ***** PROCESS. ***** */
if (gAPIDebugLevel >= VL_DEBUG_2)
{
printf("Entering app userDefinedRxFunction(), txStatus=%dn", txStatus);
}
if (txStatus == LIBUSB_TRANSFER_COMPLETED)
{
if (pRxPacket->cmd == USB_CAN_CMD_RX)
{
gCurRxPktCount++;
gCurTxRxPktCount++;
(void)VSL_CANPrintPktHeader("Packet Received:", pRxPacket);
CANPrintPacket(pRxPacket);
}
}
else
{
gFailedPktCount++;
}
/* ******************** */
if (gAPIDebugLevel >= VL_DEBUG_2)
printf("Leaving app userDefinedRxFunction()n");
return;
}
How can I get Visual Studio to prioritize the application definition?
1