473,399 Members | 4,177 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Invalid Handle Error

Jay
Hey There,
When I run the code below, I get the error "The handle is invalid."
.. This is output in the 2nd fprintf. The first one gives me a success
message. What could be causing this?

-Jay
(patelj27b at gmail dot com)

char fileName[1024];
WIN32_FIND_DATA findData;
HANDLE findHandle;
HANDLE Handle2;
HANDLE volumeHandle;

static char volumeName[] = "\\\\.\\A:";
int i;
NTSTATUS status;
NTFS_FILE_RECORD_INPUT_BUFFER inBuffer;
NTFS_FILE_RECORD_OUTPUT_BUFFER outBuffer;
DWORD InBuffSize;
DWORD OutBuffSize;
LARGE_INTEGER RefNum;
DWORD bytesRet;
OVERLAPPED overLapVal;
int FileLength;
FILE* fp;
BOOL retVal;
LPVOID lpvMessageBuffer1;

inBuffer.FileReferenceNumber.u.HighPart = 0;
inBuffer.FileReferenceNumber.u.LowPart = 10;
inBuffer.FileReferenceNumber.QuadPart = 20;
inBuffer.FileReferenceNumber.HighPart = 0;
inBuffer.FileReferenceNumber.LowPart = 100;
InBuffSize = sizeof(NTFS_FILE_RECORD_OUTPUT_BUFFER) + recSize - 1;
volumeName[4] = DriveId + 'A';
volumeHandle = CreateFile( volumeName, GENERIC_READ,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
0, 0 );
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpvMessageBuffer1,
0, NULL);

fp = fopen(LOG_FILE,APPEND_MODE);
fprintf(fp,"errmsg=%s\n",lpvMessageBuffer1);
fclose(fp);

retVal = DeviceIoControl( volumeHandle,
FSCTL_GET_NTFS_FILE_RECORD,
(LPVOID)&inBuffer,
sizeof(NTFS_FILE_RECORD_INPUT_BUFFER),
(LPVOID)&outBuffer,
InBuffSize,
&bytesRet,
&overLapVal
);

if(retVal == 0)
{
FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM, NULL, GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPSTR)&lpvMessageBuffer1,
0, NULL);

fp = fopen(LOG_FILE,APPEND_MODE);
fprintf(fp,"errmsg=%s\n",lpvMessageBuffer1);
fclose(fp);
}

FileLength = (int)outBuffer.FileRecordLength;
fp = fopen(LOG_FILE,APPEND_MODE);
fprintf(fp,"Record Num=%d\n",outBuffer.FileReferenceNumber.LowPart);
for(i = 0;i <1000;i++)
fprintf(fp,"buffVal[%d]=%c\n",i,outBuffer.FileRecordBuffer[i]);
fclose(fp);
CloseHandle(volumeHandle);

May 16 '06 #1
0 1325

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

Similar topics

5
by: Danny | last post by:
Does anybody have a nice method of forcing a user to enter a value into a form using asp? I think the best is to have a popup when they hit submit that will stay on the same page and then just...
0
by: nek | last post by:
Would anyone have any ideas or come across the 'invalid handle' problem? Even after setting diaglevel=4, I could not get much out of the db2diag.log to diagnose the problem. The only thing I...
3
by: Frank Perry | last post by:
Howdy, I'm trying to write data out the com port. I have taken the code from the sample on the MSDN Library CD and used the parts that seem relevant. I can open the com port with CreateFile...
2
by: Schorschi | last post by:
Can't seemd to get ReadFile API to work! Returns invalid handle error? =========================================================================== Ok, the visual basic gurus, help! The...
3
by: Ajay Choudhary | last post by:
Hi, If the client tries to access a web service with invalid namespace, it gets a SOAP exception as invalid SOAPAction. The invalid namespace will happen because the proxies on the client side...
5
by: Eric | last post by:
I run a program which read emails from a text file. There is some thing invalid in one or more text file. When program is busy doing parsing it shows that error and process stop. I dont know which...
5
by: Grant Edwards | last post by:
I'm trying to use the py-gnuplot module on windows, and have been unable to get it to work reliably under Win2K and WinXP. By default, it uses popen(gnuplotcmd,'w'), but in some situations that...
10
by: SQACPP | last post by:
Hi, I try to figure out how to use Callback procedure in a C++ form project The following code *work* perfectly on a console project #include "Windows.h" BOOL CALLBACK...
8
by: Lambda | last post by:
When I call the standard strncpy function, I provide it a negative argument, such as: strncpy(s, ct, -1) I compile the code with gcc, when I run, it says "Segmentation fault". Do you think...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...

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.