开发者

codeblock vs VS2010

I have got following code:-

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    char ay[256]={0};//HWND hwnd= GetForegroundWindow();
    if( GetClassName(hwnd,ay,256))
    {
        char x[70]={0};
        GetWindowText(hwnd,x,70);
        if(IsWindowVisible(hwnd))
        {
            // Captur开发者_运维知识库eAnImage(hwNd,hwnd);
            HINSTANCE hins= (HINSTANCE) GetWindowLong(hwnd,GWL_HINSTANCE);
            WNDCLASSEX lpwcx;
            GetClassInfoEx(hins,ay,&lpwcx);

            if (MessageBox(0, 
                           strcat(strcat(x, "\r\n"), lpwcx.lpszClassName),
                           "Info", 0x06L) == IDTRYAGAIN)
            {
                return false;
            }
        }
    }
    return true;
}

void cstm()
{
    EnumWindows(EnumWindowsProc,0);
}

This runs fine on Codeblocks (with VS 2010 compiler(cl)) but VS2010 gives a corrupted lpwcx value, I have tried the Unicode as well as Ascii to tackle this but no good result at all. The first lpwcx is correct but later they return class not found(1411) ,although the hinstance and class name is correct.

Please help.


   strcat(strcat(x, "\r\n"), lpwcx.lpszClassName),

The odds that this will overflow the x buffer and stomp some local variable values, like *lpwcx", are very high. 70 chars is unreasonably frugal. If you don't want to use strcat_s() then at least make it bigger. And yes, initialize lpwcx.cbSize


Always fill in the cbSize member of data blocks before calling any API functions. Many of them rely upon this value to know which version of the data structure they should fill in.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜