|
Is it possible to display a CFormView in a CFrameWnd without using all of the dyncreate stuff? I ask because I don't want to use any of the document stuff - I just want the CFrameWnd to display the CFormView in its client area.
Thanks,
Adam
|
|
|
|
|
Hi,
I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:
LRESULT CNetworkMonitoringListView::OnThreadUpdate(WPARAM wParam, LPARAM lParam)
{
CString sResult;
LV_ITEM lvi;
lvi.mask = LVIF_TEXT | LVIF_DI_SETITEM;
lvi.iItem = (INT)lParam;
lvi.iSubItem = 0;
lvi.pszText = (LPTSTR)(LPCTSTR)lParam;
GetListCtrl().InsertItem(&lvi);
for (int i = 0; i < 5; i++)
{
lvi.iSubItem = i;
GetDocument()->m_cs.Lock();
sResult = GetDocument()->m_capturedPacket.GetDescription((UINT)lParam, i);
GetDocument()->m_cs.Unlock();
lvi.pszText = (LPTSTR)(LPCTSTR)(sResult);
GetListCtrl().SetItem(&lvi);
}
return 0;
}
The second time the message from the worker thread is processed
GetListCtrl().InsertItem(&lvi)
causes an access violation and fails to add another entry into the CListview, is there anything I can do?
Cheers
Packetlos
|
|
|
|
|
packetlos wrote:
I am calling the following bit of code from a worker thread via SendMessage to update the user interface in the view:
Use PostMessage() instead. Read this article.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Cheers for the link, i have read the article and I am doing what it suggests by using a user defined message to trigger OnThreadUpdate now using PostMessage() and it is still causing access violations. Any other things I should be looking at anybody?
Thanks
|
|
|
|
|
The VC Debugger will point you towards the location of the access violation, which should help you to fix the cause.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
// My Code
TCHAR m_szDrive[10];
TCHAR m_szDir[MAX_PATH];
TCHAR m_szFullPath[MAX_PATH];
CString sFile;
// Application Path
::GetModuleFileName(NULL,m_szFullPath,MAX_PATH);
_splitpath(m_szFullPath,m_szDrive,m_szDir,NULL,NULL);
sFile=m_szDrive;
sFile+=m_szDir;
sFile+=_T("myfile.txt");
HANDLE hfile=CreateFile(sFile,.... THAT DOESN'T WORK
Do you know how can I convert my string to the right parameter?
Try it, hfile always 0xfffffff
Thanks
Doc
|
|
|
|
|
doctorpi wrote:
HANDLE hfile=CreateFile(sFile,.... THAT DOESN'T WORK
Define "DOESN'T WORK" further. Are you getting compiler, or runtime errors? What does GetLastError() return?
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|
|
Recommend using makepath(), it should work anyway. But the problem probably lies in the arguments to CreateFile() which you are not giving us. Does the file already exist? Are you opening is with CREATE_ALWAYS or what?
INTP
|
|
|
|
|
Hello doctorpi,
Here's a snippet that I used - it is part of code to examine a DACL and/or SACL.
Jeff
DWORD dwDesiredAccess = READ_CONTROL;
if( TRUE == m_bSACL ) { dwDesiredAccess |= ACCESS_SYSTEM_SECURITY; }
if( TRUE == bDirectory ) {
hFile = CreateFile( pszFileObject, dwDesiredAccess, 0,
NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL );
} else {
hFile = CreateFile( pszFileObject, dwDesiredAccess, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
}
if( hFile == INVALID_HANDLE_VALUE ) {
outfile.WriteString( (CString)pszFileObject + _T("\n") );
switch( GetLastError() ) {
case ERROR_FILE_NOT_FOUND:
outfile.WriteString( _T(" ERROR: The system cannot find the file specified.\n") );
break;
case ERROR_ACCESS_DENIED:
outfile.WriteString( _T(" ERROR: Access Denied.\n") );
break;
case ERROR_BAD_NETPATH:
outfile.WriteString( _T(" ERROR: The network path was not found.\n") );
break;
case ERROR_SHARING_VIOLATION:
outfile.WriteString( _T(" ERROR: The process cannot access the file because it is being used by another process.\n") );
break;
case ERROR_PRIVILEGE_NOT_HELD:
outfile.WriteString( _T(" ERROR: A required privilege is not held by the client.\n") );
break;
default:
szMessage.Format( _T(" ERROR: %d\n"), GetLastError() );
outfile.WriteString( szMessage );
}
outfile.WriteString( _T("\n") );
return;
}
|
|
|
|
|
There could be lots of reasons for your code's not working fine. Use GetLastError() to find out.
Gurmeet S. Kochar
If you believe in God, it's because of the Devil
|
|
|
|
|
The error is that if I put
HANDLE hfile=CreateFile("c:\\Myapp\\Myfile.txt",......) WORKS (the handle is not -1) And if I put the code of my first post with the same name file when debugging the return value is -1 and the problem is related to the name of the file.
Why is diferent "c:\\Myapp\\Myfile.txt" to "c:\Myapp\Myfile.txt" that is what I receive from the get app path?
Thanks for your help.
Best Regards
Doc
|
|
|
|
|
So Sorry guys
Completely my fault. Unfortunately the file was open before, and the error was due to this.
Sorry for your time spent in this silly mistake.
Get a beer , I'll pay.
Doc
|
|
|
|
|
I've got a problem and I was wondering if anyone else has had it, and if so, how they fixed it.
I've created an installer package using Visual Studio, and it works just fine about 99% of the time. However, a few times when it goes to install the program (on an upgrade), it won't really upgrade the program to the new executable and create another entry in the add/remove programs window. I have the DetectNewerInstalledVersion set to true, along with Remove PreviousVersions, and have incremented the Version.
It does install/upgrade correctly most of the time, but on two computers so far, the user has to manaully uninstall the previous version before it will install correctly. Any ideas on what is going on/how to fix it?
|
|
|
|
|
Well not really a programming question. What, if any, kind of software protection scheme do you or you company use to protect yourself against piracy, ect?
Any recommendations for commercial products?
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
Well, it depends on your wish. It's quite possible to make everything yourself, with key around 30 chars, code encryption etc. I did this in my last project, since I don't wanted to use Asprotect, and it seems to be quite stable till now.
There are also several ready to use solutions:
-Asprotect (aspack.com, at the moment they have some problems, either with hosting or hackers): long key (around 500 characters), but version 2 promised to have short key;
- Armadillo (http://www.siliconrealms.com/armadillo.shtml)
- HardKey(http://www.strongbit.com/) - short key;
- activatesoft.net - activation service, combined with hardkey system;
You can also check http://www.exetools.com/protectors.htm for a list.
Anyway, do not forget that anything can be cracked. What can not be cracked in pure, will be purchased, cracked, and chargebacked
Igor Green
http://www.grigsoft.com/ - files and folders comparison tools
|
|
|
|
|
Thanks for your suggestions. I will check them out. Sometimes the boss had a good idea. He would rather us spend our time working on the core program than the "fluff". So he would rather just buy a solution off the shelf rather than waste our time trying to come up with a scheme. He is very time-to-market oriented.
Artificial intelligence is no match for natural
stupidity.
|
|
|
|
|
I want to do stuff like :
dc2->MoveTo(f,w);
dc2->LineTo( f + 20, w);
but not in the OnDraw() function which makes the line show up from the very start.
When a button is pressed I want to draw the line. If I put in the button click function:
CDC dc2;
dc2->MoveTo(f,w);
dc2->LineTo( f + 20, w);
of course it crashes. So how does one do this?
thanks
ns
|
|
|
|
|
|
call Invalidate() or InvalidateRect
|
|
|
|
|
The problem ns has is that dc2 has not been assigned to a device context.
You are right however that after drawing you need to invalidate.
Ant.
|
|
|
|
|
You can get the DC at anytime by calling GetDC(). But unless you want the line to be overdrawn the next time the OnDraw() is called then you should just set a flag when the button is pushed and invalidate the area being drawn to.
if( bFlag )
INTP
|
|
|
|
|
The right way to do this is to maintain a data structure that contains a collection of linked points. The data structure is updated in your button's handler. Your view's OnDraw() handler should paint itself (i.e. draw lines) based on the points in the data structure.
See the MFC "Scribble" demo app to see how this is done.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
Appreciate the help. Many thanks,
ns
|
|
|
|
|
I've been playing with a CString implementation I found here (Thanks, Joe!)[^] and it collides with another header I use. Compiling my app produces the following warning:
Warning C4065: switch statement contains 'default' but no 'case' labels and points to this section (and another like it) in Joe's StdString.h header:
inline void ssasn(std::wstring& sDst, const int nNull)<br />
{<br />
UNUSED(nNull);<br />
ASSERT(nNull==0);<br />
sDst.assign(L"");<br />
}
I've found UNUSED defined in several ways, in a lot of headers. Here's how it looks in ...\VC98\MFC\Include\AFX.h:
#ifdef _DEBUG<br />
#define UNUSED(x)<br />
#else<br />
#define UNUSED(x) x<br />
#endif<br />
#define UNUSED_ALWAYS(x) x
but in a third-party header I need, it gets defined thus:
#ifndef UNUSED<br />
#ifdef _CVI_<br />
#define UNUSED(a)<br />
#else<br />
#define UNUSED(a) switch((int)&a){default:break;} /* bypass bogus warnings on external compilers */<br />
#endif
It's this last definition that seems to be getting used in the compilation and generates the warning.
Any ideas what this is for? Can I remove the offending references to it without some weird side effect?
Thanks in advance for all your help.
'til next we type...
HAVE FUN!! -- Jesse
|
|
|
|
|
It's actually in place to squelch another compiler warning: C4101. A variable was declared, but never used. You can add a #pragma warning(disable:4507) statement if you don't like the C4065 warning.
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
|
|
|
|