2013-06-04 69 views
0

我在win32控制台应用程序中使用了libcurl,它工作正常。我遵循了这里的指示。 http://theetrain.ca/tech/installing-curl-using-visual-studio-2010-beginners-guide/。现在我想在Windows窗体应用程序中使用Lib curl。但它显示出一些错误。Visual C++ 2010 Express Edition中的Windows窗体应用程序中的Libcurl错误

1>阅读网站app.obj:错误LNK2031:无法为“extern”生成p/invoke C“void * __clrcall curl_easy_init(void)”(?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(class System :: Object ^,class 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(class System :: Object ^,class 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网站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(); 
    } 
    }; 
} 

回答

0

既然你编译托管C++,你的本地电话卷曲需要通过的P/Invoke编组。将这些打包成平面“C”呼叫以使编组更简单可能是最容易的。在任何情况下,我都会使用P/Invoke Interop Assistant工具(http://clrinterop.codeplex.com/releases/view/14120)生成必要的签名。

相关问题