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:
#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 )
{
CHAR buffer[2048] ;
CString m_strContents;
DWORD dwRead;
HINTERNET hiNet = InternetOpen(
L"InetURL/1.0",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL,
NULL,
0
);
if( !hiNet ) { return( -1010 ); }
HINTERNET hConnection = InternetConnect(
hiNet,
L"www.yoursite.com",
INTERNET_DEFAULT_HTTP_PORT,
NULL,
NULL,
INTERNET_SERVICE_HTTP,
0,
0
);
if( !hConnection )
{
InternetCloseHandle(hiNet);
return( -1020 );
}
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 ); }
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;
}
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.