|
I have a function that is handled for my listbox's double-click event. When a file in the list is double clicked it is opened in its default application. It was suggested by one of the users that I make this file read-only after it was opened so that if the user tried to then save a modification they would be reminded. Since the file is saved in the database, when my app closes, it goes through the temp folder and deletes all files that were open during this session. In case I also made it where it'll remove the read-only attribute and delete it if it's already there. The problem is that the BYTE buffer I allocate with the new operator is causing a memory leak, and when I try to call delete on it, I get an error in this section of code in "comip.h":
~_com_ptr_t() throw()<br />
{ <br />
_Release(); <br />
}
here's my function, with offending lines in bold:
BeginWaitCursor();
_RecordsetPtr rst;
strWhere.Format("LinkID = %d",data);
rst = theApp.GetRecordset(_T("*"),_T("tblLink") ,strWhere);
CString str,strPath;
FieldsPtr pFields = rst->GetFields();
FieldPtr pField,pName;
pField= pFields->GetItem(_T("FileBytes"));
pName = pFields->GetItem(_T("Link"));
unsigned long nLength = pField->GetActualSize();
str.Format("%s",(char*)_bstr_t(pName->Value));
_variant_t varBLOB = pField->GetChunk(nLength);
pBuf = new BYTE[nLength];
SafeArrayAccessData(varBLOB.parray,(void **)&pBuf);
pBytes = pBuf;
SafeArrayUnaccessData(varBLOB.parray);
::GetModuleFileName(NULL,szPath,512);
strPath.Format("%s",szPath);
int pos = strPath.ReverseFind('\\');
strDirectory = strPath.Left(pos + 1) + "temp\\";
strPath = strDirectory + url;
CreateDirectory(strDirectory,NULL);
CFile file;
CFileException ex;
CFileStatus status;
status.m_attribute = 0;
if(file.Open(strPath,CFile::modeRead,&ex))
{
file.Close();
CFile::SetStatus(strPath,status);
DeleteFile(strPath);
}
if(file.Open(strPath,CFile::modeCreate | CFile::modeWrite,&ex))
{
file.Write(pBytes,nLength);
file.Close();
file.GetStatus(status);
status.m_attribute |= 0x01;
CFile::SetStatus(strPath,status);
int iReturn = (int) ShellExecute(NULL, _T("open"), strPath, NULL, NULL, SW_SHOWNORMAL);
if (iReturn <= 32)
MessageBox (_T("Cannot open file. File may have been moved or deleted."), _T("Error!"), MB_OK | MB_ICONEXCLAMATION) ;
if(url.GetLength()==0)
MessageBox (_T("This is an empty entry! Try clicking a filled link! "), _T("Error!"), MB_OK | MB_ICONEXCLAMATION) ;
}
else
{
AfxMessageBox("File could not be opened from this location.\r\n"
"Check to make sure you don\'t already have this attachment open.",MB_ICONINFORMATION);
}
}
MYCATCHALL
url.ReleaseBuffer();
EndWaitCursor();
[insert witty comment here]
bdiamond
|
|
|
|
|
Hi,
Does anyone know how to write a text string on a video stream captured with the DirectX libraries in a way that the text is embedded in the stream ? In other words, it is possible to apply a text overlay on a video stream that will be saved with the stream ?
Any help would be greatly appreciated,
John
|
|
|
|
|
Hi,
Does anyone know how to write a text string on a video stream captured with the DirectX libraries in a way that the text is embedded in the stream ? In other words, it is possible to apply a text overlay on a video stream that will be saved with the stream ?
Any help would be greatly appreciated,
John
|
|
|
|
|
Hi i am tyring to build the sample console app using Zlib compression library.
I am getting linker error for following functions.
int __cdecl inflate_trees_fixed(...)<br />
void __cdecl zcfree(void *,void *)<br />
void * __cdecl zcalloc(void *,unsigned int,unsigned int)
for the first function inflate_trees_fixed(...) there is no function prototype in any of the file.
but it has following code in zconf.h file
<br />
#if defined(__MVS__)<br />
# pragma map(inflate_trees_free,"INTRFR")<br />
#endif <br />
AFAIK, if you are using #pragma map then you need not to define the function prototype.
Can someone throw light on this.
Thanks in advance.
Abhi Lahare
|
|
|
|
|
I have a listCtrl in report mode. Now I display a dialog to display/edit items when I double-click on an item in the list.
The problem is I would like to return to the dialog but with the selected item clearded down.
Currently as soon as I click on the dialog the last item is selected. I am using LVS_EX_FULLROWSELECT, so the full row is always selected.
Simply how do I unselect the selected row?
|
|
|
|
|
You need to clear that items selected state.
If you are using MCF:
m_LI.SetItemState (nItem, LVIS_SELECTED, LVIS_SELECTED);
m_LI.SetItemState (nItem, 0, LVIS_SELECTED);
m_LI.Invalidate ();
Otherwise:
LVITEM lvi;
memset (&lvi, 0, sizeof (lvi));
lvi.mask = LVIF_STATE;
lvi.stateMask = LVIS_SELECTED;
lvi.state = bSelected ? LVIS_SELECTED : 0;
SendMessage (hWndLI, LVM_SETITEM, 0, (LPARAM) &lvi);
Does that help?
Iain.
|
|
|
|
|
sweep123 wrote:
The problem is I would like to return to the dialog...
From where?
sweep123 wrote:
...the selected item clearded down.
What does "clearded down" mean?
sweep123 wrote:
Simply how do I unselect the selected row?
Call SetItemState(nItem, 0, LVIS_SELECTED) .
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
sweep123 wrote:
The problem is I would like to return to the dialog...
From where?
A Modeless Dialog (edit some fields on this row)
sweep123 wrote:
...the selected item clearded down.
What does "clearded down" mean?
When I next click on the dialog with the listctrl the last item is still selected.
sweep123 wrote:
Simply how do I unselect the selected row?
Call SetItemState(nItem, 0, LVIS_SELECTED).
That works when I display the Modeless dialog - thanks.
One other question, how do I force a complete redraw to the listctrl; say I need to show many changes?
Thanks for you post.
|
|
|
|
|
sweep123 wrote:
One other question, how do I force a complete redraw to the listctrl; say I need to show many changes?
If the items are kept in a data structure of some sort, you can just clear the contents of the list control and re-add them from the data structure. If you are just editing one item at a time, call SetItemText() after the modeless dialog is dismissed.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks again for your post.#
I endd up using Invalidate() to redraw the list following data changes in the structure.
I use SetItemText for small changes.
I dont know if Invalidate() is OK to use.
|
|
|
|
|
i am trying to compling an oci program but keep getting these error messages:
Linking...
cdemorid.obj : error LNK2001: unresolved external symbol _OCIDescriptorAlloc
cdemorid.obj : error LNK2001: unresolved external symbol _OCIHandleAlloc
cdemorid.obj : error LNK2001: unresolved external symbol _OCILogon
cdemorid.obj : error LNK2001: unresolved external symbol "int __cdecl init_handles(struct OCIEnv * *,struct OCIError * *,int)" (?init_handles@@YAHPAPAUOCIEnv@@PAPAUOCIError@@H@Z)
cdemorid.obj : error LNK2001: unresolved external symbol _OCIEnvInit
cdemorid.obj : error LNK2001: unresolved external symbol _OCIInitialize
cdemorid.obj : error LNK2001: unresolved external symbol _OCIHandleFree
cdemorid.obj : error LNK2001: unresolved external symbol _OCILogoff
cdemorid.obj : error LNK2001: unresolved external symbol _OCIErrorGet
cdemorid.obj : error LNK2001: unresolved external symbol _OCIAttrGet
cdemorid.obj : error LNK2001: unresolved external symbol _OCIStmtFetch
cdemorid.obj : error LNK2001: unresolved external symbol _OCIDefineByPos
cdemorid.obj : error LNK2001: unresolved external symbol _OCIStmtExecute
cdemorid.obj : error LNK2001: unresolved external symbol _OCIAttrSet
cdemorid.obj : error LNK2001: unresolved external symbol _OCIStmtPrepare
cdemorid.obj : error LNK2001: unresolved external symbol _OCIBindByPos
Debug/cdemorid.exe : fatal error LNK1120: 16 unresolved externals
Error executing link.exe.
cdemorid.exe - 17 error(s), 1 warning(s)
|
|
|
|
|
did you well included the headers in the source files, and don't you use in you project some extern variables ?
TOXCCT >>> GEII power
|
|
|
|
|
Hi ,
I use MVC++ editor for my vc++ program. When I try to debug it, it shows the point where an exception occured in the assembly language (Disassmebly). I dont know how to convert and find where it happened in the actual code.
what do I do to find where the exception occured in my actual code?
Thanks,
Deepak Samuel.
|
|
|
|
|
Use "Call Stack" to view history of function calls leading to exception.;)
ARSALAN MALIK
|
|
|
|
|
you cannot debug a program compiled in "Release Mode". if you have the source, use the call stack (as said previously) or place some breakpoints where you want to stop the execution, but be SURE you are compiling in "DEBUG MODE ".
you could also click on the rebuild all menu item ; sometimes, it is useful 'cause VC++ fails in its links.
Otherwise, two choices for you : first of them, you learn pentium assembly
second one, you let the program with its bugs and throw it to the trash...
TOXCCT >>> GEII power
|
|
|
|
|
hello sir
I am working on disk imaging. I am able to read the hard disk and getting its image in a file and in a buffer.I am also able to write this image back. but i want to connect an image of hard disk as a virtual logical disk.So that i am able to cut, copy data from that virtual drive. Plz help me by giving programming clue and solution of this problem.
With best regards
darpan kamboj
|
|
|
|
|
Hi
There are many Win32 APIs that when passed with a NULL returns the size of the buffer it is expecting (say- GetLogicalDriveStrings).
The question is which one would be better.
1. Create a reasonable sized array and call api.
2. Call the API twice and then allocate.
Regards
Shiraz
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
I'm yet to see the speed of a program be affected by doing twice API calls: most slow code I've seen was because of bad coding practices (aka messy, ill-written and structured code) or because of poor algorithms.
Answering your question: you don't need to pass NULL on the first call - you can use a reasonable sized array. Then, if the call fails because of the buffer size, you can retry it with a bigger buffer.
Yes, even I am blogging now!
|
|
|
|
|
Premature optimization is the root of all evil. (in programing)
Do not ask this question unless you have your app mostly completed, it is running too slow, and you have determined that calls to one particular API are taking too long!
In general if you know the size of data you need it doesn't matter if the API can return more, just ask for how much of it you will need. If you don't know, then pick one of the two.
|
|
|
|
|
Hi
I have completed the whole application. And My application also runs quite fast .
But its always good to understand what we have done is DONE, atleast thats why it is called software engineering.
Regards
Shiraz
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
If you realy want to know where your code is spending its time then profiling is the answer. I find Glowcode www.glowcode.com[^] very good for this.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
For what CPU with what cache size? How much memory are we talking about in the typical case? Worse case? Best case? What compiler? What memory manager in the OS and/or standard libraries? How complex is the function you are calling?
These can make a LARGE difference. And they affect each other. (compilers optimize different for different CPUs, and different optimizations change what it is best) Even given two otherwise identail CPUs, except for cache sizes, there can be a difference. And of course if your function is slow you need to give it enough memory so you don't have to do it again.
As for engineering, smart engineers know when to quit. You will never have time in your life to learn it all! Learn what is important now, and be aware of what you don't know. If it becomes important, learn it then.
|
|
|
|
|
zainu wrote:
The question is which one would be better.
"Better" means different things to different people.
10-15 years ago when a program's efficiency had to be measured with a micrometer having 0.001" precision, this might have been a valid concern. Today it will go unnoticed, mainly because so many things are also going on. Asking the memory manager for another 10KB of memory, or spending a few more CPU cycles calling a function an extra time pale in comparison.
Do what you need to to make your code work with as few errors as possible.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Hi..
Thankyou all for your suggestions...
I just asked this question inspired by curiosity..
Its true that efficiency is a compramise between memory and cpu cycles. Anyway I believe we should keep these things in mind while creating softwares.
Thanks again
Regards
Shiraz
The Best Relligion is Science.
Once you understand it, you will know God.
|
|
|
|
|
I need help,
I want to use gdiplus.dll but explicitly
This question is also general
How can I explicitly use class from some DLL library?
I know how to use function, I can imagine variable
..but how to manage Class with all its class member function
Thanx
viliam
|
|
|
|