473,769 Members | 1,730 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::ReadBusEv ent 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 3860
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.even ts[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 SecurityPermiss ion object ndrequest access to umanaged code by s settting of the SecurityPermiss ionFlag. 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
1754
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 is a constant >misery, having to mangle identifiers while documenting and thinking >in languages other than English, merely because the Python notion of >letter is limited to the English subset. Granted, keywords and standard >library use...
0
2119
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 .bas file - this was converted to .NET class module. To this module we added some cutom transformation tasks. An additional info - we are invoking Comp1 in a loop inside Comp2. The transformation succesfully happens for a few files in the list...
0
7047
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
7656
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 the onchange event isn't called when mouse wheel scrolling between A3 and B1, but it works properly when scrolling between A1 and A2. E.g. ------------------------------------------
4
2591
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
9055
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 object (both the HTML and control are built in the same .ascx file) The target button simply fires an event in the WebUserControl-derived object. So, alternatively, if there was a mechanism to call a method (explicitly or using an event of some...
6
1388
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 following event to determine when I can continue with my code flow. Event: %printername%.mfx.complete Can anyone help me out with some sample code to loop and wait for this event? I found one example in C#, but I'm not having much luck getting to...
22
2778
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 fun() {
4
1376
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 called, "sender" appears to points to the form that started the thread rather than Thread.CurrentThread.Name. What is going wrong please? _ReadTimeoutThread = new Thread(new ThreadStart(OnReadMessageLoop));
2
9153
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 ThreadStart(Run)); Worker.Start();
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3958
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 we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.