🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #1796

Re: console ping example

#1796
From: Michel Leunen
Date: Sun, 29 Oct 2006 10:25
53 lines
2657 bytes
DeKayA@bellsouth.net wrote:


> #include <windows.h>

#include <stdio.h> 	// for sprintf

>  HANDLE hIP;WSADATA wsa;HANDLE hIcmp;DWORD *dwIPAddr;struct hostent 
>     *phostent;

Replace the HANDLE hIcmp;
par :
HINSTANCE hIcmp;
LoadLibrary() returns a HINSTANCE not a HANDLE.


>  HANDLE ( WINAPI *pIcmpCreateFile )( VOID );
>  BOOL ( WINAPI *pIcmpCloseHandle )( HANDLE );
>  DWORD (WINAPI *pIcmpSendEcho)(HANDLE,DWORD,LPVOID,WORD,LPVOID,
>                                                  LPVOID,DWORD,DWORD);

Use typedefs when you have to deal with function pointers. It helps a lot:

typedef HANDLE ( WINAPI *ICMPCREATEFILE )( VOID );
typedef BOOL ( WINAPI *ICMPCLOSEHANDLE )( HANDLE );
typedef DWORD (WINAPI *ICMPSENDECHO)(HANDLE,DWORD,LPVOID,WORD,LPVOID,
                                        LPVOID,DWORD,DWORD);


> ->    pIcmpCreateFile=GetProcAddress( hIcmp,"IcmpCreateFile");
> ->    pIcmpCloseHandle=GetProcAddress( hIcmp,"IcmpCloseHandle");
> ->    pIcmpSendEcho =GetProcAddress( hIcmp,"IcmpSendEcho" );

You just need to cast the return value of GetProcAddress() to the 
correct function pointer. It's here your typedefs help you :

ICMPCREATEFILE pIcmpCreateFile=(ICMPCREATEFILE)GetProcAddress( 
hIcmp,"IcmpCreateFile");
        ICMPCLOSEHANDLE 
pIcmpCloseHandle=(ICMPCLOSEHANDLE)GetProcAddress( hIcmp,"IcmpCloseHandle");
        ICMPSENDECHO pIcmpSendEcho =(ICMPSENDECHO)GetProcAddress( 
hIcmp,"IcmpSendEcho" );


HTH
Michel
-- 
----------------------------------------
Michel Leunen
mailto: see my homepage.
C++Builder, BCC5.5.1 Web site:
http://www.leunen.com/
----------------------------------------
Technical Details
Message-ID: <4544818b$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <45440dc2.34466740@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,31ea45a742d03588
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
Date: Sun, 29 Oct 2006 11:25:20 +0100
From: Michel Leunen <nospam@noreply.be>
Organization: www.leunen.com
User-Agent: Thunderbird 1.5.0.7 (Windows/20060909)
MIME-Version: 1.0
Newsgroups: borland.public.cppbuilder.internet.socket
Subject: Re: console ping example
References: <45440dc2.34466740@forums.borland.com>
In-Reply-To: <45440dc2.34466740@forums.borland.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 81.247.90.89
Message-ID: <4544818b$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1162117515 81.247.90.89 (29 Oct 2006 02:25:15 -0700)
Lines: 53
Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail