An illegal operation message

This is a discussion on An illegal operation message within the C++ Programming forums, part of the General Programming Boards category; This is my code: Code: #include <string> #include <windows.h> #include <iostream> #include <algorithm> using namespace std; bool DownloadFile(LPCTSTR URL , ...

  1. #1
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318

    An illegal operation message

    This is my code:
    Code:
    #include <string>
    #include <windows.h>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    bool DownloadFile(LPCTSTR URL , LPCTSTR LocalFilename); 
    typedef long (WINAPI * MYPROC)(long,LPCTSTR,LPCTSTR,DWORD,long);
    bool DownloadFile(LPCTSTR URL , LPCTSTR LocalFilename) 
    {        
        long lngRetVal;              
    	HMODULE hinstLib; 
        MYPROC ProcAdd;                                 
        BOOL fFreeResult, fRunTimeLinkSuccess = FALSE;
    	hinstLib = LoadLibrary("urlmon.dll");
      if(hinstLib != NULL)
      { 
    	ProcAdd = (MYPROC) GetProcAddress(hinstLib, "URLDownloadToFileA");
    	   if (NULL != ProcAdd) 
    	   {
                fRunTimeLinkSuccess = TRUE;
    		    lngRetVal = ProcAdd(0, URL, LocalFilename, 0, 0);
    		    fFreeResult = FreeLibrary(hinstLib);
    
    		}	
      }
    }
    int main(){
    string man;
    char est[200];
    cout<<"Tere tulemast!";
    cin.getline(est,200,'\n');
    cout<<"test1";
    man=strcat("http://maxorator.farvista.net/man.php?red=",est);
    cout<<"test2";
    char shelp[200];
    *(std::copy(man.begin(), man.end() - man.begin() < 200 ? man.end() : man.begin() + 199, shelp)) = 0;
    LPCTSTR URL = shelp;
    DownloadFile(URL,"C:\\My Documents\\temp2.abc");
    }
    It only couts test1, so that means the problem must be in this line:
    Code:
    man=strcat("http://maxorator.farvista.net/man.php?red=",est);
    If I tried to use debug, it displayed the blue screen and closed my compiler(Dev-C++).
    Any ideas?

  2. #2
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    Yep,
    The first argument must be a non constant char* variable, cause the second string('est') is appended on to it. but I'm not sure...

  3. #3
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    All you need:

    Code:
    	std::string url("http://maxorator.farvista.net/man.php?red="), temp;
    	std::getline(std::cin, temp);
    	url += temp;
    	DownloadFile(url.c_str(), "C:\\My Documents\\temp2.abc");
    Stick to std::string's, or char*'s, don't intermix them so. You got the illegal operation because the program was not able to append contents to a string literal in read-only code. Look at a strcat reference for appropriate use. You have a lot of wierd things in your code, keep it simple. You could simply link urlmon into your project too. If you got a bluescreen off of that, ... , yeah.

  4. #4
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    How can I link it to my project?

  5. #5
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Project Options (Alt-P), and libraries (I think).

    strcat() reference.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strange string behavior
    By jcafaro10 in forum C Programming
    Replies: 2
    Last Post: 04-07-2009, 08:38 PM
  2. Problem in message handling VC++
    By 02mca31 in forum Windows Programming
    Replies: 5
    Last Post: 01-16-2009, 09:22 PM
  3. socket message sending and receiving problem
    By black in forum C Programming
    Replies: 5
    Last Post: 01-15-2007, 04:46 AM
  4. Sending CChildView a Message :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-06-2002, 03:00 PM
  5. Illegal operation
    By nadkingcole in forum C Programming
    Replies: 2
    Last Post: 03-07-2002, 04:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21