|
They are both heap-based memory allocation.
Vaclav_Sal wrote: lpBuffer = (LPBYTE) new BYTE[sizeof(iClipboardSize)];
This is not right. You are allocating 4 bytes of memory, yet the call to memcpy() is copying iClipboardSize bytes (which is likely far more than 4).
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
David,
sorry, I did not included the whole code.
The clipboard size is 640*480*3 + 40.
If the are both heap based why does the method using new fails with this clipboard size?
I think I'll try to build a new DIB bitmap instead of monkeying around whit this packed RGB AVI format. Mainly because I cannot figure out if the RGBQUAD is sized properly and if not how to resize it in BITMAPINFO structure.
Thanks for your help.
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: If the are both heap based why does the method using new fails with this clipboard size?
Because you are only allocating 4 bytes of memory.
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Good spot.
|
|
|
|
|
Serves as a good example, what is the difference of arrays and pointers (and variables)... just recently had that topic. Good spot.
|
|
|
|
|
Good spot, but this discussion also serves as a shinning example on how to change the subject without arousing much suspicion.
I still cannot memcpy 640*480*4 size of buffer!
Thanks anyway. I am working on an alternative.
Vaclav
|
|
|
|
|
Vaclav_Sal wrote: I still cannot memcpy 640*480*4 size of buffer!
Have you tried:
lpBuffer = new BYTE[iClipboardSize];
"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
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
I like rhetorical questions.
|
|
|
|
|
There are days I really like this forum.
|
|
|
|
|
Vaclav_Sal wrote: I still cannot memcpy 640*480*4 size of buffer!
I just tried
int size = 640*480*4;
PBYTE buffa = new BYTE[size];
PBYTE buffb = new BYTE[size];
memcpy(buffb, buffa, size);
and it works fine; total bytes copied 1,228,800.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
of course that works fine, there wasn't any real information in the source buffer!
|
|
|
|
|
And it fails if the destination buffer is smaller than the source buffer.
Thanks for all your inputs - problem solved.
|
|
|
|
|
Vaclav_Sal wrote: And it fails if the destination buffer is smaller than the source buffer.
Who'd a thunk it?
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
I wondered why it was so fast.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Hi all,
i m using atoi function to convert string value to its coressponding integer value.
when i convert "22 dollar" its return 22 but when i convert "dollar 22" its return 0.
how can i get 22 also here.
please help me for this .
thank in advance.
|
|
|
|
|
Iterate through the string and check for numerals using the isdigit function.
Once you get to a digit, continue iteration and save all characters to another array till you do not find a digit.
|
|
|
|
|
The atoi() function (see the MSDN documentation[^]) will stop scanning at the first non-numeric character it encounters. In the case of the string "dollar 22" you first need to adjust your pointer to skip all the characters in front of the number.
Just say 'NO' to evaluated arguments for diadic functions! Ash
|
|
|
|
|
Additionally to what the others said, you can use strpbrk[^] to find the first alphanumeric character inside your string and then use atoi on that to convert.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> "It doesn't work, fix it" does not qualify as a bug report. <
> Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
|
|
|
|
|
I have an EXE class which contains a button resource with ID EXE_BUTTON_RESOURCE
ON_UPDATE_COMMAND_UI(EXE_BUTTON_RESOURCE, OnUpdateExeButtonResource)
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
pCmdUI->Enable(exe_flag);
}
This EXE application will load another DLL class.
DLL class is having a menu item resource with ID DLL_MENU_RESOURCE.
Unfortunately, EXE_BUTTON_RESOURCE and DLL_MENU_RESOURCE is having the same resource ID. To avoid them have conflict ID is pretty difficult, as they are two separate projects.
Whenever exe_flag, which is the member for EXE turn to false, this will affect menu in DLL too. Clicking on DLL_MENU_RESOURCE menu will have no effect at all.
How can I avoid this trap? Having manual inspection on their resource.h files is not an option for me, as they are 2 separate projects, managed by 2 separate teams.
|
|
|
|
|
Try adding the following statement as the first line in every exported function of the DLL.
AFX_MANAGE_STATE(AfxGetStaticModuleState());
|
|
|
|
|
Do you mean code like this ?
void EXE::OnUpdateExeButtonResource(CCmdUI* pCmdUI)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
pCmdUI->Enable(exe_flag);
}
No. It doesn't work. Clicking on DLL's menu item will still have no effect.
Is changing
#define DLL_RESOURCE_ID 1234
to
const int DLL_RESOURCE_ID = ::RegisterWindowMessage(_T("DLL_RESOURCE_ID"));
a elegant solution (To avoid resource ID conflict)? I don't know.
|
|
|
|
|
I meant adding in the DLL's code, not the EXE's.
|
|
|
|
|
I cannot use your suggestion as I am using extension DLL.
http://support.microsoft.com/kb/161589
However, I already did a similar thing even before your suggestion.
void DLL::OnContextMenu(CWnd* pWnd, CPoint point)
{
RestoreDLLState ext;
...
}
RestoreDLLState will load global DLL resource, and load back its original resource once done.
RestoreDLLState::RestoreDLLState()
{
m_hInstOld = AfxGetResourceHandle();
AfxSetResourceHandle(g_hResource);
}
RestoreDLLState::~RestoreDLLState()
{
AfxSetResourceHandle(m_hInstOld);
}
It doesn't work.
|
|
|
|
|
The RegisterWindowMessage Function (Windows)[^] defines a new window message that is guaranteed to be unique throughout the system, and is designed to generate at runtime message IDs that could be used for inter-process communications: using it solve your problem, but it could not be a good idea if you use it extensively, because it waste system resources.
Anyway, the changement you are evaluating, requires that you manually modify the resource.h file on your project to remove the correspondant #define and produce a situation where the resource editor is not able to load and handle your resource script file (i.e. project_name.rc), then you should modify it manually.
|
|
|
|
|
Hi gang,
I've got a custom control (m_HScrollBar1Ex ) which I have made appear over a CTreeView derived interface (CLeftView ) which moves up and down with the CTreeView object's scrollbar moderately well with a call to my control-positioning function PlaceScrollBar in the OnVScroll function. However, the custom control only 'snaps' in to its final position when the left mouse button is released. Ideally I'd like the control to move in absolute synch with the graphics underneath it (ie. the tree control).
Is there another message I could respond to which will allow the custom control to draw itself in the right place before the mouse button is released?
I'm guessing that the answer is a bit more involved than this - in which case any clues that you can give me will be very much appreciated.
Very much looking forward to your replies,
Ben.
void CLeftView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
if (m_HScrollBar1Ex.m_hWnd != NULL){
m_HScrollBar1Ex.ShowWindow(SW_HIDE);
}
PlaceScrollBar();
CTreeView::OnVScroll(nSBCode, nPos, pScrollBar);
}
<pre>
and
<pre>
void CLeftView::PlaceScrollBar(void)
{
if (m_bBlockScrollDraw==FALSE){
CRect parentRect;
CTreeCtrl &ctlFolders = this->GetTreeCtrl();
ctlFolders.GetWindowRect(&parentRect);
ScreenToClient(&parentRect);
CRect contRect;
HTREEITEM hRoot;
HTREEITEM hFolder;
hRoot = ctlFolders.GetSelectedItem();
CRect heightRect;
int count=0;
int yPos=0;
CRect itemRect;
if (ctlFolders.ItemHasChildren(hRoot))
{
HTREEITEM hNextItem;
HTREEITEM hChildItem = ctlFolders.GetChildItem(hRoot);
CWnd * pChild = (CWnd *) &hChildItem;
count = 1;
if (ctlFolders.IsTopParentActive()){
DWORD dwData = ctlFolders.GetItemData(hRoot);
m_dw08bCurNodeVisItems = (dwData & 0x000000FF);
m_dw24bCurNodeScrollPos = (dwData & 0xFFFFFF00) >> 8;
}
else m_dw24bCurNodeScrollPos = 99;
ctlFolders.GetItemRect(hChildItem, itemRect, FALSE);
while (hChildItem != NULL)
{
hNextItem = ctlFolders.GetNextItem(hChildItem, TVGN_NEXT);
if (hNextItem != NULL){
count++;
}
hChildItem = hNextItem;
}
}
if (m_HScrollBar1Ex.m_hWnd != NULL && m_intChildCount > m_dw08bCurNodeVisItems){
m_HScrollBar1Ex.SetScrollRange(1, m_intChildCount-m_dw08bCurNodeVisItems+1);
if (m_dw24bCurNodeScrollPos == 0)
m_HScrollBar1Ex.SetScrollPos(1) ;
else
m_HScrollBar1Ex.SetScrollPos(m_dw24bCurNodeScrollPos);
m_HScrollBar1Ex.GetWindowRect(&contRect);
ScreenToClient(&contRect);
contRect.MoveToX(parentRect.right-contRect.Width()-16);
m_HScrollBar1Ex.SetWindowPos(&wndTop,contRect.left,itemRect.top,
contRect.Width(),count*ctlFolders.GetItemHeight(),SWP_SHOWWINDOW);
}
}
}
|
|
|
|