CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10
  1. #1
    Join Date
    May 2010
    Posts
    38

    Hoe Solve these errors?

    Dear Sirs,
    I trying using below code for making dll and meet these errors:

    //+------------------------------------------------------------------+
    //| Sample DLL for MQL4 |
    //| Copyright © 2004-2006, MetaQuotes Software Corp. |
    //| http://www.metaquotes.net |
    //+------------------------------------------------------------------+
    #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <wininet.h>
    #include <atlstr.h>
    #include <string>

    //----
    #define MT4_EXPFUNC __declspec(dllexport)
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+

    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+

    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+
    MT4_EXPFUNC int __stdcall Sample( int Whatever )
    {
    //---- Declare Return Value
    CHAR buffer[2048] ;
    CString m_strContents;
    DWORD dwRead;

    /* Connect to the internet */
    HINTERNET hiNet = InternetOpen(
    L"InetURL/1.0",
    INTERNET_OPEN_TYPE_PRECONFIG,
    NULL,
    NULL,
    0
    );
    /* if connection fails throw error */
    if( !hiNet ) { return( -1010 ); }

    /* Connect to a site */
    HINTERNET hConnection = InternetConnect(
    hiNet,
    L"www.yoursite.com",
    INTERNET_DEFAULT_HTTP_PORT,
    NULL,
    NULL,
    INTERNET_SERVICE_HTTP,
    0,
    0
    );
    /* if connetion to site failed */
    if( !hConnection )
    {
    InternetCloseHandle(hiNet);
    return( -1020 );
    } // COULD NOT CONNECT TO WEBSITE

    /* Get Data */
    HINTERNET hData = HttpOpenRequest( hConnection, L"GET", L"/yourpage.php", NULL, NULL, NULL, INTERNET_FLAG_KEEP_CONNECTION, 0 );
    if ( !hData )
    {
    InternetCloseHandle(hConnection);
    InternetCloseHandle(hiNet);
    return( -1030 ); // PAGE NOT FOUND
    }

    HttpSendRequest( hData, NULL, 0, NULL, 0);
    bool Done = false;
    while( !Done )
    {
    InternetReadFile( hData, buffer, 255, &dwRead );
    if ( dwRead == 0 ) { Done = true; }
    buffer[dwRead] = 0;
    m_strContents += buffer;
    }

    //---- Here you can output m_strContents
    MessageBox( 0, m_strContents, L"WebPage OutPut", 0 );

    InternetCloseHandle(hConnection);
    InternetCloseHandle(hiNet);
    InternetCloseHandle(hData);
    }
    //+------------------------------------------------------------------+
    //| |
    //+------------------------------------------------------------------+


    errors are as below:

    1>------ Build started: Project: ExpertSample, Configuration: Debug Win32 ------
    1>Compiling...
    1>ExpertSample.cpp
    1>c:\users\reza\desktop\555\3\dllsample\expertsample.cpp(41) : error C2664: 'InternetOpenA' : cannot convert parameter 1 from 'const wchar_t [12]' to 'LPCSTR'
    1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    1>c:\users\reza\desktop\555\3\dllsample\expertsample.cpp(55) : error C2664: 'InternetConnectA' : cannot convert parameter 2 from 'const wchar_t [17]' to 'LPCSTR'
    1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    1>c:\users\reza\desktop\555\3\dllsample\expertsample.cpp(64) : error C2664: 'HttpOpenRequestA' : cannot convert parameter 2 from 'const wchar_t [4]' to 'LPCSTR'
    1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    1>c:\users\reza\desktop\555\3\dllsample\expertsample.cpp(83) : error C2664: 'MessageBoxA' : cannot convert parameter 3 from 'const wchar_t [15]' to 'LPCSTR'
    1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
    1>Build log was saved at "file://C:\Users\Reza\Desktop\555\3\DLLSample\Debug\BuildLog.htm"
    1>ExpertSample - 4 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    Hoe solve these errors,
    Thanks.

  2. #2
    Join Date
    Feb 2010
    Posts
    30

    Re: Hoe Solve these errors?

    the first argument of InternetOpen() is an address/pointer to the string, not a string

  3. #3
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Hoe Solve these errors?

    Check your compilation settings, your are supposed to compile it in Unicode or ANSI mode.
    Check this.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  4. #4
    Join Date
    May 2010
    Posts
    38

    Re: Hoe Solve these errors?

    Dear sirs,
    Thank you for your reply.

    After delete "L" from my code it compiled.
    After that I tried build dll for that and when tried build that I met below errors:

    1>------ Build started: Project: ExpertSample, Configuration: Debug Win32 ------
    1>Linking...
    1> Creating library .\Debug/ExpertSample.lib and object .\Debug/ExpertSample.exp
    1>ExpertSample.obj : error LNK2019: unresolved external symbol __imp__InternetReadFile@16 referenced in function "int __stdcall Sample(int)" (?Sample@@YGHH@Z)
    1>ExpertSample.obj : error LNK2019: unresolved external symbol __imp__HttpSendRequestA@20 referenced in function "int __stdcall Sample(int)" (?Sample@@YGHH@Z)
    1>ExpertSample.obj : error LNK2019: unresolved external symbol __imp__HttpOpenRequestA@32 referenced in function "int __stdcall Sample(int)" (?Sample@@YGHH@Z)
    1>ExpertSample.obj : error LNK2019: unresolved external symbol __imp__InternetCloseHandle@4 referenced in function "int __stdcall Sample(int)" (?Sample@@YGHH@Z)
    1>ExpertSample.obj : error LNK2019: unresolved external symbol __imp__InternetConnectA@32 referenced in function "int __stdcall Sample(int)" (?Sample@@YGHH@Z)
    1>ExpertSample.obj : error LNK2019: unresolved external symbol __imp__InternetOpenA@20 referenced in function "int __stdcall Sample(int)" (?Sample@@YGHH@Z)
    1>.\Debug/ExpertSample.dll : fatal error LNK1120: 6 unresolved externals
    1>Build log was saved at "file://c:\Users\Reza\Desktop\555\3\DLLSample\Debug\BuildLog.htm"
    1>ExpertSample - 7 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


    I must add any linker to this?
    How I can modify this?

    Best Regards,

  5. #5
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Hoe Solve these errors?

    Link your project with Wininet.lib

    To do that, go to project settings, Linker, Input and put this library.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  6. #6
    Join Date
    May 2010
    Posts
    38

    Re: Hoe Solve these errors?

    dear Sirs,
    Thank you for your reply.
    Now it works.
    Another question:
    How I return "WebPage OutPut" in MessageBox or read that?
    I mean how I can use that for example for printing or use in other section my program?

    Thanks.

  7. #7
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Hoe Solve these errors?

    I would suggest you to refrain from Internet programming, or anything extra-ordinary stuff. Learn basics of program compilation, linking, debugging, general problem solving. Develop normal console or GUI program for common needs.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  8. #8
    Join Date
    May 2010
    Posts
    38

    Re: Hoe Solve these errors?

    Quote Originally Posted by Ajay Vijay View Post
    I would suggest you to refrain from Internet programming, or anything extra-ordinary stuff. Learn basics of program compilation, linking, debugging, general problem solving. Develop normal console or GUI program for common needs.
    Dear Ajay,
    thank you for your advise.
    I am really beginner in this field and need this application for other my software.
    This is my last problem for this work.
    If possible help me I can solve this item.

    Thanks.

  9. #9
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Hoe Solve these errors?

    You can use the data represented by InternetReadFile and display it.

    But what you should display? The retrieved content may just be HTML or some other gibberish that user won't understand. Would you write HTML parsing logic?
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  10. #10
    Join Date
    May 2010
    Posts
    38

    Re: Hoe Solve these errors?

    Quote Originally Posted by Ajay Vijay View Post
    You can use the data represented by InternetReadFile and display it.

    But what you should display? The retrieved content may just be HTML or some other gibberish that user won't understand. Would you write HTML parsing logic?
    Dear Ajay,
    Thank you for your helping.
    I want read only one number from my webpage.
    My webpage address is: http://www.silverea.com/print.php
    I want read this number and use that as int or double number.
    I want use than this number for compare two number in my program.
    Thank you for your helping again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured