0

我在 win32 控制台应用程序中使用了 libcurl,它工作正常。我已按照此处的指示进行操作。http://theetrain.ca/tech/installing-curl-using-visual-studio-2010-beginners-guide/。现在我想在 Windows 窗体应用程序中使用 Lib curl。但它显示了一些错误。

1>读取网站app.obj:错误LNK2031:无法为“extern "C" void * __clrcall curl_easy_init(void)" (?curl_easy_init@@$$J0YMPAXXZ)生成p/invoke;元数据1>读取网站app.obj中缺少调用约定:错误LNK2028:未解析的令牌(0A000011)“extern”C“void * __clrcall curl_easy_init(void)”(?curl_easy_init@@$$J0YMPAXXZ)在函数“private:void”中引用__clrcall Readwebsiteapp::Form1::button1_Click(class System::Object ^,class System::EventArgs ^)" (?button1_Click@Form1@Readwebsiteapp@@$$FA$AAMXP$AAVObject@System@@P$AAVEventArgs@4@ @Z) 1>读取网站 app.obj : error LNK2019: unresolved external symbol "extern "C" void * __clrcall curl_easy_init(void)" (?curl_easy_init@@$$J0YMPAXXZ) 在函数“private:

请给我一些建议来解决这个问题。谢谢你。我的代码是:

#define CURL_STATICLIB
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>
#include <string.h>
using namespace std;
#pragma once
namespace Readwebsiteapp {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  button1;
    protected: 
    private: System::Windows::Forms::TextBox^  textBox1;

    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->button1 = (gcnew System::Windows::Forms::Button());
            this->textBox1 = (gcnew System::Windows::Forms::TextBox());
            this->SuspendLayout();
            // 
            // button1
            // 
            this->button1->Location = System::Drawing::Point(120, 70);
            this->button1->Name = L"button1";
            this->button1->Size = System::Drawing::Size(75, 23);
            this->button1->TabIndex = 0;
            this->button1->Text = L"button1";
            this->button1->UseVisualStyleBackColor = true;
            this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
            // 
            // textBox1
            // 
            this->textBox1->Location = System::Drawing::Point(120, 153);
            this->textBox1->Name = L"textBox1";
            this->textBox1->Size = System::Drawing::Size(100, 20);
            this->textBox1->TabIndex = 1;
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(420, 337);
            this->Controls->Add(this->textBox1);
            this->Controls->Add(this->button1);
            this->Name = L"Form1";
            this->Text = L"Form1";
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
    private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e)
    {
        textBox1->Text = "hello";

        CURL *curl;
        CURLcode result;

        curl = curl_easy_init();
     }
    };
}
4

1 回答 1

0

由于您正在编译托管 C++,因此您的本机 curl 调用需要通过 p/Invoke 进行编组。将这些封装在扁平的“C”调用中可能是最简单的,以使编组更简单。在任何情况下,我都会使用 P/Invoke Interop Assistant 工具 ( http://clrinterop.codeplex.com/releases/view/14120 ) 来生成必要的签名。

于 2013-06-04T04:13:51.993 回答