locked
WFP & Windows Forms с++. Visual Studio 2010 RRS feed

  • Question

  • I add a a clean Windows Forms + + project with the following code:

     

    // Visual Interface Firewall.cpp : main project file.
    
    #include "stdafx.h"
    #include "Form1.h"
    
    #include <windows.h>
    #include <fwpmu.h>
    #include <stdio.h>
    
    #pragma comment(lib, "fwpuclnt.lib");
    
    
    #define SubLayer_name L"SubLayerName";
    
    // {2504835B-485B-442A-99E3-8DDB7AC1E617}
    const GUID subLayer_GUID = 
    { 0x2504835b, 0x485b, 0x442a, { 0x99, 0xe3, 0x8d, 0xdb, 0x7a, 0xc1, 0xe6, 0x17 } };
    
    
    void CreateFWL(){
    	HANDLE hEngine=NULL;
    
    	DWORD dwFwAPiRetCode = ERROR_BAD_COMMAND;
    
    	//Initialization Engine
    	try
    	{
    
    		dwFwAPiRetCode=FwpmEngineOpen0(NULL, RPC_C_AUTHN_WINNT,NULL,NULL,&hEngine);
    
    		
    	}
    	catch (...)
    	{
    		//обработчик
    	}
    
    	//структура SubLayer
    	FWPM_SUBLAYER0 SubLayer;
    
    	SubLayer.subLayerKey=subLayer_GUID;
    	SubLayer.displayData.name=SubLayer_name;
    	SubLayer.displayData.description=SubLayer_name;
    	SubLayer.flags=FWPM_SUBLAYER_FLAG_PERSISTENT;
    	SubLayer.weight=0x01;
    
    	//add Sublayer'a
    
    	dwFwAPiRetCode=FwpmSubLayerAdd0(hEngine,&SubLayer,NULL);
    	
    	
    	
    	//create Filter
    	FWPM_FILTER0 Filter;
    	FWPM_FILTER_CONDITION0 Condition[3];
    
    	memset(&Filter,0,sizeof(Filter));
    
    	Filter.action.type = FWP_ACTION_BLOCK;
    	Filter.subLayerKey = subLayer_GUID;
    	Filter.displayData.name = L"Test Sublayer";
    	Filter.weight.type = FWP_EMPTY;
    	Filter.layerKey= ::FWPM_LAYER_ALE_AUTH_CONNECT_V4;//FWPM_LAYER_INBOUND_TRANSPORT_V4 
    	Filter.numFilterConditions=3; 
    	Filter.filterCondition=Condition;
    
    	FWP_V4_ADDR_AND_MASK AddrMask;
    	AddrMask.addr=C0A80201;<br/>	AddrMask.mask=0xffffffff;
    
    
    	Condition[0].fieldKey=FWPM_CONDITION_IP_REMOTE_ADDRESS;
    
    	Condition[0].matchType=FWP_MATCH_EQUAL;
    	Condition[0].conditionValue.type=FWP_V4_ADDR_MASK;
    	Condition[0].conditionValue.v4AddrMask=&AddrMask;
    
    	
    	UINT16 port_block;
    	port_block = 80;
    
    	Condition[1].fieldKey=FWPM_CONDITION_IP_REMOTE_PORT;
    
    	Condition[1].matchType=FWP_MATCH_EQUAL;
    	Condition[1].conditionValue.type=FWP_UINT16;
    	Condition[1].conditionValue.uint16=port_block;
    
    
    	FWP_BYTE_BLOB *applicationID=NULL;
    	dwFwAPiRetCode=FwpmGetAppIdFromFileName0(L"C:\\Program Files\\Mozilla Firefox\\firefox.exe",&applicationID);
    
    
    	Condition[2].fieldKey=FWPM_CONDITION_ALE_APP_ID;
    
    	Condition[2].matchType=FWP_MATCH_EQUAL;
    	Condition[2].conditionValue.type=FWP_BYTE_BLOB_TYPE;
    	Condition[2].conditionValue.byteBlob=applicationID;
    
    	UINT64 filterId;
    	
    	dwFwAPiRetCode = FwpmFilterAdd0(hEngine,&Filter,NULL,&filterId);
    	
    
    	FwpmFilterDeleteById0(hEngine,filterId);
    
    
    	FwpmSubLayerDeleteByKey0(hEngine,&subLayer_GUID);
    
    
    	FwpmEngineClose0(hEngine);
    }
    
    
    
    using namespace VisualInterfaceFirewall;
    
    [STAThreadAttribute]
    int main(array<System::String ^> ^args)
    {
    	// Enabling Windows XP visual effects before any controls are created
    	Application::EnableVisualStyles();
    	Application::SetCompatibleTextRenderingDefault(false); 
    
    	// Create the main window and run it
    	Application::Run(gcnew Form1());
    	return 0;
    }
    

    and the compiler generates an error:

    Error 9 error LNK1120: 8 unresolved externals

    Error 5 error LNK2001: unresolved external symbol FWPM_CONDITION_ALE_APP_ID

    Error 7 error LNK2001: unresolved external symbol FWPM_CONDITION_IP_REMOTE_ADDRESS

    Error 6 error LNK2001: unresolved external symbol FWPM_CONDITION_IP_REMOTE_PORT

    Error 8 error LNK2001: unresolved external symbol FWPM_LAYER_ALE_AUTH_CONNECT_V4

    Error 1 error LNK2020: unresolved token (0A00001C) FWPM_CONDITION_IP_REMOTE_PORT

    Error 2 error LNK2020: unresolved token (0A00001D) FWPM_CONDITION_ALE_APP_ID

    Error 3 error LNK2020: unresolved token (0A000023) FWPM_LAYER_ALE_AUTH_CONNECT_V4

    Error 4 error LNK2020: unresolved token (0A00002C) FWPM_CONDITION_IP_REMOTE_ADDRESS

    Please, help me

    Thursday, May 19, 2011 11:41 AM