Exception thrown at 0x7C573C1E (vcruntime140d.dll) in Project1.exe: 0xC0000005: Access violation writing location 0x8F003300

-1

Can anyone help me solve about this error? im still new at c++ programming, and im using C++/CLR to make button click event, also try to use curl library to get some http request. but instead i got that exception throw.

this is my button click code:

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
        System::String^ username = textBox1->Text;
        System::String^ password = textBox2->Text;
        CURLcode res;
        std::string readBuffer;
        System::String^ read;

        curl_global_init(CURL_GLOBAL_ALL);
        CURL* curl = nullptr;
        curl = curl_easy_init();
        if (curl)
        {
            //std::cout << url;
            curl_easy_setopt(curl, CURLOPT_URL, "www.google.com");
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, readBuffer);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
            CURLcode code = curl_easy_perform(curl);
            curl_easy_cleanup(curl);
        }

        curl_global_cleanup();
    }

and this is my write function outside button event:

int writer(char* data, size_t size, size_t nmemb, std::string* writerData)
    {
        if (writerData == NULL)
            return 0;

        writerData->append(data, size * nmemb);

        return size * nmemb;
    }

it got no error when i run it works fine, but after i click the button it shows error

c++
visual-c++
c++-cli
clr
libcurl
asked on Stack Overflow Oct 29, 2020 by Cupangku

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0