Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version
Go to top

Secure Function Pointer and Callbacks in Windows Programming

, 4 May 2011
This article explains the usage of function pointer and callback in Windows application programming Interface (API).
Securefunctionpointer_CFunctionPointer.zip
CFunctionPointer
CFunctionPointer
CFunctionPointer.suo
Securefunctionpointer_CPPFunctionPointer.zip
CPPFunctionPointer
CPPFunctionPointer
CPPFunctionPointer.suo
Securefunctionpointer_SecureFP.zip
SecureFP
SecureFP
SecureFP.suo
Securefunctionpointer_UnsafeFP.zip
UnsafeFP
UnsafeFP
UnsafeFP.suo
Securefunctionpointer_Win32DLL.zip
Win32DLL
Win32DLL
Win32DLL.suo
Win32DLL.def
Securefunctionpointer_Win32DLLClient.zip
Win32DLLClient
Win32DLLClient
Win32DLLClient.suo
#include "StdAfx.h"
#include "Employee.h"

#ifdef __cplusplus    // If used by C++ code, 
extern "C" {          // we need to export the C interface
#endif
 

IMPEXP void BubbleSort(int arr[], int n) {
  bool swapped = true;
  int j = 0;
  int tmp;
  while (swapped) {
        swapped = false;
        j++;
        for (int i = 0; i < n - j; i++) {
             if (arr[i] > arr[i + 1]) {
                    tmp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = tmp;
                    swapped = true;
             }
        }
  }
}


IMPEXP void Display(int arr[], int n) {
	for(int i=0;i<n;i++)
		printf("%d ",arr[i]);

	printf("\n");

}


IMPEXP int BinarySearch(int arr[], int value, int left, int right) {
	printf("\nSearch using BinarySearch...\n");
      while (left <= right) {
            int middle = (left + right) / 2;
            if (arr[middle] == value)
                 return middle;
            else if (arr[middle] > value)
                  right = middle - 1;
            else
                 left = middle + 1;

      }
      return -1;
}


IMPEXP int LinearSearch(int arr[], int value, int left, int right) {
	printf("\nSearch using LinearSearch...\n");
	for(int i=left;i<right;i++)
	{
		if(arr[i]==value)
			return i;
	}
    return -1;
}

IMPEXP int arr[]={1,9,8,4,6,5,3,7,2};
IMPEXP int searchval = 6;
IMPEXP int nSize = 9;

static void (*FPBubbleSort)(int arr[], int) = &BubbleSort;
static void (*FPDisplay)(int arr[], int) = &Display;

 IMPEXP void InitBubbleSort( void )
{
	printf("\nDisplay before BubbleSort...\n");
	if(FPDisplay)
		(*FPDisplay)(arr,nSize);

	if(FPBubbleSort)
		(*FPBubbleSort)(arr,nSize);

	printf("\nDisplay after BubbleSort...\n");
	if(FPDisplay)
		(*FPDisplay)(arr,nSize);

}



 
 
#ifdef __cplusplus
}
#endif

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

Share

About the Author

R.selvam
Software Developer (Senior)
India India
Selvam has worked on several technologies like Core Java, VC++, MFC, Windows API and Weblogic server. He takes a lot of interest in reading technical articles and enjoy writing them too. He has been awarded as a Microsoft Community Star in 2004, MVP in 2005-06, SCJP 5.0 in 2009, Microsoft Community Contributor(MCC) 2011.
 
Github : https://github.com/selvamselvam
Web site: http://www15.brinkster.com/selvamselvam
Follow on   LinkedIn

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 4 May 2011
Article Copyright 2011 by R.selvam
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid