473,503 Members | 5,495 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Invoking a clr event from a non-clr library

1 New Member
Hi,

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
  1. error C2664: 'CANPC_set_interrupt_event' : cannot convert parameter 1 from 'MyDel ^' to 'HANDLE'
  2.  
  3. error C3374: can't take address of 'CCAN::ReadBusEvent' unless creating delegate instance
(HANDLE is a function pointer)

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
  1. /**********************************************************
  2.   Initialize interrupt handling
  3. **********************************************************/
  4. int InitInterruptHandling32(void)
  5. {
  6.   int ret;
  7.  
  8.   if (NULL == (threadData.events[INT_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL)))
  9.   {
  10. //    printf("-->Error creating interrupt event 0x%X\n", GetLastError());
  11.     return(-1);
  12.   }
  13.  
  14.   ResetEvent(threadData.events[INT_EVENT]);
  15.  
  16.   if (NULL == (threadData.events[END_EVENT] = CreateEvent(NULL, FALSE, FALSE, NULL)))
  17.   {
  18. //    printf("-->Error creating thread end event 0x%X\n", GetLastError());
  19.     CloseHandle(threadData.events[INT_EVENT]);
  20.     return(-1);
  21.   }
  22.  
  23.   if (CANPC_OK != (ret = CANPC_set_interrupt_event(threadData.events[INT_EVENT])))
  24.   {
  25. //    printf("-->Error set interrupt event 0x%X\n", ret);
  26.     CloseHandle(threadData.events[INT_EVENT]);
  27.     CloseHandle(threadData.events[END_EVENT]);
  28.     return(-1);
  29.   }
  30.  
  31.  
  32.   if (NULL == (intThread = (HANDLE) _beginthreadex(NULL, 0, interruptThread, 
  33.                                                    (void *) &threadData, 0, &tid)))
  34.   {
  35. //    printf("-->Error create interrupt thread 0x%X\n", GetLastError());
  36.     INIPC_close_board();
  37.     CloseHandle(threadData.events[INT_EVENT]);
  38.     CloseHandle(threadData.events[END_EVENT]);
  39.     return(-1);
  40.   }
  41.  
  42.   InitializeCriticalSection(&CriticalSectionForInterrupt);
  43.  
  44.   return(0);
  45. }
May 10 '07 #1
3 3847
weaknessforcats
9,208 Recognized Expert Moderator Expert
I presume you have entered unmanaged code? Yes?
May 10 '07 #2
AdrianH
1,251 Recognized Expert Top Contributor
It seems clear to me that threadData.events[INT_EVENT] is not of the right type.

It also appears to be a C# type.

IIRC, you will need some type of wrapper to allow the C# to interact directly with the Win32 API.


Adrian
May 10 '07 #3
weaknessforcats
9,208 Recognized Expert Moderator Expert
you will need some type of wrapper to allow the C# to interact directly with the Win32 API.
I think in C# you use the SecurityPermission object ndrequest access to umanaged code by s settting of the SecurityPermissionFlag. Once you have permission, you can call native Win32 functions using C++.

Checout all of the Ineroperability doeumentation provided for C# in Visual Studio.NET.
May 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

17
1735
by: Doug Fort | last post by:
This is an excerpt from a much longer post on the python-dev mailing list. I'm responding here, to avoid cluttering up python-dev. <snip> >Some English readers might not really imagine, but it...
0
2068
by: Prasad | last post by:
We are invoking a SQL DTS component (lets call it Comp1) built by us in another component (Comp2).Comp1 was built by creating the DTS package using the SQL DTS wizard and then saving it as a VB...
0
7008
by: Andy Read | last post by:
Hello all, I have the requirement to produce source code that produces an object hierarchy. Example: Root | Folder 1
10
7623
by: Ryan McGeary | last post by:
In a <select> drop-down, the onchange event isn't called when scrolling through the dropdown using the mouse-wheel and when crossing over a new <optgroup>. Using the example below, notice how...
4
2573
by: Joanna Carter \(TeamB\) | last post by:
I am trying to invoke an event using reflection. ////////////////////// public class Test { public event EventHandler NameChanged; public void CallEvent() {
2
9018
by: JCE | last post by:
I need to programmatically invoke an asp:Button click event from a javascript function. The page containing the script and the button is the HTML page associated with a WebUserControl-derived...
6
1367
by: Jon | last post by:
I have a service program that creates a crystal report and prints the report to a named printer driver. The printer driver raises an event when it is finished. I am supposed to trap for the...
22
2716
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
4
1365
by: Claire | last post by:
Visual Studio 2003 I have a thread running a small timeout. Rather than defining my own delegate I decided to be lazy and use a standard EventHandler delegate When OnReadMessageTimeout is...
2
9136
by: Sin Jeong-hun | last post by:
Suppose class Engine do something in another thread and raise events. class Engine { Thread Worker; public event ... EngineMessage; public void Start() { Worker=new Thread(new...
0
7207
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7291
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7357
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7012
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5598
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5023
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1522
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.