Click here to Skip to main content
12,698,913 members (22,917 online)
Click here to Skip to main content


53 bookmarked

Secure Function Pointer and Callbacks in Windows Programming

, 4 May 2011 CPOL
This article explains the usage of function pointer and callback in Windows application programming Interface (API).
#include "StdAfx.h"
#include "Employee.h"

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

IMPEXP void BubbleSort(int arr[], int n) {
  bool swapped = true;
  int j = 0;
  int tmp;
  while (swapped) {
        swapped = false;
        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]);



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;
                 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++)
			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");


	printf("\nDisplay after BubbleSort...\n");


#ifdef __cplusplus

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.


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


About the Author

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 :
Web site:

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170118.1 | Last Updated 4 May 2011
Article Copyright 2011 by R.selvam
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid