i need to write a program that checks for the existence of a file in the
application data folder referred by the environment variable %APPDATA%. If it
does not exist the file will be created, written to, compressed and closed. if
it exists then the file will be opened using LZOPenFile(). The end of file will
be sought and the file will be written to. Then the file will be closed with
LZClose(). My code is listed below:
#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
#include <conio.h>
extern INT APIENTRY LZOpenFile(LPTSTR name,LPOFSTRUCT reOpen,WORD style);
extern LONG APIENTRY LZSeek(INT hFile,LONG offset,INT mode);
extern VOID APIENTRY LZClose(INT hFile);
void main(void)
{
/*security descriptor needs to be added*/
CHAR filename[256],dirname[256];
char inputData[256];
char *inputPtr;
inputPtr=&(inputData[0]);
HANDLE file;
OFSTRUCT open;
LPOFSTRUCT openPtr=&(open);
LPCSTR namePtr=&(filename[0]),dirPtr=&(dirname[0]);
LPTSTR name2ptr=&(filename[0]);
DWORD desAccess=GENERIC_READ|GENERIC_WRITE;
DWORD share=FILE_SHARE_READ;
DWORD creationMode=OPEN_ALWAYS;
DWORD error;
DWORD flags=FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM;
/* *dirPtr="%APPDATA%\mydir";
namePtr=strcat(filename,dirPtr);*/
namePtr="%APPDATA%\temp.dat";
inputPtr="sdjsahdjkahdjhdjkshdjksahjkdsahdkjhsajkdhkjshdjksahdksafdskprif0-ewfpdslfjkdsrfoeidsfkeporifeopio";
file=CreateFile(namePtr,desAccess,share,NULL,creationMode,flags,NULL);
DWORD writeBytes=0;
LPDWORD bytesWritten=&(writeBytes);
if(file!=INVALID_HANDLE_VALUE)
{
printf("Opening file.Checking status..\n");
error=GetLastError();
if(error==0)/*file created*/
{
printf("File created. Writing....\n");
if(WriteFile(file,inputPtr,sizeof(*inputPtr),bytesWritten,NULL)){
DWORD ioCode=FSCTL_SET_COMPRESSION;
DWORD bytes=0;
LPDWORD bytesRet=&(bytes);
USHORT format[1];
LPVOID inBuffer=&(format[0]);
format[0]=COMPRESSION_FORMAT_DEFAULT;
if(DeviceIoControl(file,ioCode,inBuffer,1,NULL,0,bytesRet,NULL))
CloseHandle(file);
}
}
else if(error==183){/*file exists*/
printf("File exists.\n");
INT result=LZOpenFile(name2ptr,openPtr,OF_READWRITE);
if(result!=-1 && result!=-5)
{
BOOL success;
LONG pos=0;
LARGE_INTEGER largeStruct;
PLARGE_INTEGER fileSize=&(largeStruct);
success=GetFileSizeEx(file,fileSize);
if(success){
printf("Seeking EOF..\n");
pos=LZSeek(result,(LONG)fileSize->QuadPart,(INT)0);
printf("Writing to file....\n");
WriteFile(file,inputPtr,sizeof(*inputPtr),bytesWritten,NULL);
CloseHandle(file);
}
else
printf("Could not get file size!\n");
LZClose(result);
}
}
printf("File closed...");
}
else
printf("No file!");
getch();
}
i am using the lcc win32 compiler and am getting the error message:
"undefined reference to _lzopenf...@12" in the line which calls
INT result=LZOpenFile(name2ptr,openPtr,OF_READWRITE);
please help!