curl_easy_escape无法使用C ++ DLL

时间:2013-02-14 03:37:26

标签: visual-studio-2010 dll curl libcurl

我在使用C ++ DLL中的curl_easy_escape函数时遇到问题。如果我创建一个控制台应用程序,curl_easy_escape将按预期工作。

cURL curl-7.28.1-devel-mingw32
Visual Studio 2010

控制台应用程序(按预期工作)

int _tmain(int argc, _TCHAR* argv[])
{
    CURL *curl;
    char *data1;
    char *data2;
    int data2len;

    curl = curl_easy_init();
    if (curl)
    {
        data1 = curl_easy_escape(curl, "this is a string with spaces", 0);
        printf("\r\ndata1 = %s\r\n", data1);
        data2 = curl_easy_unescape(curl, data1, 0, &data2len);
        printf("\r\ndata2 = %s\r\n", data2);
        curl_easy_cleanup(curl);
    }
    printf(“\r\nPress any key to continue\r\n”);
    return 0;

输出

data1 = this%20is%20a%20string%20with%20spaces
data2 = this is a string with spaces
Press any key to continue

C ++ DLL

Visual C ++> Win32> Win32项目
应用程序类型= DLL(默认情况下所有其他选项)
链接器>输入>附加依赖项,添加了libcurl.lib

extern "C"
{
    __declspec(dllexport) int * curl_test(char *sBuf)
    {
        CURL *curl;
        curl = curl_easy_init();
        if (curl)
        {
            // The following line does not work
            //strcpy(sBuf, curl_easy_escape(curl, "this is a string with spaces", 0));

            // This line does work
            strcpy(sBuf, "this is a string with spaces");

            curl_easy_cleanup(curl);
        }
        return 0;

    }
}

dll用于C程序,并使用curl_test调用char ptr[256]curl_easy_escape到位后,LoadLibrary调用失败:

Error: C interpreter run time error: Error -- File error : LoadLibrary(mydll.dll) failed : The specified procedure could not be found.

请注意,这是LoadLibrary,因此尚未调用curl_test函数。

我想我可以找到一些URL编码/解码功能,但更喜欢使用cURL提供的功能。我对curl_easy_strerror函数也有同样的问题。

可能是'const char *'吗?

更新

理想情况下,我想使用curl_easy_escape/curl_easy_unescape,但作为一种解决方法,我决定在C中实现自己的URL编码/解码。我在http://www.geekhideout.com/urlcode.shtml找到了高效,编写良好的编码/解码功能

0 个答案:

没有答案