473,467 Members | 1,514 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ReadFileEx callback doesn't work - simple question

Hi all,

After having checked some of these threads out I realized that you
guys here on the forum probably will solve my problem in no-time,
while it is a tough problem for me.

In your answers - please be explainatory and tell the obvious as I am
a hardware guy trying to make a sw driver to a com-port. That's
another way of saying "I kinda suck at programming" :)

Ok - here goes:

I first used ReadFile and it worked nicely. Then I exchange it with
ReadFileEx and try and interface it like this: (I've rearranged the
code in a try to make it simple to interpret)

//First I have a callback declared as:
private callback my_callback;
//And it looks like this:
private delegate void callback(int nErrorCode,
int nNumberOfBytesTransfered,
ref OVERLAPPED lpOverlapped);
//When I create my file I also create the callback function:
my_callback = new callback(this.this_happens_after_callback);
//And the input to "my_callback" is:
private void this_happens_after_callback(int nErrorCode,
int nNumberOfBytesTransfered,
ref OVERLAPPED lpOverlapped)
{
}
//After I have started the program I make a new lpOverlapped, and call
ReadFileEx:
OVERLAPPED ovlCommPort = new OVERLAPPED();
ReadFileEx(hComm,BufBytes,NumBytes,ref ovlCommPort, ref
my_callback);

//Some additional information:

//I create the file like this:
hComm = CreateFile("COM" + PortNum ,GENERIC_READ |
GENERIC_WRITE,0, 0,OPEN_EXISTING,FILE_FLAG_OVERLAPPED,0);

//My OVERLAPPED looks like this:
[StructLayout(LayoutKind.Sequential)]
private struct OVERLAPPED {
public int Internal;
public int InternalHigh;
public int Offset;
public int OffsetHigh;
public int hEvent;
}
//And this is what the import looks like:
[DllImport("kernel32.dll")]
private static extern bool ReadFileEx(
int hFile, // filehandle
byte[] lpBuffer, // data buffer
int nNumberOfBytesToRead, // number of bytes to read
ref OVERLAPPED lpOverlapped, // overlapped buffer
ref callback lpCompletionRoutine // pointer to the completion
routine... I think.
);

Now for the (to me) strange part: I never enter the callback-function!
Why is this? That is why I don't have anything written in
"this_happens_after_callback" - it is useless as I never enter the
procedure...

I would be most grateful for help in this matter, as I've been trying
and trying for a whole day to make it work - without success...

Regards,
Christian
Nov 13 '05 #1
1 5394
egl
1 New Member
You need to call SleepEx API and set Alertable to 1 or True right after your call to ReadFileEx. This will get you into that callback. regards - egl
Feb 22 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ash | last post by:
Hello all, I am hoping this is the appropriate newsgroup for a C++ interface design question. I am trying to design an interface for a subscriber to register/deregister handlers for various...
20
by: chris.schwalm | last post by:
This is part II of this <a...
5
by: Maxwell | last post by:
Hello, Newbie question here. I have a VS.NET 2003 MC++ (not C++/cli) project where I have a managed class reference in a unmanaged class...simple enough. To keep things short I am for the most...
6
by: Minfu Lu | last post by:
I have a problem dealing with passing a function address to a COM callback. I use this COM function for communicating to a hardware. My original project was written in VB. I have converted it to...
0
by: Robert | last post by:
After failing on a yield/iterator-continuation problem in Python (see below) I tried the Ruby (1.8.2) language first time on that construct: The example tries to convert a block callback interface...
4
by: sloan | last post by:
I"m trying to figure out what concept I'm missing here, or if its not a good idea .. or what. Here is my example.. code is below. I have an employee class. It has an event that can be raised....
0
by: Brian | last post by:
Hi, I've been trying to get a simple client / script callback to work. I was using IE6 to the ASP Development Server / IIS 5 and it just didn't work. I ended up using an example straight from an...
0
by: rich | last post by:
Hi all, I have a fairly complex "feed" application that recieves messages from an external user-supplied API via a callback function, and attempts to forward these messages to another...
6
by: smmk25 | last post by:
Before I state the problem, I just want to let the readers know, I am knew to C++\CLI and interop so please forgive any newbie questions. I have a huge C library which I want to be able to use in...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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
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,...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.