000
24.08.2008, 11:44 Uhr
sojahulk
|
hallo,
ich versuche verzweifelt mit meinen rudimentären c++ fähigkeiten eine dll zu programmieren, mir eine function aus einer anderen dll mit einer callbackfucktion ausführt.
folgendes habe ich geschreieben:
C++: |
#include "stdafx.h" #include "types.h"
#include "antdefines.h" #include "antmessage.h" #include "ant_dll.h"
P_ANT_ARF ANT_AssignResponseFunction; P_ANT_AEF ANT_AssignChannelEventFunction; P_ANT_SHM ANT_SerialHaveMessage;
static HMODULE hANTdll; static BOOL bLoaded = FALSE;
UCHAR ucChannel;
BOOL ANT_Load(void) { if (bLoaded) return TRUE;
hANTdll = LoadLibraryA("ANT_DLL.dll"); if (hANTdll == NULL) return FALSE;
ANT_AssignResponseFunction = (P_ANT_ARF) GetProcAddress(hANTdll, "ANT_AssignResponseFunction"); ANT_AssignChannelEventFunction = (P_ANT_AEF) GetProcAddress(hANTdll, "ANT_AssignChannelEventFunction"); ANT_SerialHaveMessage = (P_ANT_SHM) GetProcAddress(hANTdll, "ANT_SerialHaveMessage");
if (ANT_AssignResponseFunction == NULL) return FALSE; if (ANT_AssignChannelEventFunction == NULL) return FALSE; if (ANT_SerialHaveMessage == NULL) return FALSE;
bLoaded = TRUE; return TRUE; }
void ANT_UnLoad(void) { if (hANTdll != NULL) { FreeLibrary(hANTdll); } bLoaded = FALSE; }
UCHAR* SerialRawData(UCHAR ucChannel, UCHAR *pucRxBuffer) { ANT_AssignResponseFunction( (RESPONSE_FUNC)ANT_SerialHaveMessage,aucResponseBuf ); ANT_AssignChannelEventFunction(ucChannel, (CHANNEL_EVENT_FUNC)ANT_SerialHaveMessage, pucRxBuffer ); return pucRxBuffer; }
|
als bsp: die event funkiton ist wie folgt aufgebaut:
C++: |
//in der .h definierter functionpointer typedef BOOL (*CHANNEL_EVENT_FUNC)(UCHAR ucANTChannel, UCHAR ucEvent); //
void ANT_AssignChannelEventFunction(UCHAR ucLink, CHANNEL_EVENT_FUNC pfLinkEvent, UCHAR *pucRxBuffer) { sLink[ucLink].pfLinkEvent = pfLinkEvent; sLink[ucLink].pucRxBuffer = pucRxBuffer; }
|
und der linkevent wir hier behandelt:
C++: |
void ANT_SerialHaveMessage(void) { UCHAR aucData[MESG_RSSI_DATA_SIZE]; UCHAR ucSize; UCHAR ucID; UCHAR ucANTChannel;
//If no response function has been assigned, ignore the message and unlock //the receive buffer if (pfResponseFunc == NULL) { Serial_ClearState(SERIAL_STATE_RX_BUFFER_LOCK); // unlock RX buffer return; }
ucSize = Serial_GetMesg(&ucID, &aucData[0]);
ucANTChannel = aucData[MESG_CHANNEL_OFFSET] & CHANNEL_NUMBER_MASK;
//Process the message to determine whether it is a response event or one //of the channel events and call the appropriate event function. switch (ucID) { case MESG_RESPONSE_EVENT_ID: if (aucData[MESG_EVENT_ID_OFFSET] != MESG_EVENT_ID) // this is a response { if (pucResponseBuffer) { memcpy(pucResponseBuffer, &aucData[0], MESG_RESPONSE_EVENT_SIZE); pfResponseFunc(ucANTChannel, MESG_RESPONSE_EVENT_ID); } } else // this is an event { // If we are in auto transfer mode, stop sending packets if ((aucData[MESG_EVENT_CODE_OFFSET] == EVENT_TRANSFER_TX_FAILED) && (ucAutoTransferChannel == ucANTChannel)) usNumDataPackets = 0;
if (sLink[ucANTChannel].pfLinkEvent == NULL) break;
memcpy(sLink[ucANTChannel].pucRxBuffer, &aucData[0], ucSize); sLink[ucANTChannel].pfLinkEvent(ucANTChannel, aucData[MESG_EVENT_CODE_OFFSET]); // pass through any events not handled here } break;
case MESG_BROADCAST_DATA_ID: if (sLink[ucANTChannel].pfLinkEvent == NULL) break;
//Call channel event function with Broadcast message code memcpy(sLink[ucANTChannel].pucRxBuffer, &aucData[0], MESG_DATA_SIZE); sLink[ucANTChannel].pfLinkEvent(ucANTChannel, EVENT_RX_BROADCAST); // process the event break; . . .
|
ich wäre sehr dankbar für hilfe, und auch bereit zu zahlen, wenn sich jemand dieser aufgabe annehmen möchte.
thanx hulk |