| 作者 | 主题 |
|---|---|
|
沉默是金 游士 经验值:258 发帖数:155 精华帖:5 |
楼主
主题:枚举用户名的实现代码!简单介绍CALLBACK类函数的调用
点击此处查看附件 WINCC例子程序已上传! ////////////////////////////////////////////////////////////////////////////////// //在项目函数或标准函数中建立回调函数,在回调函数中编写实现具体功能的代码; //回调函数:MyPWGENEnumUsersCallBack ///////////////////////////////////////////////////////////////////////////////// #pragma code ("UseGen.DLL") #include "usegenap.h" #pragma code () BOOL MyPWGENEnumUsersCallBack ( LPWGEN_USERINFO lpUserInfo, PVOID lpUser) { static int n=0; if(n==GetTagSDWord("NewTag")) n=1; else n=n+1; switch(n) { case 9:SetTagChar("username10",lpUserInfo->login); break; case 8:SetTagChar("username9",lpUserInfo->login); break; case 7:SetTagChar("username8",lpUserInfo->login); break; case 6:SetTagChar("username7",lpUserInfo->login); break; case 5:SetTagChar("username6",lpUserInfo->login); break; case 4:SetTagChar("username5",lpUserInfo->login); break; case 3:SetTagChar("username4",lpUserInfo->login); break; case 2:SetTagChar("username3",lpUserInfo->login); break; case 1:SetTagChar("username2",lpUserInfo->login); SetTagChar("username1",lpUserInfo->login); } printf("UserIName:%s Group:%s AutomationLogout:%dM\r\n", lpUserInfo->login,lpUserInfo->group,lpUserInfo->expiration_time-1024); return TRUE; } /////////////////////////////////////////////////////////////////////////// //在项目函数或标准函数中建立调用回调函数的功能函数; //调用回调函数的功能函数: EnumUser /////////////////////////////////////////////////////////////////////////////// #pragma code ("UseGen.DLL") #include "usegenap.h" #pragma code () CMN_ERROR err; CMN_ERROR Error; LPCMN_ERROR error; DWORD countname; char usedata; char *DSNNAME = NULL; char project[_MAX_PATH + 1]; extern BOOL MyPWGENEnumUsersCallBack ( LPWGEN_USERINFO lpUserInfo ,PVOID lpUser);//回调函数声明 VOID EnumUser() { if(!DMGetRuntimeProject(project, sizeof(project), &Error)) { MessageBox(NULL,"DMGetRuntimeProject ERROR","ERROR",MB_OK); } else { DM_PROJECT_INFO ProjectInfomation; if (!DMGetProjectInformation(project, &ProjectInfomation, &Error)) { MessageBox(NULL,"DMGetProjectInformation ERROR","ERROR",MB_OK); } else { DSNNAME = SysMalloc(strlen(ProjectInfomation.szDSNName) + 1); if(DSNNAME ) { strcpy(DSNNAME, ProjectInfomation.szDSNName); strcat(DSNNAME, "R"); } else { MessageBox(NULL,"SysMalloc ERROR","ERROR",MB_OK); } } } if(PWGENConnect(DSNNAME,&err)) { PWGENEnumUsers (&countname,MyPWGENEnumUsersCallBack,&usedata,error); //调用回调函数MyPWGENEnumUsersCallBack SetTagSDWord("NewTag",countname); //Return-Type: BOOL printf("Count:%2d\r\n",countname); } else { printf("PWGENConnect Error :%d\r\n",err); } PWGENDisconnect(&err); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 注意事项 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// 1. 回调函数和调用回调函数的功能函数,不能够在同一模块内编写; 2. 编写调用回调函数的新函数时,在此新函数内必须对回调函数进行声明; 3. 在画面中属性或事件触发C动作中,调用回调函数可以不进行回调函数声明; 调试环境:WIN2000 SP4+WINCC6.0SP2
糊口饭吃
|