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: - 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
(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: - /**********************************************************
-
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);
-
}
3 3860
I presume you have entered unmanaged code? Yes?
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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...
|
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
|
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.
------------------------------------------
|
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()
{
| |
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...
|
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...
|
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()
{
|
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));
|
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();
|
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,...
| |
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...
|
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,...
|
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...
|
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...
|
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();...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |