Click here to Skip to main content
15,915,508 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 8:09
Mike Borozdin27-Sep-07 8:09 
QuestionRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 8:14
David Crow27-Sep-07 8:14 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 8:43
Mike Borozdin27-Sep-07 8:43 
QuestionRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 8:46
David Crow27-Sep-07 8:46 
AnswerRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 9:10
Mike Borozdin27-Sep-07 9:10 
GeneralRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 9:16
David Crow27-Sep-07 9:16 
GeneralRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 9:30
Mike Borozdin27-Sep-07 9:30 
GeneralRe: CString to char* leads to an exception Pin
David Crow27-Sep-07 9:34
David Crow27-Sep-07 9:34 
Mike Borozdin wrote:
Yes, it's UNICODE.


That might explain why gethostbyname() does not work. It's Ansi only. Try this:

void CNetScanMfcDlg::OnBnClickedButton1()
{
    PortScanner portScanner(m_host, m_startPort, m_endPort);
}
 
PortScanner::PortScanner(LPCTSTR sHost, int startPort, int endPort)
{
    address.sin_family = AF_INET;
    USES_CONVERSION;
    hostent *host = gethostbyname(T2A(sHost));
    address.sin_addr.s_addr = (unsigned long) atoi(host->h_addr_list[0]); //this leads to an exception
    this->startPort = startPort;
    this->endPort = endPort;
}
Mike Borozdin wrote:
By the way, MessageBox((LPCTSTR) "Wrong host") shows rubbish...


Since you are using Unicode, try:

MessageBox(L"Wrong host");
Using the _T() macro is the preferred method, however.


"A good athlete is the result of a good and worthy opponent." - David Crow

"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne


GeneralRe: CString to char* leads to an exception Pin
Mark Salsbery27-Sep-07 8:38
Mark Salsbery27-Sep-07 8:38 
GeneralRe: CString to char* leads to an exception Pin
Mike Borozdin27-Sep-07 8:44
Mike Borozdin27-Sep-07 8:44 
QuestionDDE Question Pin
__DanC__27-Sep-07 6:18
__DanC__27-Sep-07 6:18 
Questionextend the "Save As..." dialog Pin
carabutnicolae123427-Sep-07 5:39
carabutnicolae123427-Sep-07 5:39 
AnswerRe: extend the "Save As..." dialog Pin
Nelek28-Sep-07 0:37
protectorNelek28-Sep-07 0:37 
GeneralRe: extend the "Save As..." dialog Pin
carabutnicolae123428-Sep-07 3:52
carabutnicolae123428-Sep-07 3:52 
GeneralRe: extend the "Save As..." dialog Pin
Nelek30-Sep-07 22:09
protectorNelek30-Sep-07 22:09 
QuestionNewbie question Pin
Nelek27-Sep-07 4:35
protectorNelek27-Sep-07 4:35 
AnswerRe: Newbie question Pin
toxcct27-Sep-07 4:47
toxcct27-Sep-07 4:47 
GeneralRe: Newbie question Pin
Nelek27-Sep-07 5:02
protectorNelek27-Sep-07 5:02 
AnswerRe: Newbie question Pin
Matthew Faithfull27-Sep-07 4:54
Matthew Faithfull27-Sep-07 4:54 
GeneralRe: Newbie question Pin
Nelek27-Sep-07 21:31
protectorNelek27-Sep-07 21:31 
Question"Default" class member Pin
DQNOK27-Sep-07 4:11
professionalDQNOK27-Sep-07 4:11 
AnswerRe: "Default" class member Pin
David Crow27-Sep-07 4:17
David Crow27-Sep-07 4:17 
AnswerRe: "Default" class member Pin
Matthew Faithfull27-Sep-07 4:18
Matthew Faithfull27-Sep-07 4:18 
GeneralRe: "Default" class member Pin
DQNOK27-Sep-07 4:24
professionalDQNOK27-Sep-07 4:24 
GeneralRe: "Default" class member Pin
DQNOK27-Sep-07 4:39
professionalDQNOK27-Sep-07 4:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.