I am developing a firew开发者_C百科all 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.
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:
- Create a plain Win32 console application (I did it with VS2012) and build it - make sure it works
- Add the header file to the project (PacketFilter.h) to the project
- Replace the main source file with (PacketFilter.cpp) contents, but don't delete the include for "stdafx.h" on the top of the file
- 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.
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.
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
精彩评论