Sprawdzanie zewnętrznego adresu IP.
http://cyfbar.republika.pl/siec.html#siec8
dodałem do projektu wininet.lib
mimo wszytko pokazuje mi takie błądy:
[BCC32 Error] Unit2.cpp(16): E2034 Cannot convert 'wchar_t *' to 'const char *' |
Te blędy dodtycza tej linii:
KOD cpp: UKRYJ
hSession = InternetOpen(Application->Name.c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
Czy ja aby w dobry miejscu wstawiłem ten kod?
cały kod:
KOD cpp: UKRYJ
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include <wininet.h>
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
AnsiString GetExternalIP(void)
{
AnsiString ip = "";
AnsiString Url = "http://dynupdate.no-ip.com/ip.php";
DeleteUrlCacheEntry(Url.c_str());
HINTERNET hSession;
hSession = InternetOpen(Application->Name.c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
if(hSession)
{
HINTERNET hService;
hService = InternetOpenUrl(hSession, Url.c_str(), NULL, 0, 0, 0 );
if(hService)
{
while(1)
{
char lpBuffer[1024 + 1];
DWORD dwBytesRead;
InternetReadFile(hService, lpBuffer, 1024, &dwBytesRead);
if(dwBytesRead == 0) break;
lpBuffer[dwBytesRead] = 0;
ip += lpBuffer;
}
}
InternetCloseHandle(hService);
}
InternetCloseHandle(hSession);
return ip;
}
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Label1->Caption = "Zewnętrzny adres IP: " + GetExternalIP();
}
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit2.h"
#include <wininet.h>
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
AnsiString GetExternalIP(void)
{
AnsiString ip = "";
AnsiString Url = "http://dynupdate.no-ip.com/ip.php";
DeleteUrlCacheEntry(Url.c_str());
HINTERNET hSession;
hSession = InternetOpen(Application->Name.c_str(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0 );
if(hSession)
{
HINTERNET hService;
hService = InternetOpenUrl(hSession, Url.c_str(), NULL, 0, 0, 0 );
if(hService)
{
while(1)
{
char lpBuffer[1024 + 1];
DWORD dwBytesRead;
InternetReadFile(hService, lpBuffer, 1024, &dwBytesRead);
if(dwBytesRead == 0) break;
lpBuffer[dwBytesRead] = 0;
ip += lpBuffer;
}
}
InternetCloseHandle(hService);
}
InternetCloseHandle(hSession);
return ip;
}
TForm2 *Form2;
//---------------------------------------------------------------------------
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Button1Click(TObject *Sender)
{
Label1->Caption = "Zewnętrzny adres IP: " + GetExternalIP();
}
//---------------------------------------------------------------------------
Z góry dziekuje za pomoc
Pozdrawiam