www.digitalmars.com         C & C++   DMDScript  

c++ - writing c code in a c++ app

reply david <david_member pathlink.com> writes:
Hello,

I am having difficulties in writing a c++ prog that uses C code to send an icmp
packet (icmpapi.h, ipexport.h (used by icmpapi.h)).  This is what my code looks
like so far:



-------------------------------------
#include <iostream>
#include <windows.h>

extern "C" {
#include <icmpapi.h>
}

int main(){
using namespace std;
HANDLE icmp;
icmp = IcmpCreateFile();

cout << "hello";
return 0;
}
________________________________________________


It compiles but then i get an error that says:

_______________________________________________
hello.obj(hello)
Error 42: Symbol Undefined _IcmpCreateFile 0

--- errorlevel 1
_______________________________________________




Before i added the:
extern "C" 

I would get the error:

_____________________________________________________________________
hello.obj(hello)
Error 42: Symbol Undefined ?IcmpCreateFile  YGPAXXZ (void *stdcall
IcmpCreateFile (void ))

--- errorlevel 1
_____________________________________________________________________


Any insight would be greatly appreciated.  Is there a way to send a custom icmp
packet using C++ libraries?  This might help some.  The code for sending the
exact packet I need to send is already written in C for me, so ideally I would
like to write a C++ prog that does some extra work but also sends the icmp
packet (exactly as written in the already existing C code that I have).


Thank you,

David S
Feb 10 2005
parent reply Jan Knepper <jan smartsoft.us> writes:
You've got to include the library in the link that contains 
IcmpCreateFile ().

Jan



david wrote:
 Hello,
 
 I am having difficulties in writing a c++ prog that uses C code to send an icmp
 packet (icmpapi.h, ipexport.h (used by icmpapi.h)).  This is what my code looks
 like so far:
 
 
 
 -------------------------------------
 #include <iostream>
 #include <windows.h>
 
 extern "C" {
 #include <icmpapi.h>
 }
 
 int main(){
 using namespace std;
 HANDLE icmp;
 icmp = IcmpCreateFile();
 
 cout << "hello";
 return 0;
 }
 ________________________________________________
 
 
 It compiles but then i get an error that says:
 
 _______________________________________________
 hello.obj(hello)
 Error 42: Symbol Undefined _IcmpCreateFile 0
 
 --- errorlevel 1
 _______________________________________________
 
 
 
 
 Before i added the:
 extern "C" 
 
 I would get the error:
 
 _____________________________________________________________________
 hello.obj(hello)
 Error 42: Symbol Undefined ?IcmpCreateFile  YGPAXXZ (void *stdcall
 IcmpCreateFile (void ))
 
 --- errorlevel 1
 _____________________________________________________________________
 
 
 Any insight would be greatly appreciated.  Is there a way to send a custom icmp
 packet using C++ libraries?  This might help some.  The code for sending the
 exact packet I need to send is already written in C for me, so ideally I would
 like to write a C++ prog that does some extra work but also sends the icmp
 packet (exactly as written in the already existing C code that I have).
 
 
 Thank you,
 
 David S
 
 

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org
Feb 10 2005
parent reply david <david_member pathlink.com> writes:
The file that contains IcmpCreateFile () is icmpapi.h and i've included that
file in my prog.  Is this what you mean by including the library in the link
that contains IcmpCreateFile ()?


In article <cugg6l$2tn3$1 digitaldaemon.com>, Jan Knepper says...
You've got to include the library in the link that contains 
IcmpCreateFile ().

Jan



david wrote:
 Hello,
 
 I am having difficulties in writing a c++ prog that uses C code to send an icmp
 packet (icmpapi.h, ipexport.h (used by icmpapi.h)).  This is what my code looks
 like so far:
 
 
 
 -------------------------------------
 #include <iostream>
 #include <windows.h>
 
 extern "C" {
 #include <icmpapi.h>
 }
 
 int main(){
 using namespace std;
 HANDLE icmp;
 icmp = IcmpCreateFile();
 
 cout << "hello";
 return 0;
 }
 ________________________________________________
 
 
 It compiles but then i get an error that says:
 
 _______________________________________________
 hello.obj(hello)
 Error 42: Symbol Undefined _IcmpCreateFile 0
 
 --- errorlevel 1
 _______________________________________________
 
 
 
 
 Before i added the:
 extern "C" 
 
 I would get the error:
 
 _____________________________________________________________________
 hello.obj(hello)
 Error 42: Symbol Undefined ?IcmpCreateFile  YGPAXXZ (void *stdcall
 IcmpCreateFile (void ))
 
 --- errorlevel 1
 _____________________________________________________________________
 
 
 Any insight would be greatly appreciated.  Is there a way to send a custom icmp
 packet using C++ libraries?  This might help some.  The code for sending the
 exact packet I need to send is already written in C for me, so ideally I would
 like to write a C++ prog that does some extra work but also sends the icmp
 packet (exactly as written in the already existing C code that I have).
 
 
 Thank you,
 
 David S
 
 

-- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org

Feb 10 2005
parent "Walter" <newshound digitalmars.com> writes:
"david" <david_member pathlink.com> wrote in message
news:cugnfk$3ul$1 digitaldaemon.com...
 The file that contains IcmpCreateFile () is icmpapi.h and i've included

 file in my prog.  Is this what you mean by including the library in the

 that contains IcmpCreateFile ()?

No, icmpapi.h is likely just a list of declarations. In the library would be the code to implement it. It'll have a .lib extension. Look in the comments in your header file, maybe it says where the corresponding library file is. icmpapi.h is not one of the files that comes with DMC++, nor is its corresponding library file.
Feb 10 2005