--- In [email protected], Thomas Hruska <thru...@...> wrote:
>
> hari_poddar2009 wrote:
> > --- In [email protected], Thomas Hruska <thruska@> wrote:
> >> hari_poddar2009 wrote:
> >>> 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:
> >>>
> >> <snip>
> >>> 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!
> >> This is a linker issue. You probably need to add 'lz32.lib' to the
> >> linker dependency/library options.
> >>
> >
> > i created a new project and added the source file with my code to it.
> > i also mentioned 'lz32.lib' in the linker settings dialog box. i rebuilt
> > the make file as prompted and then compiled the project. i still got the
> > same error i mentioned in my previous post!
>
> You mentioned that you are using lcc win32, which I'm not familiar with.
> This is a linker error you will have to figure out. Alternatively,
> you could try using LoadLibrary()/GetProcAddress().
>
> --
> Thomas Hruska
> CubicleSoft President
> Ph: 517-803-4197
>
> *NEW* MyTaskFocus 1.1
> Get on task. Stay on task.
>
> http://www.CubicleSoft.com/MyTaskFocus/
>
yes i have been able to solve the problem in part by using LoadLibrary() and
GetProcAddress(). i have been able to decompress the file (after it has been
created and compressed) using LZOpenFile().
Now i want to append data to it. i used WriteFile() but the file's previous
data is getting overwritten. How do i make sure that the new data is appended
and not overwritten on previous data. Could u tell me if 'zlib' library is of
any use here? here's my latest code:
#include <stdio.h>
#include <windows.h>
#include <winioctl.h>
#include <conio.h>
typedef INT (*openFunc)(LPTSTR name,LPOFSTRUCT reOpen,WORD style);
openFunc myOpening;
extern LONG APIENTRY LZSeek(INT hFile,LONG offset,INT mode);
extern VOID APIENTRY LZClose(INT hFile);
void main(void)
{
CHAR filename[256],dirname[256],dllName[15],allUsers[512];
char inputData[256];
char *inputPtr;
inputPtr=&(inputData[0]);
HANDLE file;
OFSTRUCT open;
LPOFSTRUCT openPtr=&(open);
LPCSTR
namePtr=&(filename[0]),dirPtr=&(dirname[0]),dllPtr=&(dllName[0]),userPtr=&(allUsers[0]);
LPTSTR name2ptr;
DWORD
desAccess=GENERIC_READ|GENERIC_WRITE,share=FILE_SHARE_WRITE|FILE_SHARE_READ,creationMode=OPEN_ALWAYS,error;
DWORD envVar=0,flags=FILE_ATTRIBUTE_HIDDEN|FILE_ATTRIBUTE_SYSTEM;
LPCSTR envName="ALLUSERSPROFILE";
envVar=GetEnvironmentVariable(envName,userPtr,512);
if(envVar<=512){
CHAR *str="\\temp.dat";
namePtr=strcat(userPtr,str);
name2ptr=(LPTSTR)&(allUsers[0]);
printf("%s\n",namePtr);
printf("%s\n",name2ptr);
dllPtr="lz32.dll";
file=CreateFile(namePtr,desAccess,share,NULL,creationMode,flags,NULL);
error=GetLastError();
DWORD writeBytes=0;
LPDWORD bytesWritten=&(writeBytes);
HMODULE mod=LoadLibrary(dllPtr);
myOpening=(openFunc)GetProcAddress(mod,"LZOpenFileA");
if(mod!=NULL){
if(file!=INVALID_HANDLE_VALUE)
{
printf("Opening file.Checking status..\n");
if(error==0)/*file created*/
{
inputPtr="This is a very long line in a very large file that has to be
compressed!\n";
printf("File created. Writing....\n");
if(WriteFile(file,inputPtr,strlen(inputPtr),bytesWritten,NULL)){
printf("Data written!\n");
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,2,NULL,0,bytesRet,NULL)){
CloseHandle(file);
printf("File compressed!\n");
}
}
}
else if(error==183){/*file exists*/
printf("File exists.\n");
inputPtr="This is the next long line in a very large file is already
compressed!\n";
if(myOpening!=NULL){
INT result=(myOpening)(name2ptr,openPtr,OF_READWRITE);
printf("result = %d\n",result);
if(result!=-1 && result!=-5)
{
printf("Opened
compressed file..\n");
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)0,(INT)2);
printf("End
pos: %ld\n",pos);
printf("Writing
to file....\n");
WriteFile(file,inputPtr,strlen(inputPtr),bytesWritten,NULL);
CloseHandle(file);
printf("Finished writing!\n");
LZClose(result);
}
else
{
printf("File error code: %d\n",GetLastError());
}
}
else
{
printf("LZOpenFile
could not be invoked! ");
printf("%d\n",GetLastError());
}
}
printf("File closed...");
}
else
printf("No file!");
FreeLibrary(mod);
}
}
getch();
}