问题编译/链接WinINet示例 [英] Problem compiling/linking WinINet example

查看:73
本文介绍了问题编译/链接WinINet示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尊敬的先生们,

我正在使用以下代码制作DLL,但是遇到了一些我不知道如何解决的编译错误:

Dear Sirs,

I''m using the below code to make a DLL, but have encountered some compilation errors I don''t know how to fix:

//+------------------------------------------------------------------+
//| 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 ==========



如何解决这些错误?

谢谢.



How do I solve these errors?

Thanks.

推荐答案

错误消息中命名的函数期望使用非宽字符字符串,但是您要在宽字符字符串前添加前缀'' L''.

删除字符串文字之前的L,它应该进行编译.
The functions that are named in the error messages are expecting non wide-character strings, but you are specifying wide-character strings by prefixing them with ''L''.

Take away the L before your string literals, and it should compile.


您应该引用此lib:
Wininet.lib

有两种方法可以做到:

1.在项目属性的链接器"设置中添加此库
2.将以下内容添加到您的代码中:
You should reference this lib:
Wininet.lib

There are 2 ways to do this:

1. Add this lib in ''Linker'' settings in project properties
2. Add the following into your code:
#pragma comment(lib, "Wininet")


尊敬的先生,
感谢您的答复.
从我的代码中删除L后,它将进行编译.
之后,我尝试为此构建dll,并在尝试进行构建时遇到以下错误:

1> ------构建开始:项目:ExpertSample,配置:调试Win32 ------
1>正在链接...
1>创建库.\ Debug/ExpertSample.lib和对象.\ Debug/ExpertSample.exp
1> ExpertSample.obj:错误LNK2019:在函数"int __stdcall Sample(int)"中引用的未解析的外部符号__imp__InternetReadFile @ 16(?Sample @@ YGHH @ Z)
1> ExpertSample.obj:错误LNK2019:在函数"int __stdcall Sample(int)"中引用的未解析的外部符号__imp__HttpSendRequestA @ 20(?Sample @@ YGHH @ Z)
1> ExpertSample.obj:错误LNK2019:在函数"int __stdcall Sample(int)"中引用的未解析的外部符号__imp__HttpOpenRequestA @ 32(?Sample @@ YGHH @ Z)
1> ExpertSample.obj:错误LNK2019:在函数"int __stdcall Sample(int)"中引用的未解析的外部符号__imp__InternetCloseHandle @ 4(?Sample @@ YGHH @ Z)
1> ExpertSample.obj:错误LNK2019:在函数"int __stdcall Sample(int)"中引用的未解析的外部符号__imp__InternetConnectA @ 32(?Sample @@ YGHH @ Z)
1> ExpertSample.obj:错误LNK2019:在函数"int __stdcall Sample(int)"中引用的未解析的外部符号__imp__InternetOpenA @ 20(?Sample @@ YGHH @ Z)
1>.\ Debug/ExpertSample.dll:致命错误LNK1120:6个未解析的外部
1>构建日志保存在文件://c:\ Users \ Reza \ Desktop \ 555 \ 3 \ DLLSample \ Debug \ BuildLog.htm"中
1> ExpertSample-7个错误,0个警告
========== Build:0成功,1失败,0最新,跳过0 ==========


我必须为此添加任何链接器吗?
我该如何修改?

谢谢.
Dear Sir,
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?

Thanks.


这篇关于问题编译/链接WinINet示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆