c++ - 静态函数中不可访问的非静态成员

标签 c++ winapi dialog static-methods static-members

我定义了一个函数

HRESULT AMEPreviewHandler:: CreateHtmlPreview()
{
    ULONG  CbRead;
    const int Size= 115000;
    char Buffer[Size+1];
    HRESULT hr = m_pStream->Read(Buffer, Size, &CbRead ); 
    //this m_pStream is not accessible here even it is declared globally. the program is asking me to 
    // declare it static because this CreateHtmlPreview() function called 
    //inside the Static function (i mean here :-static CreateDialog\WM_Command\CreateHtmlPreview();)
    //but if i declare it static the two problems arised are 
    //(1.) It is not able to access the value of the m_pStream which is defined globally.
    //(2.)If i declare it static globally then there are so many other function which are using this
    // value of m_pStream are not able to access it because they are non static.  

}

它在我的程序中的某处声明为静态的,如下所示:

static HRESULT CreateHtmlPreview(); //i have declared it static because i am calling this function from DialogProc function.If i dont create it static here it dont work

//The function CreateHtmlPreview() is called inside the DialogProc function like this-

BOOL CALLBACK AMEPreviewHandler::DialogProc(HWND m_hwndPreview, UINT Umsg, WPARAM wParam, LPARAM lParam) 
{......
case WM_COMMAND:
{  
    int ctl = LOWORD(wParam);
    int event = HIWORD(wParam);

    if (ctl == IDC_PREVIOUS && event == BN_CLICKED ) 
    {                       
        CreateHtmlPreview(); //here i am calling the function
        return 0;
    }  
}

那么如何才能使非静态 m_pStream 的值在静态 CreateHtmlPreview() 函数定义中可访问?

最佳答案

在静态类函数中,您只能访问静态类成员。

关于c++ - 静态函数中不可访问的非静态成员,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17789402/

相关文章:

Android:Dialog 和 onResume() 方法中的 requestWindowFeature 错误

c++ - 将项目小部件宽度(列表内容)调整为父 QListWidget 宽度

带有引用参数的 C++ 函数因迭代器而出错。求解释

c++ - 确定两个路径是否引用 Windows 中同一文件的最佳方法?

c++ - boost::asio 无法从文件中读取超过 65536 个字节

c# - 关闭浏览对话框导致窗体关闭

c++ - (Qt C++) 将 QString 以二进制形式写入文件

c++ - 无论如何在 Win32 API 中动态释放线程本地存储?

c - 使用 TextOut 函数打印新行

java - Java "go to previous/next"选项中的 GUI?