473,324 Members | 2,356 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,324 software developers and data experts.

What's Wrong with this program

dfound
52
Expand|Select|Wrap|Line Numbers
  1. #include<windows.h>
  2. #include<dos.h>
  3. #include<dir.h>
  4. #include<fstream.h>
  5. #include<stdio.h>
  6. #include<process.h>
  7.  
  8. #include"resource.h"       //resource header file
  9.  
  10.  
  11. long convert(char *pass)   //to convert password in to long integer
  12. {
  13. long total=0;
  14. for(int i=0;i<strlen(pass);i++)
  15. {
  16.  total+=pass[i];
  17.  }
  18.  total=total;
  19. return(total);
  20. }
  21.  
  22.  
  23. int check(char *p)     // to check if the path entered is a file or directory
  24. {
  25. int done;
  26. struct ffblk ffblk;
  27. done=findfirst(p,&ffblk,0);
  28. while(!done)
  29. {
  30. if(ffblk.ff_attrib&&FA_DIREC)    //returns 1 if its a directory
  31. return(1);
  32. done=findnext(&ffblk);
  33. }
  34. return(0);
  35. }
  36.  
  37. int encode(char *path,int op,char *pass) //fuction to encode file
  38. {
  39. long password=0;
  40. int done;
  41. char ch;
  42. double ctr;
  43. ifstream fin;
  44. ofstream fout;
  45. struct ffblk ffblk;
  46. switch(op)
  47. {
  48. case 0:ctr=0;
  49.         password=convert(pass);
  50.        fin.open(path,ios::in|ios::binary);
  51.        fout.open(path,ios::out|ios::ate|ios::nocreate|ios::binary);
  52.        if(!fin||!fout)     //place where something goes wrong I think
  53.        return(-1);
  54.        while(!fin.eof())
  55.        {
  56.         fin.seekg(ctr);
  57.         fin.get(ch);         //reading each character
  58.         if(fin.eof())
  59.         break;
  60.         ch=int(ch+password); //adding some value to character(encoding)
  61.         fout.seekp(ctr);
  62.         fout.put(ch);
  63.         ctr++;
  64.         }
  65.         fout.flush();
  66.         fin.close();
  67.         fout.close();
  68.         break;
  69.  
  70. case 1:chdir(path);         //changing directory if the entere path is a folder
  71.        done=findfirst("*.*",&ffblk,0);     //searching every file
  72.        while(!done)
  73.        {
  74.        encode(ffblk.ff_name,0,pass);  
  75.        done=findnext(&ffblk);
  76.        }
  77.        break;
  78. default:return(-1);
  79. }
  80. return(0);
  81. }
  82.  
  83. int decode(char *path,int op,char *pass) //to decode file:similar to encode
  84. {
  85. long password=0;
  86. int done;
  87. char ch;
  88. double ctr;
  89. ifstream fin;
  90. ofstream fout;
  91. struct ffblk ffblk;
  92. if(op==-1)
  93. return(-1);
  94. switch(op)
  95. {
  96. case 0:ctr=0;
  97.         password=convert(pass);
  98.        fin.open(path,ios::in|ios::binary);
  99.        fout.open(path,ios::out|ios::ate|ios::nocreate|ios::binary);
  100.        if(!fout||!fin)
  101.        return(-1);
  102.        while(!fin.eof())
  103.        {
  104.         fin.seekg(ctr);
  105.         fin.get(ch);
  106.         if(fin.eof())
  107.         break;
  108.         ch=ch-int(password);
  109.         fout.seekp(ctr);
  110.         fout.put(ch);
  111.         ctr++;
  112.         }
  113.         fout.flush();
  114.         fin.close();
  115.         fout.close();
  116.         break;
  117. case 1:chdir(path);
  118.        done=findfirst("*.*",&ffblk,0);
  119.        while(!done)
  120.        {
  121.        decode(ffblk.ff_name,0,pass);
  122.        done=findnext(&ffblk);
  123.        }
  124.        break;
  125. }
  126. return(0);
  127. }
  128.  
  129.  
  130. //No problem here I think.Here's where the dialog box stuff go
  131.  
  132. BOOL CALLBACK DlgProc(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
  133. {
  134. switch(msg)
  135. {
  136. case WM_INITDIALOG:SetDlgItemText(hwnd,IDC_TEXT_I,""); 
  137.               SetDlgItemText(hwnd,IDC_TEXT_II,"");
  138.               break;
  139. case WM_COMMAND   :
  140.                    switch(LOWORD(wParam))
  141.                    {
  142.                    case IDC_ENCODE:{
  143.                    int len1=GetWindowTextLength(GetDlgItem(hwnd,IDC_TEXT_I));
  144.                    int len2=GetWindowTextLength(GetDlgItem(hwnd,IDC_TEXT_II));
  145.                    if(len1>0&&len2>0)
  146.                    {
  147.                     char *buf1,*buf2;
  148.                     buf1=(char*)GlobalAlloc(GPTR,len1+1);
  149.                     buf2=(char*)GlobalAlloc(GPTR,len2+1);
  150.                     GetDlgItemText(hwnd,IDC_TEXT_I,buf1,len1+1);
  151.                     GetDlgItemText(hwnd,IDC_TEXT_II,buf2,len2+1);
  152.                     int i=check(buf1);
  153.                     int e=encode(buf1,i,buf2);
  154.                     if(e==0)
  155.                     {
  156.                     MessageBox(hwnd,"ENCODING COMPLETED","REPORT",MB_OK|MB_ICONINFORMATION);
  157.                     SetDlgItemText(hwnd,IDC_TEXT_I,"");
  158.                     SetDlgItemText(hwnd,IDC_TEXT_II,"");
  159.                     }
  160.                     else if(e==-1)
  161.                     {
  162.                     MessageBox(hwnd,"ERROR IN ENCODING PROCESS","REPORT",MB_OK|MB_ICONEXCLAMATION);//This shows up as error
  163.  
  164.                     }
  165.                     GlobalFree((HWND)buf1);
  166.                     GlobalFree((HWND)buf2);
  167.                     }
  168.                     else
  169.                     {
  170.                     MessageBox(hwnd,"PARAMETER(S) MISSING","WARNING",MB_OK|MB_ICONEXCLAMATION);
  171.                     }}
  172.                     break;
  173.                     case IDC_DECODE:{
  174.                    int len1=GetWindowTextLength(GetDlgItem(hwnd,IDC_TEXT_I));
  175.                    int len2=GetWindowTextLength(GetDlgItem(hwnd,IDC_TEXT_II));
  176.                    if(len1>0&&len2>0)
  177.                    {
  178.                     char *buf1,*buf2;
  179.                     buf1=(char*)GlobalAlloc(GPTR,len1+1);
  180.                     buf2=(char*)GlobalAlloc(GPTR,len2+1);
  181.                     GetDlgItemText(hwnd,IDC_TEXT_I,buf1,len1+1);
  182.                     GetDlgItemText(hwnd,IDC_TEXT_II,buf2,len2+1);
  183.                     int i=check(buf1);
  184.                     int e=decode(buf1,i,buf2);
  185.                     if(e==0)
  186.                     {
  187.                     MessageBox(hwnd,"ENCODING COMPLETED","REPORT",MB_OK|MB_ICONINFORMATION);
  188.                     SetDlgItemText(hwnd,IDC_TEXT_I,"");
  189.                     SetDlgItemText(hwnd,IDC_TEXT_II,"");
  190.                     }
  191.                     else if(e==-1)
  192.                     {
  193.                     MessageBox(hwnd,"ERROR IN DECODING PROCESS","REPORT",MB_OK|MB_ICONEXCLAMATION);//This shows up as error
  194.                     }
  195.                     GlobalFree((HWND)buf1);
  196.                     GlobalFree((HWND)buf2);
  197.                     }
  198.                     else
  199.                     {
  200.                     MessageBox(hwnd,"PARAMETER(S) MISSING","WARNING",MB_OK|MB_ICONEXCLAMATION);
  201.                     }}
  202.                     break;
  203.                     case IDC_about:MessageBox(hwnd,"FE for WINDOWS\r\n   -by-  \r\nRAHUL.ES\r\nCreated:18-2-07\r\nContact:es_rahul@yahoo.co.in","ABOUT",MB_ICONINFORMATION|MB_OK);
  204.                     break;
  205.                     }
  206.                     break;
  207. case WM_CLOSE       : EndDialog(hwnd,0);
  208.                       break;
  209. default             : return FALSE;
  210. }
  211. return TRUE;
  212.  
  213.  
  214. //WinMain
  215.  
  216. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
  217. {
  218. HICON hMyIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MYICON));
  219.  
  220. return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAIN), NULL, DlgProc)
  221. ;
  222. }
  223.  
  224.  
The above program is a simple program using WinApi to encode and decode files.But every time I execute it,the dialog box mentioned above in the comments appear.I can't figure out how to correct the error...

Please Help.... :-)
Feb 18 '07 #1
3 2238
DeMan
1,806 1GB
Looks to me like that's what it does......sorry maybe I don't understand ur question
Feb 20 '07 #2
RedSon
5,000 Expert 4TB
The dialog box does appear, what is your problem exactly?
Feb 20 '07 #3
dfound
52
Sorry,I meant the Message Box ,not Dialog Box.The Message Box appears saying "ERROR DURING ENCODING PROCESS"
What should I do???
Feb 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
5
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
1
by: Qiangning Hong | last post by:
I decide to seperate my data collection routine from my data analysis and storage program to a seperate process, so I try to use the new subprocess model in Python 2.4. The main program spawns...
46
by: Keith K | last post by:
Having developed with VB since 1992, I am now VERY interested in C#. I've written several applications with C# and I do enjoy the language. What C# Needs: There are a few things that I do...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
3
by: belton180 | last post by:
CODE]../* Program function: Simulate the stack using a stack limit of 10. Display a menu for the the following. Create a stack Insert an item in the stack Pop an item from the stack ...
20
by: Daniel.C | last post by:
Hello. I just copied this code from my book with no modification : #include <stdio.h> /* count characters in input; 1st version */ main() { long nc; nc = 0;
12
by: broli | last post by:
#include<stdio.h> #include<stdlib.h> struct point { double x, y, z;
4
by: hirsh.dan | last post by:
i have a functions that writes information to a file. inside that function i have a line in which i call another function. if this line is executed, nothing is written to the file, but if i remark...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.