473,786 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Reading file fails with ReadFile

Hi,

I have a windows MDI program that draws some shapes that can
be saved into a file and read from that file.
The save seems to work with the WriteFile function, but for some
reason
the ReadFile function fails. These WriteFile/ReadFile are win32 api
functions.

I'll post both, the read and write function codes here so you can take
a
look at and perhaps see what the problem is.

---- code WriteFile start -----
BOOL WriteDrzFile(HW ND hwnd, LPSTR pstrFile, PTHINGZDATA pThingzData)
{
HANDLE theFile;
BOOL bSuccess = FALSE;

DWORD dwSize;

char szTmp[255], szOut[255];
PtrThingzShapeS ave thingzSaveData;

pThingzData->pController->shapez = pThingzData->pController-
>_model.GetShap es ();
thingzSaveData = pThingzData->pController->shapez.thingzS aveData;

theFile = CreateFile(pstr File, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, FILE_ATTRIBUTE_ NORMAL, NULL);

if (theFile != INVALID_HANDLE_ VALUE)
{
DWORD structLength;
structLength = sizeof(thingzSa veData);
if (structLength 0)
{
RECT rect;
DWORD dwBufferSize = structLength + 1;

if (pThingzData != NULL)
{
DWORD dwWritten;

if(WriteFile(th eFile, thingzSaveData, structLength, &dwWritten,
NULL))
{
bSuccess = TRUE;
}
}
}
CloseHandle(the File);
}
return bSuccess;
}
---- code WriteFile end -----

---- code ReadFile start -----
BOOL ReadDrzFile(HWN D hwnd, LPSTR pstrFile, static Controller * pCtrl)
{
HANDLE theFile;
DWORD dwSize;
char szTmp[255], szOut[255];
PtrThingzShapeS ave thingzSaveData;
PTHINGZDATA pThingzData;

pThingzData->pController = pCtrl;

theFile = CreateFile(pstr File, GENERIC_READ, FILE_SHARE_DELE TE, NULL,
OPEN_ALWAYS, FILE_ATTRIBUTE_ ARCHIVE, NULL);

if (theFile != INVALID_HANDLE_ VALUE)
{
DWORD dwFileSize;

dwFileSize = GetFileSize(the File, NULL);
if(dwFileSize != 0xFFFFFFFF)
{
if (pThingzData != NULL)
{
DWORD dwRead;

if(ReadFile(the File, thingzSaveData, dwFileSize,
&dwRead, NULL))
{
pThingzData->pController->ShapeDrawFile( thingzSaveData, hwnd);
}
}
}
CloseHandle(the File);
}
return FALSE;
}
---- code ReadFile end -----

In the code the thingzSaveData is a structure which holds the saved
elements.
If there's some more explanations needed, I will try to answer any
questions to
make it clearer.

Thanks in advance.

----
Jun 27 '08 #1
1 2122
mkarja wrote:
Hi,

I have a windows MDI program that draws some shapes that can
be saved into a file and read from that file.
The save seems to work with the WriteFile function, but for some
reason
the ReadFile function fails. These WriteFile/ReadFile are win32 api
functions.

I'll post both, the read and write function codes here so you can take
a
look at and perhaps see what the problem is.
And this question, which relates only to the Win32 API is off-topic here.

Try a newsgroup with Windows or Microsoft in its title.

Please see FAQ 5.9,
http://www.parashift.com/c++-faq-lit...t.html#faq-5.9
Jun 27 '08 #2

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

Similar topics

5
2849
by: Benjamin de Waal | last post by:
Hey all, I'm trying to figure out how to directly write to a device in Windows. Basically, what I'm wanting to do is create an image of a device (specifically, a CompactFlash card that uses a filesystem Windows doesn't recognise), store it as a file, modify it and dump it back to the card. Currently, in version 0.001 of my program, I'm just calling "dd for Windows" using ShellExecute - this works perfectly, but obviously this isn't...
40
4604
by: googler | last post by:
I'm trying to read from an input text file and print it out. I can do this by reading each character, but I want to implement it in a more efficient way. So I thought my program should read one line at a time and print it out. How can I do this? I wrote the code below but it's not correct since the fscanf reads one word (terminating in whitespace or newline) at a time, instead of reading the whole line. #include <stdio.h> void...
4
8372
by: Jason Kumpf | last post by:
OK I've been staring at this code all day and still with everything I have tried I cannot figure out two problems I am having. Once is why the space limit for the directory I create in the code fails. Second, why the data reader is reading every other record. Here is all of the source code for my little application followed by the contents of the log file that it dumps out:...
8
3519
by: Andrew Robert | last post by:
Hi Everyone. I tried the following to get input into optionparser from either a file or command line. The code below detects the passed file argument and prints the file contents but the individual swithces do not get passed to option parser.
2
5201
tshabza
by: tshabza | last post by:
Could anyone give me idea on how to read a wave and convert in into an integer array file using C++, for now I can successfullly read text file.
5
32467
by: Anja | last post by:
Hi everyone, I have a question about text file reading with VBA. I want to read he whole contents of the file in one string variable. I have been able to successfully read lines using: Line Input #inputFile, inputLine ' read line into inputLine string But is there any input command that lets me read the whole file into a
3
2426
by: scorro1 | last post by:
Hey guys, I am working on a program which is supposed to read input from a file at 100 chars per time, then change the spaces to underscores and reverse the order of the entire document. Now we are not allowed to go over 100 input characters per time. I had the project finished until i realized that after 100 characters the program would print the incorrect part first. for (i=0;i<n;i++) { if(buffer== 32) ...
2
2239
by: doublemaster007 | last post by:
Hi How to read binary files in MAC OS? FILE *readFile = fopen("filename", "rb"); then reading it like this: count=fread(readBuffer, sizeof(char), bufferSize, readFile)
4
7905
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on both the Project2.java and HouseGUI.java Here are the requirements for those two. The GUI Create a class called HouseGUI which extends JFrame. It should display two text areas (JTextArea) in a grid layout (1 row, 2 columns). Your main program,...
1
10108
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
9960
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8988
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...
0
6744
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();...
0
5397
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
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
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
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.