4

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.

8
  • 1
    That is a linking error. Make sure you're linking the necessary libraries with the project. Commented Nov 8, 2010 at 4:54
  • As I told you I am using the code from code project. Commented Nov 8, 2010 at 4:55
  • And it showing all FwpmEngineOpen0 function info when I mouse over the function. This means linking is alright. But dont know why is not compiling. Commented Nov 8, 2010 at 4:56
  • 1
    Barun: The missing reference is from the codeproject code. You're not including some of the codeproject code that you need, or you need to import a library. Commented Nov 8, 2010 at 4:56
  • 2
    @Barun you have linker and compiler mixed up. Intellisense working means it's including the right header, which makes the compiler happy. But it's not finding the right lib, which results in your linker error. Since you want C# code, I suspect trying to make C++ code work will make you unhappy. Either use the Code Project discussion thread, or try a different wrapper library that will build for you. Commented Nov 8, 2010 at 5:06

3 Answers 3

6

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Wow, op should mark this as the answer. The solution is in step4.
according to MSDN FwpmEngineOpen0(...) is only Available starting with Windows Vista or Windows Server 2008, but the OP asks about Win-XP
2

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.

7 Comments

Dont know about it. Could you please provide me some C# codes.
@Barun: The bits you want are all located inside System.Runtime.InteropServices. Start here
Well I will see it. But I am sure that I am making small mistake in my present code. And I sure I will get over on that if you guyz give me a little hint on that.
It must be some project property setting problem.
@Barun: We are not psychic. The error message is the linker saying "I can't find that function/variable." Without seeing your exact machine we are not going to be able to figure out the issue, because the issue is not with your code, but rather with your compiler/project setup. The only hint anyone is going to be able to give you is "you need to configure your compiler/project so that the linker can find the function/variable it needs".
|
0

Right click on your project name in Solution explorer, select Properties. Then open Linker -> Input. Open the dropdown next to Additional Dependencies select <Edit>. Then type the following in the top textbox:

%(AdditionalDependencies) $(DDK_LIB_PATH)\NTOSKrnl.lib $(DDK_LIB_PATH)\FwpKClnt.lib $(DDK_LIB_PATH)\NetIO.lib $(DDK_LIB_PATH)\NDIS.lib $(DDK_LIB_PATH)\WDMSec.lib $(SDK_LIB_PATH)\UUID.lib 

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.