OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Apr 29, 2024 11:48 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ICMP winsock
PostPosted: Tue Feb 11, 2003 8:09 pm 
ive recently decided to learn more about sockets (more specifically non-blocking a.k.a. asynch) and came across the sourcecode for a program that simply pings. I downloaded the code, compiled it, and got this error
C:\Documents and Settings\drewski\Desktop\37tech\sockets\ping\ping.cpp(36) : error C2664: 'GetProcAddress' : cannot convert parameter 1 from 'void *' to 'struct HINSTANCE__ *'

(plus 2 more times) and each time it has to do with this function

pIcmpCreateFile=GetProcAddress(hIcmp,"IcmpCreateFile");

the block of code that seems to be troubling it is this

hIcmp = LoadLibrary( "ICMP.DLL" );
         
WSAStartup( 0x0002, &wsa );

phostent = gethostbyname( "www.microsoft.com");
dwIPAddr = (DWORD *)( *phostent->h_addr_list );
         
pIcmpCreateFile=GetProcAddress(hIcmp,"IcmpCreateFile");
pIcmpCloseHandle=GetProcAddress( hIcmp,"IcmpCloseHandle");
pIcmpSendEcho =GetProcAddress( hIcmp,"IcmpSendEcho" );

so each time i use hIcmp, it does not work. ICMP.dll is included in my project, as well as ICMP.dll. hIcmp is declared as a handle. any ideas why it isnt working?


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Tue Feb 11, 2003 8:09 pm 
i meant i have both ICMP.dll and ICMP.lib in my project, as well as all the winsock files i need.


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Tue Feb 11, 2003 8:14 pm 
you mean hIcmp is declared like this:

HANDLE hIcmp;

??

The first parameter to GetProcAddress is an HMODULE, which is probably interchangeable with the generic type HANDLE. Try a reinterpret_cast.

pIcmpCreateFile = GetProcAddress(reinterpret_cast<HMODULE>(hIcmp), "IcmpCreateFile");


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Tue Feb 11, 2003 8:16 pm 
in other words, it sounds like the problem is that the first parameter to GetProcAddress is not a void* and that hIcmp is declared as a void* (i.e., typedef void* HANDLE or something to that effect)...and in C++ a cast from a void pointer to another type of pointer requires an explicit cast.


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Tue Feb 11, 2003 8:34 pm 
'course if there's no reason why you need hIcmp to be a generic handle, then simply declare it as an HMODULE, then you don't need the cast.

Incidentally, I also found an article on MSDN that says you must cast a FARPROC function pointer to a more specific type of function pointer if the symbol STRICT is defined, otherwise the compiler will "warn you about an error in function parameter lists". GetProcAddress returns a FARPROC.


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Tue Feb 11, 2003 8:54 pm 
i have tried everything you guys said, and it still gives me many errors. i did pIcmpCreateFile = GetProcAddress(reinterpret_cast<HMODULE>(hIcmp), "IcmpCreateFile"); and i get ping.cpp(36) : error C2440: '=' : cannot convert from 'int (__stdcall *)(void)' to 'void *(__stdcall *)(void)', when I declare hIcmp as a MODULE i get ping.cpp(36) : error C2440: '=' : cannot convert from 'int (__stdcall *)(void)' to 'void *(__stdcall *)(void)', pretty much the same. so obviously i need to convert int(__stdcall*) to void*(stdcall). any ideas?


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Tue Feb 11, 2003 9:06 pm 
see my comments about the explicit cast of the FARPROC return value.

int (__stdcall*)(void) is a function pointer.

Same thing with void*(__stdcall*)(void)

what is the type of pIcmpCreateFile? try casting the return value of GetProcAddress to that type


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Sat Feb 15, 2003 2:19 pm 
The easy way of doing this is to get a recent version of the Platform SDK from Microsoft's site and #include <icmpapi.h>. Then you'll get all the Icmp functions defined without the need for LoadLibrary/GetProcAddress.

Otherwise: hIcmp should be of type HINSTANCE or HMODULE. They're not interchangable with HANDLE (HANDLE is a handle to a kernel object; HINSTANCE is a handle to a DLL or EXE). Then you'll need to declare all the Icmp functions as appropriate, e.g.:
Code:
typedef HANDLE (WINAPI *ICMPCREATEFILE)(void);
typedef DWORD (WINAPI *ICMPSENDECHO)(HANDLE, IPAddr, LPWORD, LPVOID, PIP_POPTION_INFORMATION, LPVOID, DWORD, DWORD);

ICMPCREATEFILE IcmpCreateFile;
ICMPSENDECHO IcmpSendEcho;
// ...
IcmpCreateFile = (ICMPCREATEFILE) GetProcAddress(hIcmp, "IcmpCreateFile");

etc.

But it would be easier to get a new copy of the Platform SDK. In fact, if you have icmp.lib, it seems likely that you have icmpapi.h.


Top
  
 
 Post subject: Re:ICMP winsock
PostPosted: Sun Feb 23, 2003 9:37 pm 
sorry it took so long for me to reply, but i did what u said, tom, and it works now. thanx a bunch for your help. :) i really apprectiate it, you too joel


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group