473,763 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What's Wrong with this program

dfound
52 New Member
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 2257
DeMan
1,806 Top Contributor
Looks to me like that's what it does......sorry maybe I don't understand ur question
Feb 20 '07 #2
RedSon
5,000 Recognized Expert Expert
The dialog box does appear, what is your problem exactly?
Feb 20 '07 #3
dfound
52 New Member
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
7172
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 pragmatic - 3) I usually move forward when I get the gut feeling I am correct - 4) Most likely because of 1), I usually do not manage to fully explain 3) when it comes true. - 5) I have developed for many years (>18) in many different environments,...
125
14835
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 software giant such as Microsoft SQL Server, Oracle, and Sybase? Is PostgreSQL reliable enough to be used for high-end commercial application? Thanks
5
2835
by: titan0111 | last post by:
#include<iostream> #include<iomanip> #include<cstring> #include<fstream> using namespace std; class snowfall { private: int ft;
1
2144
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 the subprocess and receives data from the pipe. When some event occurs (e.g. the user clicks the 'Stop' button on GUI), the main program will send the subprocess a command to change its behavior or ask it to exit. However, my code (attached...
46
4248
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 believe MSFT should do to improve C#, however. I know that in the "Whidbey" release of VS.NET currently
669
26182
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 paper written on this subject. On the Expressive Power of Programming Languages, by Matthias Felleisen, 1990. http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
3
2748
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 Peep/view the item at the top of the stack Current value of top View all items stored in the stack Quit *the stack accepts lowercase & uppercase characters only from A-Z
20
2818
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
2111
by: broli | last post by:
#include<stdio.h> #include<stdlib.h> struct point { double x, y, z;
4
1965
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 that line, it is written. i wanna understand what's wrong and fix it, but can't find what is wrong. also this line is mandatory in my code. the code attached is in the link, minimized to the needed info, a bit different then the way it's...
0
9566
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9389
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10149
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10003
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8825
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 projectplanning, coding, testing, and deploymentwithout 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
5271
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
5410
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3529
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2797
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.