libcURL init access violation
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11

Thread: libcURL init access violation

Hybrid View

  1. #1
    Join Date
    Jul 2010
    Posts
    10

    Question libcURL init access violation

    Using libcURL for a simple data retrieval program

    when I call the init function:
    curl_global_init(CURL_GLOBAL_ALL);
    an access violation occurs

    I also tried using the parameter CURL_GLOBAL_DEFAULT instead (out of curiosity) and it didn't help

    I'm linking against the dll/lib and I also have copies of the dlls in my project directory

    can anybody help me figure out how to get this fixed?
    thanks

  2. #2
    Join Date
    Jan 2009
    Posts
    1,689

    Re: libcURL init access violation

    Where? Does the access violation happen because you called curl_global_init, or within the function itself? curl_global_init doesn't really do a whole lot, so my guess is that the function isn't loading correctly from the dll.

    Also, what are you doing with libcurl, most things can be done with the curl_easy... methods, which don't require you call curl_global_init. Unless you're doing in-depth SSL or something, you probably don't need it.

  3. #3
    Join Date
    Jul 2010
    Posts
    10

    Re: libcURL init access violation

    it happens when I call it
    I wish there was an easy way to tell if I finally got the lib/dll added correctly

    I'm just trying to do a simple http request

    (I would call it from winsock but servers won't talk to me when I use winsock :-/ )

  4. #4
    Join Date
    Jan 2009
    Posts
    1,689

    Re: libcURL init access violation

    Forget winsock, use the libcurl built-in functions.

    Now I'm writing this in the forum, so I haven't tested but
    Code:
    string getPage(const string & url){
         string buffer;
         if (CURL * curl = curl_easy_init()){
              CURLcode res;
              curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
              curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
              curl_easy_setopt(easyhandle, CURLOPT_WRITEDATA, &buffer);
              curl_easy_perform(curl);
              curl_easy_cleanup(curl);
         }
         return buffer;
    }
    
    int writer(void * data, int size, int count, void * buffer){
         char * newdata = memcpy((char*)malloc(size * count + 1), size* count, buffer);
         newdata[size * count] = '\0';
         ((string *)buffer) -> append(newdata);
         free(newdata);
         return size * count;
    }

  5. #5
    Join Date
    Jul 2010
    Posts
    10

    Re: libcURL init access violation

    <s>[s]now curl_easy_init() crashes instead

    it must be my dlls :-([/s]</s>


    edit:
    thanks for the excellent code

    I decided to try it in the almighty dev-cpp instead and it works perfectly

    There's something incompetent happening behind the scenes with VS that's making it not take the libs and relate to the need for its dlls properly

    I guess this section isn't exactly a compiler support forum but I will need it to work in VS eventually
    Any thoughts on what may be wrong?
    Last edited by invaderjolleyolleyman; July 2nd, 2010 at 02:34 PM. Reason: update

  6. #6
    Join Date
    Apr 1999
    Posts
    27,446

    Re: libcURL init access violation

    Quote Originally Posted by invaderjolleyolleyman View Post
    <s>[s]now curl_easy_init() crashes instead

    it must be my dlls :-([/s]</s>


    edit:
    thanks for the excellent code

    I decided to try it in the almighty dev-cpp instead and it works perfectly
    Please note that Dev-CPP is not a compiler. The actual compiler is g++, and Dev-CPP last worked with a a very old version of g++.

    Regards,

    Paul McKenzie

  7. #7
    Join Date
    Jul 2010
    Posts
    10

    Re: libcURL init access violation

    yes, I'm well aware of that
    I've used the same 'compiler' on other systems before

    Most people use comfortable terms like compiler rather loosely however

    such as calling visual studio a compiler when in fact there are only a few files in it's bin directory which are actually related to compilation

    perhaps if I had called it an IDE you'd have felt more comfortable? XD



    I'm in the process of trying to put libcurl in a new DLL for VS but don't expect to have much luck
    If anyone has any tips on that, they'd also be appreciated

    thx and sorry if I'm getting to far off-topic

  8. #8
    Join Date
    Apr 1999
    Posts
    27,446

    Re: libcURL init access violation

    Quote Originally Posted by invaderjolleyolleyman View Post
    I'm in the process of trying to put libcurl in a new DLL for VS but don't expect to have much luck
    If anyone has any tips on that, they'd also be appreciated

    thx and sorry if I'm getting to far off-topic
    Did you try this:

    http://curl.haxx.se/dlwiz/?type=deve...in32&flav=MSVC

    Regards,

    Paul McKenzie

  9. #9
    Join Date
    Jan 2009
    Posts
    1,689

    Re: libcURL init access violation

    I'll be I know exactly what is wrong. curl.dll almost certainly was compiled using MinGW, and MinGW mangles names differently than VC++, so VC++ programs can't find the functions that you are looking for. A library compiled for MinGW can not be used in VC++, and vise versa.

    FYI, Dev-C++ is deprecated, it has been merged with Code::Blocks, so I recommend using that instead.

  10. #10
    Join Date
    Jul 2010
    Posts
    10

    Re: libcURL init access violation

    thx for the info
    that helps a lot

    -and extra thanks for telling me about Code::Blocks
    I knew Dev-cpp was discontinued and still had some issues but didn't know there was a new one
    I'll look into it

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center