Visual C ++ 2010 Express版中的Windows窗体应用程序中的Libcurl错误

时间:2013-06-04 03:55:04

标签: libcurl

我在win32控制台应用程序中使用了libcurl,它运行正常。我从这里开始遵循指示。 http://theetrain.ca/tech/installing-curl-using-visual-studio-2010-beginners-guide/。现在我想在Windows Forms Application中使用Lib curl。但它显示出一些错误。

1>阅读网站app.obj:错误LNK2031:无法为“extern”C“void * __clrcall curl_easy_init(void)”生成p / invoke(?curl_easy_init @@ $$ J0YMPAXXZ);在元数据中调用约定缺失 1>阅读网站app.obj:错误LNK2028:未解析的令牌(0A000011)“extern”C“void * __clrcall curl_easy_init(void)”(?curl_easy_init @@ $$ J0YMPAXXZ)在函数“private:void __clrcall Readwebsiteapp :: Form1”中引用:: button1_Click(类System :: Object ^,类System :: EventArgs ^)“(?button1_Click @ Form1 @ Readwebsiteapp @@ $$ FA $ AAMXP $ AAVObject @ System @@ P $ AAVEventArgs @ 4 @@ Z) 1>阅读网站app.obj:错误LNK2019:未解析的外部符号“extern”C“void * __clrcall curl_easy_init(void)”(?curl_easy_init @@ $$ J0YMPAXXZ)在函数“private:void __clrcall Readwebsiteapp :: Form1 ::”中引用button1_Click(类System :: Object ^,类System :: EventArgs ^)“(?button1_Click @ Form1 @ Readwebsiteapp @@ $$ FA $ AAMXP $ AAVObject @ System @@ P $ AAVEventArgs @ 4 @@ Z) 1> C:\ Documents and Settings \ nemo1 \ my documents \ visual studio 2010 \ Projects \ Readwebsiteapp \ Debug \ Read website app.exe:致命错误LNK1120:2个未解析的外部

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

#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();
     }
    };
}

1 个答案:

答案 0 :(得分:0)

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