Click here to Skip to main content
15,888,065 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created an Apache module mod_Agent,There is an Registered and defined optional function in my module abc(); ,i want to retrieve that optional in my windows application, for that i included,"mod_Agent header" in my application, also in Properties, C/C++->General provided path of that module it compiled fine,but when i am trying retrieve the optional function it is giving me Compiler error: "Error 1 error LNK2019: unresolved external symbol _imp_apr_dynamic_fn_retrieve" for this i tried giving Linker->input "path of mod_Agent.lib",but still it is giving same error.

i think some other thing needs to be given in properties or else,kindly help me is resolving this.

This is my Application.c code

C++
#pragma comment(lib,"mod_AgentConfiguration.lib")
#include "AgentConfig.h"


 //Problem is in retrieving LoadAgentConfiguration

typedef int (__cdecl *MYPROC)(char *,Agent *); 
// Not able to refer to its definition i have linked Mod_AgentConfiguration as static library and also included its header..
static APR_OPTIONAL_FN_TYPE(LoadAgentConfiguration) *pfn;
 
int main( void ) 
{ 
    Agent *Agents; 
    int iReturnVal;
    HINSTANCE hinstLib; 
    MYPROC ProcAdd; 
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
    char *Filename = "D:\\Agentconfiguration.xml";
    Agents = (Agent *)malloc (sizeof(Agent));
	memset(	Agents, 0, sizeof(Agent));

// Here not able to retreive it as it is not loading defintion of LoadAgentConfiguration
//
    pfn = APR_RETRIEVE_OPTIONAL_FN(LoadAgentConfiguration);
    iReturnVal = pfn(Filename, Agents);

    // Get a handle to the DLL module.

    hinstLib = LoadLibrary(TEXT("Evtreader.dll")); 

    // If the handle is valid, try to get the function address.

    if (hinstLib != NULL) 
    { 
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "InitializeEventReader"); 

        // If the function address is valid, call the function.
        if (NULL != ProcAdd) 
        {
            fRunTimeLinkSuccess = TRUE;
            (ProcAdd) (Filename,Agents); 
        }
        // Free the DLL module.
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "CollectEvent"); 

        if (NULL != ProcAdd) 
        {
            fRunTimeLinkSuccess = TRUE;
        }
        fFreeResult = FreeLibrary(hinstLib); 
    }

    // If unable to call the DLL function, use an alternative.
    if (! fRunTimeLinkSuccess) 
        printf("Message printed from executable\n"); 

    return 0;

}


Mod_agent.h

C++
#pragma comment(lib,"mod_AgentConfiguration.lib")
#include "AgentConfig.h"


 
typedef int (__cdecl *MYPROC)(char *,Agent *); 
static APR_OPTIONAL_FN_TYPE(LoadAgentConfiguration) *pfn;
 
int main( void ) 
{ 
    Agent *Agents; 
    int iReturnVal;
    HINSTANCE hinstLib; 
    MYPROC ProcAdd; 
    BOOL fFreeResult, fRunTimeLinkSuccess = FALSE; 
    char *Filename = "D:\\Agentconfiguration.xml";
    Agents = (Agent *)malloc (sizeof(Agent));
	memset(	Agents, 0, sizeof(Agent));
    pfn = APR_RETRIEVE_OPTIONAL_FN(LoadAgentConfiguration);
    iReturnVal = pfn(Filename, Agents);

    // Get a handle to the DLL module.

    hinstLib = LoadLibrary(TEXT("Evtreader.dll")); 

    // If the handle is valid, try to get the function address.

    if (hinstLib != NULL) 
    { 
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "InitializeEventReader"); 

        // If the function address is valid, call the function.
        if (NULL != ProcAdd) 
        {
            fRunTimeLinkSuccess = TRUE;
            (ProcAdd) (Filename,Agents); 
        }
        // Free the DLL module.
        ProcAdd = (MYPROC) GetProcAddress(hinstLib, "CollectEvent"); 

        if (NULL != ProcAdd) 
        {
            fRunTimeLinkSuccess = TRUE;
        }
        fFreeResult = FreeLibrary(hinstLib); 
    }

    // If unable to call the DLL function, use an alternative.
    if (! fRunTimeLinkSuccess) 
        printf("Message printed from executable\n"); 

    return 0;

}

<pre lang="c++">/** @file AgentConfgreader.c
*  @brief Function Definitions for the module
*
*  This Module prints out the specified tag,sub tags,attributes of the tag and
*  their values
*
*  @date  26-08-2013
*
*  @version 1.0
*
*  @author Dhawal Arora Danekhail, Programmer
*
*/

/* 
Header File
*/
#include "AgentConfig.h"

//
// Global variables
//

Agent * AgentConfigObj;
char ParentName[100];
char CtConnectID[100];
Connector *CtConnector;
int CtReaderType;
int CtQueueType;
int CtCommChaType;


// 
// Function definition
//

void AgentConfigStore(const char *TagName, const char *TagValue)
{
	// Store the agent details ( Need to add switch and case of all compar
    if (!strcmp(TagName,"AgentDisplayName"))
        strcpy(AgentConfigObj->AgentDisplayName, TagValue);

	if (!strcmp(TagName,"AgentDescription"))
        strcpy(AgentConfigObj->AgentDescription,TagValue);

	if (!strcmp(TagName,"AgentVersion"))
        AgentConfigObj->AgentVersion = atoi(TagValue);

	if (!strcmp(TagName,"OSName"))
        strcpy(AgentConfigObj->OSName,TagValue);

	if (!strcmp(TagName,"OSVersion"))
        AgentConfigObj->OSVersion = atoi(TagValue);

    if (!strcmp(TagName,"AgentGroup"))
        strcpy(AgentConfigObj->AgentGroup,TagValue);

    if (!strcmp(TagName,"HardwareType"))
        strcpy(AgentConfigObj->HardwareType,TagValue);
}

// @Function 
// Copies the Connector attribute id value for every new Connector Node
// Allocates memory for Connector object for every new Connector Node

void InitializeConnector(apr_xml_attr* ConnAttr)
{
	// Create Connectors if the connector is not matching
	// with current connector ID

	char NewConnectorID[100] = {0};
	Connector *NewConnector = 0;

	while(1)
	{
		if(ConnAttr->next == NULL || !strcmp(ConnAttr->name, "id"))
		{
			strcpy(	NewConnectorID, ConnAttr->value);
			break;
		}
		ConnAttr = ConnAttr->next;
	}

	if(strcmp(NewConnectorID, CtConnectID) != 0)
	{
		// Store the current connector ID attribute

		strcpy(CtConnectID, NewConnectorID);

		// Create New connector

		NewConnector = (Connector *) malloc (sizeof(Connector));
		memset(	NewConnector, 0, sizeof(Connector));

		
		// Check for the first element or not 
		// If so assign the pointer inline with

		if(AgentConfigObj->Connectors == NULL)
        {
            NewConnector->Next = NULL;
            NewConnector->Prev = NULL;
            CtConnector = NewConnector;
            AgentConfigObj->Connectors = CtConnector;
        }
        else
        {
            CtConnector->Next = NewConnector;
            NewConnector->Prev = CtConnector;
            CtConnector = NewConnector;
        }
	}
}

// @Function 
// Iterates all the Tags in the xml file 
// Calls their Respective Parent tags function

void Agent_ReturnTag(apr_xml_elem *e)
{
    //
    // Declaration of local variables
    //
    apr_xml_elem *ec;

    if ( e->first_cdata.first && e->first_cdata.first->text )
    {
        apr_text  *next = e->first_cdata.first;
        apr_xml_attr *tagattr = e->attr;

        if (!strcmp(e->name, "Agent") || !strcmp(e->name, "Reader") || 
            !strcmp(e->name, "Queue") || !strcmp(e->name, "CommunicationChannel") ||
            !strcmp(e->name, "Filters"))
        {
            // Store the Parent Tag value

            strcpy(ParentName, e->name);

            // Reader, Queue and CommChe needs to allocate required memory based on 
            // Reader type

            if (!strcmp(e->name, "Reader"))
            {
                CtReaderType = GetReaderType(e);

                // Based on Reader type allocate memeory

                InitializeReader(CtConnector, CtReaderType);
            }
            if (!strcmp(e->name, "Queue"))
            {
                CtQueueType = GetQueueType(e);

                // Based on Queue type allocate memory

                InitializeQueue(CtConnector, CtQueueType);
            }

            if (!strcmp(e->name, "CommunicationChannel"))
            {
                CtCommChaType = GetCommChannelType(e);

                // Based on CommChannel type allocate memory

                InitializeCommChannnel(CtConnector, CtCommChaType);
            }
        }
        else if (!(strcmp(e->name,"connector")))
        {
            // Need create new connector object and intialize respective 
            // Reader, Queue and Comm Channel objects

            InitializeConnector(tagattr);
        }
        else
        {
            // Store the required values in respective structure

            if(!strcmp(ParentName, "Agent"))
                AgentConfigStore(e->name, next->text);

            if(!strcmp(ParentName, "Reader"))
            {
                switch (CtReaderType)
                {
                case TXTReaderType:
                    TXTReaderConfigStore(e->name, next->text, (TXTReader *)CtConnector->Reader);
                    break;

                case EVTReaderType:
                    EVTReaderConfigStore(e->name, next->text, (EVTReader *)CtConnector->Reader,tagattr);
                    break;

                }
            }

        }
        if (e->first_child) 
        {
            ec = e->first_child;
            while (ec) 
            {
                //
                // recursive call
                //

                Agent_ReturnTag(ec);
                ec = ec->next;
            }
        }
    }
}

// @Function 
// Opens and Parses the xml file
// Sends the xml document root to Agent_ReturnTag Function

void GetAgentConfig(apr_pool_t *pool, char *pFileName)
{
    //
    // Local Variables declaration
    //

    apr_status_t ret;
    apr_file_t * fd;
    apr_xml_parser * parser;
    apr_xml_doc * doc;
    apr_size_t size_read = 2000;

    //
    // Open file 
    //
    ret = apr_file_open(&fd, pFileName, APR_READ, APR_OS_DEFAULT, pool );

    //
    // Parse the Xml File
    //

    ret = apr_xml_parse_file( pool, &parser, &doc, fd, size_read );
    if ( ret != APR_SUCCESS )
    {
        char errbuf[1024] = {0};
        apr_xml_parser_geterror( parser, errbuf, sizeof(errbuf)); 
    }

    /* Close file */

    apr_file_close( fd );

    Agent_ReturnTag(doc->root);
}


// @Function
// Allocates the memory to Agent structure
// Allocates pool memory for opening the xml file
int LoadAgentConfiguration(char *pFileName, Agent *OutAgentConfigObj)
{
    //
    // Intialize the variable
    //
    apr_pool_t *pool;
    apr_status_t ret;
	AgentConfigObj = OutAgentConfigObj;
    ret = apr_initialize();
    if ( ret != APR_SUCCESS) 
        printf( "apr_initialize() failed (%d)\n", ret );

    //
    //  Create pool 
    //

    ret = apr_pool_create(&pool, NULL);
    if ( ret != APR_SUCCESS) 
        printf( "apr_pool_create() failed %d\n", ret );

    GetAgentConfig(pool, pFileName);
    apr_pool_destroy( pool );
	return APR_SUCCESS;
}

//
// This Function is the Entry Point
//

static void InitAgentConfig_Hooks(apr_pool_t *pool)
{
	//ap_hook_handler(Init_AgentConfReader, NULL, NULL, APR_HOOK_LAST);
    APR_REGISTER_OPTIONAL_FN(LoadAgentConfiguration);
}
 
module AP_MODULE_DECLARE_DATA AgentConfig_modules = {
	STANDARD20_MODULE_STUFF,
	NULL,
	NULL,
	NULL,
	NULL,
	NULL,
	InitAgentConfig_Hooks
} ;



//Reader.c

C#
/** @file ReaderConf.c
*  @brief Function Definitions for the module
*
*  This Module prints out the specified tag,sub tags,attributes of the tag and
*  their values
*
*  @date  26-08-2013
*
*  @version 1.0
*
*  @author Dhawal Arora Danekhail, Programmer
*
*/

/*
Header File
*/
#include "AgentConfig.h"

//
// Global variables
//

LogRegisteredEvents *EntryRegisteredEvent;
//
// Iterates the Reader Type
//

int GetReaderType(apr_xml_elem *e)
{
    apr_xml_elem *ec = e;
    int RType = RTUnKnown;

        apr_text  *next = ec->first_cdata.first;
        ec = e->first_child->first_child;

        while (ec)
        {
            apr_text  *next = ec->first_cdata.first;
            if(!strcmp(ec->name, "Type"))
            {
                if(!strcmp(next->text, "TxtReader"))
                    RType = TXTReaderType;

                    RType = XMLReaderType;
                else if(!strcmp(next->text, "EVTReader"))
                    RType = EVTReaderType;
            }
            ec=ec->next;
        }
    return RType;
}

//
// @ Function
// Assigns memory to void pointer on basis of Reader Type

void InitializeReader(Connector *Conn, int CtReaderType)
{
    switch (CtReaderType)
    {
    case TXTReaderType:
        Conn->Reader = (void *) malloc (sizeof(TXTReader));
        memset( Conn->Reader, 0, sizeof(TXTReader));
        break;


    case EVTReaderType:
        Conn->Reader = (void *) malloc (sizeof(EVTReader));
        memset( Conn->Reader, 0, sizeof(EVTReader));
        break;
    }
    Conn->ReaderType =CtReaderType;
}

//
// @Function
// Assigns the Reader sub-tags with their Respective Tag values

void TXTReaderConfigStore(const char *TagName, const char *TagValue, TXTReader *Reader)
{
    if (!strcmp(TagName,"Plug-in") || !strcmp(TagName,"GeneralConfiguration"))
        return;

    // Store the Reader details
    if (!strcmp(TagName,"Provider"))
        strcpy(Reader->Provider,TagValue);

    if (!strcmp(TagName,"Id"))
        Reader->Id = atoi(TagValue);;

    if (!strcmp(TagName,"Version"))
        strcpy(Reader->Version,TagValue);
        //Reader->Version = atoi(TagValue);

    if (!strcmp(TagName,"Type"))
        strcpy(Reader->Type,TagValue);

    if (!strcmp(TagName,"OS"))
        strcpy(Reader->OS,TagValue);

    if (!strcmp(TagName,"OSVersion"))
        strcpy(Reader->OSVersion,TagValue);

    if (!strcmp(TagName,"HardwareType"))
        strcpy(Reader->HardwareType,TagValue);

    if (!strcmp(TagName,"FileName"))
        strcpy(Reader->FileName,TagValue);

    if (!strcmp(TagName,"FileLocation"))
        strcpy(Reader->FileLocation,TagValue);

    if (!strcmp(TagName,"MaximumFileSize"))
        strcpy(Reader->MaximumFileSize,TagValue);

    if (!strcmp(TagName,"RegEx"))
        strcpy(Reader->RegEx,TagValue);

    if (!strcmp(TagName,"Delimiter"))
        strcpy(Reader->Delimiter,TagValue);

    if (!strcmp(TagName,"FileShareCredential"))
        strcpy(Reader->FileShareCredential,TagValue);

}


void EVTReaderConfigStore(const char *TagName, const char *TagValue, EVTReader *Reader,apr_xml_attr *Rdattr)
{
    if (!strcmp(TagName,"Plug-in") || !strcmp(TagName,"GeneralConfiguration"))
        return;

    // Store the Reader details
    if (!strcmp(TagName,"Provider"))
        strcpy(Reader->Provider,TagValue);

    if (!strcmp(TagName,"Id"))
        Reader->Id = atoi(TagValue);;

    if (!strcmp(TagName,"Version"))
        Reader->Version = atoi(TagValue);

    if (!strcmp(TagName,"Type"))
        strcpy(Reader->Type,TagValue);

    if (!strcmp(TagName,"OS"))
        strcpy(Reader->OS,TagValue);

    if (!strcmp(TagName,"OSVersion"))
        strcpy(Reader->OSVersion,TagValue);

    if (!strcmp(TagName,"LogRegisteredEvents"))
        {
        LogRegisteredEvents *LastRegisteredEvent = 0;
        LastRegisteredEvent = (LogRegisteredEvents *) malloc (sizeof(LogRegisteredEvents));

        if(Reader->LogRegisteredEvents == NULL)
        {
            LastRegisteredEvent->Next = NULL;
            EntryRegisteredEvent = LastRegisteredEvent;
            Reader->LogRegisteredEvents = EntryRegisteredEvent;
        }
        else
        {
            EntryRegisteredEvent->Next = LastRegisteredEvent;
            EntryRegisteredEvent = LastRegisteredEvent;
        }
        while(1)
        {
            if(Rdattr->next == NULL || !strcmp(Rdattr->name, "id"))
            {
                    EntryRegisteredEvent->id = atoi(Rdattr->value);
                    break;
            }
            Rdattr = Rdattr->next;
        }
        EntryRegisteredEvent->Logeventsregister = (char *) malloc (strlen(TagValue));
        strcpy(EntryRegisteredEvent->Logeventsregister,TagValue);
    }

    if (!strcmp(TagName,"CheckSum"))
        Reader->CheckSum = atoi(TagValue);

    if (!strcmp(TagName,"EventFailoverCheck"))
        Reader->EventFailoverCheck = atoi(TagValue);

    if (!strcmp(TagName,"Failoverfilepath"))
        strcpy(Reader->Failoverfilepath,TagValue);

    if (!strcmp(TagName,"Delimiter"))
        strcpy(Reader->Delimiter,TagValue);

    if (!strcmp(TagName,"SysLogHeader"))
       Reader->SysLogHeader = atoi(TagValue);
}


// Reader.h skipped
Posted
Updated 31-Oct-13 0:44am
v5
Comments
Richard MacCutchan 31-Oct-13 4:37am    
Are you sure that _imp_apr_dynamic_fn_retrieve is properly exported in the library?
Dhawal Arora 31-Oct-13 4:59am    
I solved the compiler error,actually i need to give project dependencies for that i didnt gave previously,"Now i am not able to get definition of optional function in my application first i am declaring pointer in my application : APR_OPTIONAL_FN_TYPE(abc) *pfn;

than retrieving it : pfn = APR_RETRIEVE_OPTIONAL_FN(abc);
pfn();

abc is returning NULL pointer as when right click on (abc) than it is unable to show its defintion,I have statically linked my mod_Agent.lib,but still not getting its definition.
kindly help
Richard MacCutchan 31-Oct-13 5:24am    
Please edit your question above (use the Improve question link) and show the definition for APR_RETRIEVE_OPTIONAL_FN and the relevant code that is in error.
Richard MacCutchan 31-Oct-13 6:19am    
Well you have dumped all your code but you really need to identify exactly where the problem occurs. Please try and help us to find the area that needs to be looked at.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900