none
求救!关于CreateWindowEx创建ListViewControl出现1407错误! RRS feed

  • 问题

  • // dllmain.cpp : 定义 DLL 应用程序的入口点。
    #include "stdafx.h"
    HINSTANCE g_hInst;
    HWND hWinMain,hList;
    #define ID_LISTVIEW 104

    #pragma comment(lib,"comctl32")

    void InitListView()
    {

     LV_COLUMN lvc;

     hList=CreateWindowEx(WS_EX_CLIENTEDGE, WC_LISTVIEWA, NULL,
      WS_CHILD | WS_VISIBLE | LVS_REPORT | LVS_SINGLESEL | LVS_SHAREIMAGELISTS,
      0, 0, 0, 0, hWinMain, (HMENU)ID_LISTVIEW, g_hInst, NULL);
     if(!hList)
     {
      char err[50]={0};
      wsprintf(err,"Error Code=%d",GetLastError());
      MessageBox(hWinMain,err,"Error",MB_OK);

     }
     SendMessage(hList, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP | LVS_EX_GRIDLINES);

     lvc.mask= LVCF_TEXT | LVCF_WIDTH ;
     lvc.fmt=LVCFMT_RIGHT;
     lvc.pszText="序号";
     lvc.cx=50;
     SendMessage(hList, LVM_INSERTCOLUMN, 0, (LPARAM)&lvc);

     lvc.mask |= LVCF_FMT;
     lvc.fmt=LVCFMT_LEFT;

     lvc.pszText="CCCC";
     lvc.cx= 350;
     SendMessage(hList, LVM_INSERTCOLUMN, 1, (LPARAM)&lvc);

     lvc.pszText="AAAA";
     lvc.cx= 100;
     SendMessage(hList, LVM_INSERTCOLUMN, 2, (LPARAM)&lvc);

    }

    LRESULT CALLBACK  ProcWinMain(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
    {
     switch(uMsg)
     {
      //HANDLE_MSG(hwnd,WM_COMMAND,Cls_OnCommand);
     case WM_SIZE:
      MoveWindow(hList,0,0,LOWORD(lParam),HIWORD(lParam),TRUE);
      return 0;
     case WM_SHOWWINDOW:
      
      return 0;
     case WM_CREATE:
      hWinMain=hwnd;
      InitListView();
      //LocateNtdllEntry();
      //FindExport();
      //DebugPrivilege (SE_DEBUG_NAME,TRUE);
      //GetSSDT();
      return 0;
     case WM_DESTROY:
      PostQuitMessage(0);
      return 0;
     case WM_NOTIFY:
      switch (LOWORD(wParam))
      {
      case ID_LISTVIEW:
       if( ((LPNMHDR)lParam)->code == NM_CUSTOMDRAW )
       {
        switch( ((LPNMLVCUSTOMDRAW)lParam)->nmcd.dwDrawStage )
        {
        case CDDS_PREPAINT:
         return CDRF_NOTIFYITEMDRAW;
        case CDDS_ITEMPREPAINT:
         {
          LPNMLVCUSTOMDRAW customDraw = (LPNMLVCUSTOMDRAW)lParam;
          customDraw->clrTextBk=customDraw->nmcd.dwItemSpec%2?RGB(250, 250, 250):RGB(0xFF, 0xFF, 0xFF);
          //if () customDraw->clrText = RGB(255, 0, 0) ;
          //else customDraw->clrText = RGB(0, 0, 0) ;
          return CDRF_NEWFONT;
         }
         break;
        default:
         return CDRF_DODEFAULT;
        }
       }
       break;
      }
      break;
     default:
      return DefWindowProc(hwnd,uMsg,wParam,lParam);
     }
     return 0;
    }
    int ShowDialog(HINSTANCE hInstance)
    {
     WNDCLASSEX stWndClass;
     MSG stMsg;
     INITCOMMONCONTROLSEX iex;

     g_hInst=hInstance;
     iex.dwSize=sizeof(iex);
     iex.dwICC=ICC_LISTVIEW_CLASSES;
     if(!InitCommonControlsEx(&iex))
     {
      char err[50]={0};
      wsprintf(err,"Error Code=%d",GetLastError());
      MessageBox(hWinMain,err,"2",MB_OK);
      
     }
     // ssdt_list=new SSDT_LIST_ENTRY[500];

     ZeroMemory(&stWndClass,sizeof(stWndClass));
     // HMENU hMenu=LoadMenu(hInstance,MAKEINTRESOURCE(IDR_MENU1));
     HICON g_hIcon=LoadIcon(hInstance,MAKEINTRESOURCE(IDI_ICON1));;
     stWndClass.hCursor=LoadCursor(0,IDC_ARROW);
     stWndClass.cbSize=sizeof(WNDCLASSEX);
     stWndClass.style=CS_HREDRAW | CS_VREDRAW;
     stWndClass.lpfnWndProc=ProcWinMain;
     stWndClass.hbrBackground=(HBRUSH)(COLOR_WINDOW + 1);
     stWndClass.lpszClassName="DymaticCreateWindow";
     stWndClass.hIcon=g_hIcon;
     stWndClass.hInstance=g_hInst;

     if(!RegisterClassEx(&stWndClass))
     {
      char err[50]={0};
      wsprintf(err,"Error Code=%d",GetLastError());
      MessageBox(hWinMain,err,"Error",MB_OK);

     }
     //建立并显示窗口
     CreateWindowEx(WS_EX_CLIENTEDGE,"DymaticCreateWindow","动态创建窗口",
      WS_OVERLAPPEDWINDOW,
      CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
      NULL,NULL/*hMenu*/,hInstance,NULL);

     ShowWindow(hWinMain,SW_SHOWNORMAL);
     UpdateWindow(hWinMain);

     //消息循环
     while (PeekMessage(&stMsg,NULL,0,0,PM_REMOVE))
     {
      TranslateMessage(&stMsg);
      DispatchMessage(&stMsg);
     }
     while (1)
     {
       ShowWindow(hWinMain,SW_SHOWNORMAL);
     }
     WaitMessage();
     return (int)stMsg.wParam;
    }

    BOOL APIENTRY DllMain( HMODULE hModule,
           DWORD  ul_reason_for_call,
           LPVOID lpReserved
      )
    {

     switch (ul_reason_for_call)
     {
     case DLL_PROCESS_ATTACH:
       //::CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)ShowDialog,(LPVOID)hModule,NULL,NULL);
       ShowDialog(hModule);
       break;
     case DLL_THREAD_ATTACH:
     case DLL_THREAD_DETACH:
     case DLL_PROCESS_DETACH:
      break;
     }
     return TRUE;
    }

    上面是源代码,程序远程注入,在CreateProcess 的时候把进程暂停,然后远程注入执行,唯独ListView不出来,感觉像是comctl32加载问题, GetLastError =1407  无有效的模组

    怎么解决,,,如果不用CreateThread去创建窗口没有任何问题


    dspapi@gmail.com
    2010年5月29日 16:06

答案

  • 看看创建一个treeview能不能出来,不能出来的话就是没调用InitCommonControls

    The following is signature, not part of post
    Please mark the post answered your question as the answer, and mark other helpful posts as helpful, so they will appear differently to other users who are visiting your thread for the same problem.
    Visual C++ MVP
    2010年5月31日 2:07
    版主