|
Quote: This code work:
int CPageWelcome::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CStatic * lblPresent = new CStatic();
lblPresent->Create(L"Present", WS_CHILD | WS_VISIBLE,
CRect(20, 20, 100, 40), this);
return 0;
}
This code dont work:
int CPageWelcome::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
CStatic lblPresent;
lblPresent.Create(L"Present", WS_CHILD | WS_VISIBLE,
CRect(20, 20, 100, 40), this);
return 0;
}
Please help i dont understand. Thank.
|
|
|
|
|
In the first code snippet, the CStatic object is created on the heap and will remain in memory till delete is called on the object.
In the second code snippet, the CStatic object is created on the stack and will go out of scope (will be destroyed) as soon as OnCreate exits.
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
|
|
|
|
|
yea thank and if i make
private:
CStatic mpStatic;
like private member variable
End block in OnCreate not destroyed CStatic object and dont work.
If use pointer all OK.
OMG it is work and before 1 hour not =( sorry fkn bug.
Thank you for help. =)
modified 23-Jun-14 4:40am.
|
|
|
|
|
Have you tried to set
CStatic lblPresent
as member variable ? Something like
CStatic m_lblPresent
|
|
|
|
|
I have my program like this
int main()
{
char *p = "Test"
p++;
p++;
printf("%s", p[-1]);
return 0;
}
what will be printed by printf statment
Thanks,
Sakthi
|
|
|
|
|
The statement is perfectly valid "in this case".
Using an index will simply add it to the address.
So p[-1] will internally become *(p-1) .
In this case, since you're incrementing p twice, p[-1] should print e .
Correction - My earlier comment would be true if you change the statement to printf("%c", p[-1]);
«_Superman_»
I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++) (October 2009 - September 2013) Polymorphism in C
modified 23-Jun-14 4:07am.
|
|
|
|
|
p[-1] returns the character at that position ('e' in your case). When passing this value as address of a string to printf, it will try to print the memory content at the address 0x65 as string.
|
|
|
|
|
While p[-1] is valid (why didn't you try to compile it?), you are using it the wrong way: a char pointer (char * ) is expected by the format specifier "%s" while you are passing a char ( p[-1] , is like *(p-1) , that is a char ). You should have written either:
printf("%s\n", &p[-1]); producing output
est or
printf("%c\n",p[-1]); , producing output
e
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
But, when i executed the program in Visual studio i got run time error
Thanks,
Sakthi
|
|
|
|
|
What program? What error?
(Please provide both).
THESE PEOPLE REALLY BOTHER ME!! How can they know what you should do without knowing what you want done?!?!
-- C++ FQA Lite
|
|
|
|
|
Hi,
int main()
{
char *p = "Test";
p++;
p++;
printf("%s", p[-1]);
getchar();
return 0;
}
Suppose think the starting address of p will be 0x20000,
You are incrementing p two times, so before entering to the highlighted line in above code value of p is 0x20002 and the content in that location as starting address will be st.
Then p[-1] means *(p-1), means value at 0x20001 location. means 'e'.
In printf, %s is a format specifier wich will try to display the string at the memory location provided in variable list. Here the address provided in variable list is value of *(p-1), i.e, 'e' (internally this is 0x65). So %s dereferences the value at 0x65, so some garbage value it will print finally. otherwise will terminate the program as memory is un referenced.
Thanks
|
|
|
|
|
Hello. I am trying to play video file using DirectShow found on this MSDN reference. I am facing two problems.
1- local H264 video doesn't get rendered properly. A frame shows and them some blocks keep showing.
2- Can not get notifications on my dialog window using WndProc. Using this sample.
I am using following code for getting events.
void CDShowPlayerSampleDlg::OnStartPlay()
{
CPlayer::m_hWndPlayerDlg = this->m_hWnd; BOOL bResult = m_objPlayer.StartPlay(); }
LRESULT CDShowPlayerSampleDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch(wParam) {
case WM_GRAPHNOTIFY:
}
}
Now I am setting the event notifications on the IGraphBuilder like this (in CPlayer).
HRESULT hResult = m_pGraphBuilder->QueryInterface(IID_IMediaEventEx, (void**)&m_pEvent);
hResult = m_pEvent->SetNotifyWindow((OAHWND)m_hWndPlayerDlg, WM_GRAPHNOTIFY, 0);
1- So why can not I get notifications in CDShowPlayerSampleDlg::WindowProc?
2- And why is that Windows Media Video (.wmv) file plays correctly but H264 does not. What could I do for smooth H264 playback?
Thanks for any pointers.
This world is going to explode due to international politics, SOON.
modified 20-Jun-14 8:18am.
|
|
|
|
|
switch(wParam)
switch(message)
|
|
|
|
|
Yes. it solved my problem.
On a different note, as you can see in my code OnStartPlay() , I am storing my MainDlg's HWND in the CPlayer. What if I don't have a window and I still want to process these kind of messages from CPlayer? Thanks
This world is going to explode due to international politics, SOON.
|
|
|
|
|
You must have a Window, in order to receive the WM_ messages. However, you can create a Window but not make it visible if necessary.
|
|
|
|
|
Windows XP, Visual Studio 2008, C++
bool procedure( wstring *target )
{...
int wrote_count = swprintf_s(
text_to_log,
MAX_SIZE,
L"Target is %ls",
target );
... }
The debugger shows text "Messsage" in variable target but text_to_log does not have that text.
text_to_log is declared as WCHAR text_to_log[ MAX_SIZE ] where MAX_SIZE is 400.
I have tried creating a local varible of type wstring and the text will copy from target to that local string. Using that local string in the printf statement produces the same result.
What do I need to change to incorporate the text from target into the text of text_to_log?
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 19-Jun-14 14:22pm.
|
|
|
|
|
What is the value of wrote_count ? If -1 , what is errno set to?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
wrote_count is 57, I simplified some when writing this post. That value matches what is in the string it writes to. The text from target is simply missing in action.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
|
|
|
|
|
bkelly13 wrote: The text from target is simply missing in action. How are you verifying this?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Just a guess, but try using target->c_str() in the swprintf_s function call instead of just target .
I believe the printf functions expect C-style strings, not C++ string classes.
|
|
|
|
|
Just tried that: error 2228, left of .c_str() must have class/struct/union
Edit:
(*target).c_str()
You got me most of the way there, evidently there is a precedence problem. With the above the text shows up.
Thank you for your help.
Thank you for your time
If you work with telemetry, please check this bulletin board: www.irigbb.com
modified 19-Jun-14 13:38pm.
|
|
|
|
|
Why not just:
target->c_str()
?
|
|
|
|
|
I have given the value for the connetionstring and TeamsConnectionString in registry settings but s still i am facing the following error.
can anyone please suggest me to resolve this error
Error details from event details:
---------------------------------
The following information was included with the event:
Could not get the ConnectionString from Registry Key =SOFTWARE\Kimberly-Clark\Knowledge Management; Value = TeamsConnectionString
Last error number: 0
|
|
|
|
|
You need to show the code you are using to get the key, and the exact error message or return code.
|
|
|
|
|
lfLog.DebugMsgStart(" Retrieving Connection String");
csKey = "SOFTWARE\\Kimberly-Clark\\Knowledge Management";
if ( !rReg.GetSZValue(HKEY_LOCAL_MACHINE,csKey, csConnectionStringReference, csConnectionString))
{
lfLog.DebugMsgEnd("FAILED");
csMsg.Format("Could not get the ConnectionString from Registry Key = '%s', Value = '%s'", csKey, csConnectionStringReference);
elLog.ErrorMsg(csMsg);
lfLog.ErrorMsg(csMsg);
mclLog.ErrorMsg( 0, "ConnectionString");
goto exit30;
}
lfLog.DebugMsgEnd("SUCCESS");
and i am having the values in registry under the path mentioned in the code
|
|
|
|