I have defined a function
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.
}
It is declared static somewhere in my program like this:
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;
}
}
}
So what can be done to make the value of non static m_pStream
accessible in the static CreateHtmlPreview()
function definition ?
Can't you just pass the m_pStream var as a function argument?
Instead of defining the function this way
You can do it like this (you should define the stream type!)
And call it like this
In static class functions you can access to only static class members.
DoctorLove i have solved this problem actually the code by idea of accesing the non static varible using this parameter- the problem was i had not initialized the instance in WM_INITDIALOG now i donze like this-
and it works fine.
What if you make
CreateHtmlPreview()
a free function?What if you make it just create an html preview (instead of also reading from a stream)?
Then read the data from the proc, and call it in
DialogProc
You will probably need to make the function return the preview to be any use though.
You do say you need to make it
however, the DialogProc is not static (in the code you have posted), so I don't see what the problem would be.