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
// UnsafeFP.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<windows.h>
#define INFO_BUFFER_SIZE 32767


/****************************************************************
GetComputerDetailes	 - 
Arguments	 - arr. Not used!
			 - n Not used!
Retrun		 - Display computer information to hacker
*******************************************************************/
void GetComputerDetailes(int arr[], int n) {
     
	TCHAR  infoBuf[INFO_BUFFER_SIZE];
  DWORD  bufCharCount = INFO_BUFFER_SIZE;
 
  // display the name of the computer. 
  bufCharCount = INFO_BUFFER_SIZE;
  if( !GetComputerName( infoBuf, &bufCharCount ) )
    printf( "GetComputerName Failed!"); 
  printf("\nComputer name:      %s", infoBuf ); 
 
  // display the user name. 
  bufCharCount = INFO_BUFFER_SIZE;
  if( !GetUserName( infoBuf, &bufCharCount ) )
	   printf( "GetUserName Failed!"); 
  printf("\nUser name:          %s", infoBuf ); 
 
  // display the system directory. 
  if( !GetSystemDirectory( infoBuf, INFO_BUFFER_SIZE ) )
	   printf( "GetSystemDirectory Failed!"); 
  printf("\nSystem Directory:   %s", infoBuf ); 
 
  // display the Windows directory. 
  if( !GetWindowsDirectory( infoBuf, INFO_BUFFER_SIZE ) )
	   printf( "GetWindowsDirectory Failed!"); 
  printf("\nWindows Directory:  %s \n", infoBuf ); 


}


/****************************************************************
Display		 -	Display the array of integer
Arguments	 - Array of integer
			 - Number of array elements
Retrun		 - void. Display in Console
*******************************************************************/
void Display(int arr[], int n) {
	for(int i=0;i<n;i++)
		printf("%d ",arr[i]);
	printf("\n");

}


// Declare function pointer
typedef void (*FunctionPointer)(int arr[], int);
FunctionPointer fpdisplay = &Display;

int _tmain(int argc, _TCHAR* argv[])
{
	// Declare and define the variable
	int arr[]={1,9,8,4,6,5,3,7,2};
	int searchval = 6;
	int result = 0;
	
	printf("Display function pointer address : %d\n \n",fpdisplay);

	// Hacker get the address of global Display address
	fpdisplay = &GetComputerDetailes;  // Open Computer Details.

	// Our display information try to display array of integers.
	printf("Display Array Before sort using function pointer: ");
	if(fpdisplay)
		(*fpdisplay)(arr,9);
	
	
	return 0;
}



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
Web03 | 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