I have a CAN controller from which I need to read packets whenever one is received. With the CAN controller came a WIN32 (non clr) library. When a CAN packet is received the library must trigger an event, which will read the data and process it.
The library takes a __stdcall function pointer, which it uses to make a callback. The callback must be made into my clr class, in which the incomming is processed.
Is it possible to create a clr environment that can interface with a standard WIN32 library in a interrupt style way?
My function is CCAN::ReadBusEvent and I have tried to play around with delegates but since I am not that familiar with this, I have not been able to create anything that compiles.
I keep running into problems such as:
Expand|Select|Wrap|Line Numbers
- error C2664: 'CANPC_set_interrupt_event' : cannot convert parameter 1 from 'MyDel ^' to 'HANDLE'
- error C3374: can't take address of 'CCAN::ReadBusEvent' unless creating delegate instance
I am new to clr and VS 2005, so I don't know that best way to go about it. I don't have any code to show, so I am only asking about ideas on how to program this solution.
/Christian
PS. Old WIN32 implementation:
Expand|Select|Wrap|Line Numbers
- /**********************************************************
- Initialize interrupt handling
- **********************************************************/
- int InitInterruptHandling32(void)
- {
- int ret;
- if (NULL == (threadData.events[INT_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL)))
- {
- // printf("-->Error creating interrupt event 0x%X\n", GetLastError());
- return(-1);
- }
- ResetEvent(threadData.events[INT_EVENT]);
- if (NULL == (threadData.events[END_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL)))
- {
- // printf("-->Error creating thread end event 0x%X\n", GetLastError());
- CloseHandle(threadData.events[INT_EVENT]);
- return(-1);
- }
- if (CANPC_OK != (ret = CANPC_set_interrupt_event(threadData.events[INT_EVENT])))
- {
- // printf("-->Error set interrupt event 0x%X\n", ret);
- CloseHandle(threadData.events[INT_EVENT]);
- CloseHandle(threadData.events[END_EVENT]);
- return(-1);
- }
- if (NULL == (intThread = (HANDLE) _beginthreadex(NULL, 0, interruptThread,
- (void *) &threadData, 0, &tid)))
- {
- // printf("-->Error create interrupt thread 0x%X\n", GetLastError());
- INIPC_close_board();
- CloseHandle(threadData.events[INT_EVENT]);
- CloseHandle(threadData.events[END_EVENT]);
- return(-1);
- }
- InitializeCriticalSection(&CriticalSectionForInterrupt);
- return(0);
- }