基本上都是参照MSDN的代码写的,成功进入了桌面,但是桌面上只显示图标,字体什么的都不显示,应用程序也无法启动,这是什么原因呢? 
我修改了WlxInitialize,WlxActivateUserShell,WlxDisplaySASNotice,WlxLoggedOutSAS 
出现这种情况实在很费劲,烦请高手看看,谢谢:) 代码如下: 
BOOL WINAPI WlxInitialize(LPWSTR    lpWinsta, 
  HANDLE    hWlx, 
  PVOID     pvReserved, 
  PVOID     pWinlogonFunctions, 
  PVOID    *pWlxContext 
  ) 

g_pWinlogon = (PWLX_DISPATCH_VERSION_1_3) pWinlogonFunctions;  
    // Alloc and initialize the context  
    pgContext = (PGINA_CONTEXT) LocalAlloc(LMEM_FIXED  ¦ LMEM_ZEROINIT, sizeof(GINA_CONTEXT));  
    if (!pgContext) {  
            return FALSE;  
    }  
    *pWlxContext = (PVOID) pgContext;  
    pgContext->hDllInstance = hDllInstance;  
    pgContext->pWlxFuncs = (PWLX_DISPATCH_VERSION_1_3) pWinlogonFunctions;  
    pgContext->hWlx = hWlx;  
    pgContext->station = lpWinsta;  
    pgContext->pWlxFuncs->WlxUseCtrlAltDel(hWlx);  
    pgContext->pWlxFuncs->WlxMessageBox(hWlx, NULL, L"WlxInitialize finished successfully", L"WlxInitialize", MB_OK);  
return TRUE;  

BOOL WINAPI WlxActivateUserShell(PVOID pWlxContext, 
 PWSTR pszDesktopName, 
 PWSTR pszMprLogonScript, 
 PVOID pEnvironment) 

PGINA_CONTEXT pgContext = (PGINA_CONTEXT) pWlxContext;  
    STARTUPINFO si;  
    PROCESS_INFORMATION pi;  
    BOOL bRet;  
    WCHAR szText[MAX_PATH];  
    PWSTR pszScan;  
pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx, NULL, L"Starting Shell", L"WlxActivateUserShell", MB_OK);  
    GetProfileString(WINLOGON_APP, USERINIT, USERINIT_DEFAULT, szText, MAX_PATH);  
    pszScan = wcstok(szText, TEXT(","));  
    si.cb = sizeof(STARTUPINFO);  
    si.lpReserved = NULL;  
    si.lpTitle = L"userinit";  
    si.dwX = si.dwY = si.dwXSize = si.dwYSize = 0L;  
    si.dwFlags = 0;  
    si.wShowWindow = SW_SHOW;  
    si.lpReserved2 = NULL;  
    si.cbReserved2 = 0;  
    si.lpDesktop = pszDesktopName;  
    bRet = CreateProcessAsUser(pgContext->UserToken, pszScan, NULL, NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT, pEnvironment, NULL, &si, &pi);  
    if (bRet == FALSE) {  
        pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx, NULL, L"Failure!", L"CreateProcessAsUser", MB_ICONERROR  ¦ MB_OK);  
    }  
    else {  
        pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx, NULL, L"Success?", L"CreateProcessAsUser", MB_ICONINFORMATION  ¦ MB_OK);  
    }  
    VirtualFree(pEnvironment, 0, MEM_RELEASE);  
    return(bRet);  
//return theApp.MyWlxActivateUserShell(pWlxContext,pszDesktopName,pszMprLogonScript,pEnvironment); 

VOID WINAPI WlxDisplaySASNotice(PVOID pWlxContext) 

    int ret;  
    PGINA_CONTEXT pgContext;  
    pgContext = (PGINA_CONTEXT) pWlxContext;  
    ret = pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx, NULL, L"CTRL+ALT+DEL to Logon", L"WlxDisplaySASNotice Message", MB_OK );      // Send CTRL+ALT+DEL SAS to winlogon when the user clicks the OK  
    if (ret == IDOK) {  
        pgContext->pWlxFuncs->WlxSasNotify(pgContext->hWlx, WLX_SAS_TYPE_CTRL_ALT_DEL);  
    }  //theApp.MyWlxDisplaySASNotice(pWlxContext); 
} // 在没有任何一个用户登陆的情况下,Winlogon.exe接收到SAS事件调用该函数 
int WINAPI WlxLoggedOutSAS(PVOID                pWlxContext, 
   DWORD                dwSasType, 
   PLUID                pAuthenticationId, 
   PSID                 pLogonSid, 
   PDWORD               pdwOptions, 
   PHANDLE              phToken, 
   PWLX_MPR_NOTIFY_INFO pMprNotifyInfo, 
   PVOID *              pProfile) 
{     
//return theApp.MyWlxLoggedOutSAS(pWlxContext,dwSasType,pAuthenticationId,pLogonSid,pdwOptions,phToken,pMprNotifyInfo,pProfile); 
PGINA_CONTEXT pGlobal_Context = (PGINA_CONTEXT) pWlxContext;  
TOKEN_STATISTICS userStats;  
DWORD cbStats;  
    pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx, NULL, L"Starting authentication", L"WlxLoggedOutSAS", MB_OK);  
if (!phToken) return WLX_SAS_ACTION_NONE;  
if(!LogonUser(TEXT("username"),TEXT(""),TEXT("password"), LOGON32_LOGON_UNLOCK, LOGON32_PROVIDER_DEFAULT,phToken)) 

AfxMessageBox(_T("密码或者用户名错误!不能登陆!")); 
return WLX_SAS_ACTION_NONE; 

if (!(*phToken)) return WLX_SAS_ACTION_NONE; 
pGlobal_Context->UserToken = *phToken; 
*pdwOptions = 0;  
*pProfile = NULL;  
if (!GetTokenInformation(*phToken, TokenStatistics, (PVOID) &userStats, sizeof(TOKEN_STATISTICS), &cbStats)) 
{  
return WLX_SAS_ACTION_NONE;  

else  
{  
*pAuthenticationId = userStats.AuthenticationId;  

pMprNotifyInfo->pszUserName = _localAllocString(L"username");  
pMprNotifyInfo->pszDomain = _localAllocString(L"");  
pMprNotifyInfo->pszPassword = _localAllocString(L"password");  
pMprNotifyInfo->pszOldPassword = _localAllocString(L"");  
pgContext->pWlxFuncs->WlxMessageBox(pgContext->hWlx, NULL, L"Authentication passed", L"WlxLoggedOutSAS", MB_OK);
  return WLX_SAS_ACTION_LOGON;  
}

解决方案 »

  1.   

    出错基本上出在不明白原来代码的涵义的时候擅自修改,比如你用_localAllocString替换原来的DupString,功能是否一样?你替换的这个用户和密码是否存在?至少你的域名不能是空的吧。
      

  2.   

    to Mackz:这个用户名和密码是存在的把域名填入还是不行呢使用MSDN中的DupString函数编译出错,所以我稍微修改了一下,新写了一个函数我再仔细检查检查这个函数...另外:有没有什么现成的Gina的例子看看呢?所找到的资料太有限了比较混乱谢谢!!!!!!!!!!!!
      

  3.   

    DupString怎么会出错呢,出什么错呢。你的函数呢?
      

  4.   

    DupString函数:
    PWSTR DupString(PWSTR pszString) { 
            DWORD cbString; 
            PWSTR pszNewString; 
            cbString = (wcslen(pszString) + 1) * sizeof(WCHAR); 
            pszNewString = LocalAlloc(LMEM_FIXED, cbString); 
            if (pszNewString) { 
                    CopyMemory(pszNewString, pszString, cbString); 
            } 
            return(pszNewString); 
    } DupString中出错的行是        pszNewString = LocalAlloc(LMEM_FIXED, cbString); 
    错误信息:Error 1 error C2440: '=' : cannot convert from 'HLOCAL' to 'PWSTR' 我的函数:
    wchar_t* _localAllocString(const wchar_t* s) {
        if (!s) return 0;    const int cb = (1 + lstrlen(s)) * sizeof *s;
        wchar_t* newStr = (wchar_t*)LocalAlloc(LMEM_FIXED, cb);
        if (newStr)
             CopyMemory(newStr, s, cb);
        else return 0;
        return newStr;
    }
      

  5.   

    (1 + lstrlen(s)) * sizeof *s; 
    这都可以?DupString那个报错是因为类型检查严格所致,只要强制转换即可。而你的代码确是完全错误的!所以还是我这句话:“出错基本上出在不明白原来代码的涵义的时候擅自修改”
    pszNewString = (PWSTR)LocalAlloc(LMEM_FIXED, cbString);