GUI (windowsform) using winPcap library and functions

Hello,

I have the following winPcap problem using windows forms in C++ with the winPcap functions (after pushing a button in the windowsform).

Introduction/background:
-------------------
I've build an extensive GUI application for working with some hardware which are connected and distributing messages and information by ethernet packages.

The GUI is build in Visual Studio 2010 (and also working with 2012) and using C++ and some C code. And should send or receive some specific message.

I thought to get this adressed I should use winPcap (and installed the full package and got an example working in a general console programm, so it's woking fine!)

When I open the GUI program (XXX.H) and assign some code to a specific button (in this case, just initialization or check how many devices are attached) I wanted to use the C code of the same example I got running in the console program.

HERES THE PROBLEM
-------------------

I can not define the library in the XXXX.H and when I iclude it in the main C++/C programfile I can not adress the libraries in the GUI.H file.

HOW DO I ADRESS the winPcap variables and functions in the XXX.H file?

As it's not a class I can not define namespace (it seems) or open the library in the XXX.h, so I wonder how I can access the library and it's functions and variables in the program.

Please help me, as I'm reallyt stuck!

Many many thanks in advance!!!

Tabe
Last edited on
XXX.H file?

I thought I use winpcap
Why?
mmmm OK sorry.
Last edited on
Stuff Below shows the result... I deleted some stuff
Last edited on
I can not define the library in the XXXX.H

Why not? How do you normally call functions from other source files? Just include the header...

********************************************
GUI.H
********************************************

#include "pcap.h"

pcap_if_t *alldevs;
pcap_if_t *d;
int i;
char errbuf[PCAP_ERRBUF_SIZE];


** Other code stuff from the form...**

THEN THE CODE for getting the devices:

if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
{
MessageBox::Show("Error", "GUI Initialization");
}

// Print the list //
for(d= alldevs; d != NULL; d= d->next)
{
// printf("%d. %s", ++i, d->name); //
if (d->description)
MessageBox::Show("IF", "GUI Initialization");
// printf(" (%s)\n", d->description);//
else
MessageBox::Show("ELSE", "GUI Initialization");
//printf(" (No description available)\n");//
}

/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);

NOTE:

1>
1> Invoking CVTRES.EXE:
1> /machine:x86
1> /verbose
1> /out:"C:\Users\-\AppData\Local\Temp\lnk3B8A.tmp"
1> /readonly
1> "Debug\app.res"
1> Microsoft (R) Windows Resource To Object Converter Version 10.00.40219.01
1> Copyright (C) Microsoft Corporation. All rights reserved.
1>
1> adding resource. type:ICON, name:1, language:0x0413, flags:0x1010, size:744
1> adding resource. type:ICON, name:2, language:0x0413, flags:0x1010, size:296
1> adding resource. type:GROUP_ICON, name:1, language:0x0413, flags:0x1030, size:34
Program in C++.obj : error LNK2031: unable to generate p/invoke for "extern "C" void __clrcall pcap_freealldevs(struct pcap_if *)" (?pcap_freealldevs@@$$J0YMXPAUpcap_if@@@Z); calling convention missing in metadata
Last edited on
Use /clr linker option, not /clr:pure and see what happens.
http://www.visualcplusdotnet.com/visualcplusdotnet7a.html
Hi all,

First of all: thanks to the replies, and with your help and some other friends I solved the problems.

For those who are working with Windows Forms AND the WinPcap library it's important to understand the following:

The WinPcap library can NOT be used easily as including some of the functions will not be compiled without warnings and errors and the code will not run. Main problem here is the usage of Managed Code VS Unmanaged code.

To still work with your code there are several solutions:

After correctly set all details in the LINKER and other settings for the WinPcap (find this at winPcap.org or check some video's or examples on this. This will solve the LNKerrors etc..

- Set the setting for the Common Language Runtime Support and change it from /clr:pure to /clr

-> Make sure that the library is included in your code file!!

- Use a wrapper around the code in a seperate file (or try using the sharpPcap library as this already wrapped, but I did not try to use this. Can also be used as an example for your own codewrap).

Cheers!
Topic archived. No new replies allowed.