//function pointers do function arguments#include <stdio.h>#include<stdlib.h>#include<string.h>#include<Windows.h>/*function pointers do 2 functions for function parameters:1. Defines a pointer type that allocates 4 bytes of memory space of 2. The parameter list for the calling function is specified, and the return value is called forward: calling the DLL file from the window's own system function library, getting the address of the function in the DLL file, executing the function reverse call: Call another function in another function through a function pointer*/voidMain () {//Forward Call//defines the handle----hinstance header file is Windows.hhinstance hinstance; //defining function pointer typestypedefint(*socketinittype) (void**/* out*/); typedefint(*socketsendtype) (void*, unsignedChar*,int ); typedefint(*socketrevtype) (void*, unsignedChar**,int*); typedefint(*socketdestory) (void**); intRET =0; void*handle=NULL; //ready to send a delivery paper Char*sendstr ="dddddd"; intBuflen1 = strlen (SENDSTR) +1; //Receiving Messages Char*revstr =NULL; intBuflen2 =0; //Serious note (for the first half-hour): When using the LoadLibrary macro definition, be sure to set the CharSet is not set, or the C language compiler does not recognize the file path//settings: Project Right--Properties--Configuration Properties--general--character set--not setHINSTANCE = LoadLibrary ("E:/l001.dll"); if(hinstance==NULL) {printf ("failed to get file address! \ n"); } //Get function AddressSocketinittype PF = (socketinittype) GetProcAddress (HINSTANCE,"Cltsocketinit"); if(pf==NULL) {printf ("failed to get function pointer! \ n"); return; } socketsendtype PF2= (Socketsendtype) GetProcAddress (HINSTANCE,"Cltsocketsend"); if(PF2 = =NULL) {printf ("failed to get function pointer! \ n"); return; } socketrevtype pf3= (Socketrevtype) GetProcAddress (HINSTANCE,"Cltsocketrev"); if(PF3 = =NULL) {printf ("failed to get function pointer! \ n"); return; } socketdestory pf4= (socketdestory) GetProcAddress (HINSTANCE,"cltsocketdestory"); if(Pf4 = =NULL) {printf ("failed to get function pointer! \ n"); return; } ret= PF (&handle); if(ret!=0) {printf ("Handle initialization failed! \ n"); GotoAAA; } ret= PF2 (handle, (unsignedChar*) Sendstr, buflen1); if(ret!=0) {printf ("message failed to send! \ n"); } ret= PF3 (handle, (unsignedChar* *) &REVSTR, &buflen2); if(ret!=0) {printf ("Message Acceptance failed! \ n"); } //Print the Received messageprintf (REVSTR); //Releasing message Memory Free(REVSTR); RET= Pf4 (&handle); if(Ret! =0) {printf ("release handle failed! \ n"); }aaa:system ("Pause");}
C language Function pointer two (forward call)