Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Error on compile

Tags:

c++

linker

I am developing a firewall application which is complete for Windows XP.

To accomplish this, I am creating a dll file, which can be used in C# file.

For Vista or later, I used this code, but it's not compiling. I have win sdk 2008 and it is showing this error:

Error 19 error LNK2019: unresolved external symbol _FwpmEngineOpen0@20 referenced in function "private: unsigned long __thiscall PacketFilter::CreateDeleteInterface(bool)" (?CreateDeleteInterface@PacketFilter@@AAEK_N@Z) PacketFilter.obj FirewallVista ".

It must be some project property setting problem because I know all lib files are imported correctly.

like image 463
Barun Avatar asked Feb 26 '23 21:02

Barun


2 Answers

It seems like you're trying to compile the simple WFP project from codeproject. The guys above probably didn't understand the questions but the answer was:

  • find the first function linker fails at and find it on MSDN, eg. FwpmEngineOpen0 and find which library it needs to link to and add it to the project properties / Linker / Input / Additional Dependencies
  • Actually in the sample, there was another function failing to link UuidCreate

Long story short:

  1. Create a plain Win32 console application (I did it with VS2012) and build it - make sure it works
  2. Add the header file to the project (PacketFilter.h) to the project
  3. Replace the main source file with (PacketFilter.cpp) contents, but don't delete the include for "stdafx.h" on the top of the file
  4. Add the following libraries into the linker section (as per above)

Fwpuclnt.lib Rpcrt4.lib

Build and run the application (you might need to change the character set to multi-byte too).

You'll have to modify the IP address in the source to make the sample work. I picked a local IP address and did

ping -n 100 192.168.100.200

See the ping returning, start the exe, and see ping failing to reach destination (timing out) - eg. firewall is working. Then press any key to stop firewall and see ping reaching destination again.

I would've posted the link to the codeproject page, but as I have less than 10 credit - I can't :-P

Google for: "Firewall using Vista's Windows Filtering Platform APIs"

Hope this helps anyone who tries to build this sample.

like image 71
user8472 Avatar answered Mar 06 '23 19:03

user8472


You are missing a library reference. Check that you have imported the .lib that your code is expecting.

EDIT: The missing import is from the library you're talking about itself. That probably indicates you forgot to import the .lib of that actual library, or you need to attach the .cpp files from that project into your own project. In other words, you need more than the headers.

Also, if you're working from .NET, consider using the plain Vista Firewall API because it is already exposed as a COM coclass, which .NET can talk with natively.

like image 27
Billy ONeal Avatar answered Mar 06 '23 19:03

Billy ONeal