|
You are right, register the ActiveX has anything to do with the 'No Safe' message displayed. but if we want to use the Activex we have to register it. Now I'm doing same manually by using Regsvr32 /u D:\MyActivexCtrl.ocx. How can i do so programeticall? And also If I'm trying to register in some system it is giving error LoadLibrary(".ocx") failed - This application has failed to start because
the application configuration is incorrect.
How to fix this?
|
|
|
|
|
I assume you need to implement IPropertyBag2 interface to get rid of activeX warning. I did it long time ago. don;t remember the details as of now.
HTH.
|
|
|
|
|
I'm getting some very strange behavior in an MDI MFC application with tabbed views I'm working on that I can reproduce easily in any new MDI application I make (that uses tabbed views), and I can't seem to fix it. I'm using Visual Studio 2010. I made a sample application to demonstrate my problem. In my CView (in my example called CNewTestView) I override CView::OnActivateView. I can't seem to call DestroyWindow in OnActivateView, but ONLY when the view is activated by switching to it through the Windows 7 Aero Preview thumbnails. ie. When I switch to a non-active view by either clicking a tab or by pressing CTRL+Tab there are no problems at all, but when I hover the mouse over the application icon in the taskbar and then switch views by clicking on the non-active one then the problem shows up. In the application, I create 2 tabs by pressing Ctrl+N.
As an example, I made a member variable of type CEdit called CNewTestView::m_edit, in a new MFC project with tabbed MDI views, and no other code at all added or modified. Here's the code for OnActivateView:
void CNewTestView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
{
if (bActivate)
{
if (m_edit.GetSafeHwnd())
m_edit.DestroyWindow();
m_edit.Create(WS_VISIBLE | WS_BORDER | WS_CHILD, CRect(0,0,100,20), this, 1234);
}
CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
}
I get an assertion in CWnd::DestroyWindow on line 1047 when the HWND of the CEdit is being looked up in the HWND map returned by the call to afxMapHWND. Here's the code in wincore.cpp where the assertion occurs:
if (pWnd != NULL)
{
#ifdef _DEBUG
ASSERT(pMap->LookupPermanent(hWndOrig) == NULL);
#endif
}
Note that for the assertion all I get is a buzz noise to indicate the assertion, but the debugger doesn't actually break at the assertion. If I compile a Release version I still have a problem (basically I can't recreate the window, and so the application doesn't work properly). If instead I slightly delay the call to DestroyWindow, eg. if I destroy the window in CView::OnTimer after setting a timer in OnActivateView or in a message handler after calling PostMessage then there's no problem at all. Unfortunately I can't do this, since in my real application I'm developing there seems to be other calls resulting from OnActivateView that, after a long line of calls, eventually results in a call to CWnd::DestroyWindow, and the application has gotten large enough that it would be very time consuming to implement the PostMessage call to work with no assertions at all. Does anyone know what's going on?
In the example I gave above I did not add anything else at all to the empty application other than what I mentioned in this email.
Martin
|
|
|
|
|
I fixed the PostMessage problem I mentioned. Turned out the problem was with my code, so everything's working well with my call to PostMessage in OnActivateView. Regardless, I'm still curious as to why I can't call DestroyWindow of a child within OnActivateView of the CView. (I forgot to mention that I'm using a document/view architecture)
|
|
|
|
|
I don't have access to MFC, unfortunately, but can you attempt to debug the application and follow the code into m_edit.DestroyWindow()? It might give you some clue as to when things start to go wrong inside DestroyWindow.
I've read something about LookupPermanent going wrong when it is called from the wrong thread. I can't imagine that to be the problem, but it's something you might want to rule out, just to be sure.
|
|
|
|
|
I know Active document server can render a ole file such as office document, but i found AcroPDF also use Active document server technology to load .pdf files in IE.
When I open a pdf file with UltraEdit,see binary data,not seems like a ole file.
why?
and anyone can tell me how can i create a Active document server to render a txt file.
thanks.
|
|
|
|
|
This is the ATL/WTL/STL forum, your question does not seem to have anything to do with any of those subjects. Please try a more appropriate section.
|
|
|
|
|
ATL is a way to create ActiveX docuemnt,i think my subject accordant for ATL forum
|
|
|
|
|
How to Check the iterator is valid?
|
|
|
|
|
|
In general you can't.
Steve
|
|
|
|
|
|
|
I construct a Streambuf with "an array of char". and use the steambuf to construct a ostream/istream:strm.
But the strm cannot do anything with "char array".like << | >> doesn't affect the char array data.
Have I missed something?
|
|
|
|
|
Without source code, it's hard to say.
The streams shouldn't see a char array, but a streambuf. It's up to the streambuf to provide the functionality the stream needs for its internal use.
The streaming operators << and >> work on streams, not streambuf. For instance, when streaming a character out (strm << 'o'; ) the ostream will call streambuf::sputc to add it to the buffer.
modified on Wednesday, September 7, 2011 7:37 AM
|
|
|
|
|
hi,everyone.
When using the Windows FileOpen dialog with multiple selection do you ever wonder how much memory you have to allocate for the buffer. Is one kilobyte going to be enough? Or should you make it ten? How about one Megabyte just to be safe?
It seems that no matter what you choose, you are either going to waste a whole bunch of memory just to be safe, or your user is going to select a bunch of files only to find their selection didn't work because your buffer was too small.
one way is Derive the CFileDialog class , the article as follow introduce it:
Multiple Selection in a File Dialog[]
but I have the other method: use the hook function of CFileDialog. I write some code as follow:
<pre lang="c++">
UINT_PTR CALLBACK MyOFNHookProc( HWND hdlg,
UINT uiMsg,
WPARAM wParam,
LPARAM lParam
)
{
int nResult = FALSE;
if (hdlg == NULL)
return 0;
#ifdef _DEBUG
_AFX_THREAD_STATE* pThreadState = AfxGetThreadState();
if (pThreadState->m_pAlternateWndInit != NULL)
pThreadState->m_pAlternateWndInit = NULL;
#endif
switch(uiMsg)
{
case WM_NOTIFY:
{
LPOFNOTIFY pOfn = (LPOFNOTIFY)lParam;
switch(pOfn->hdr.code)
{
case CDN_SELCHANGE:
{
TCHAR dummy_buffer;
HWND hOwner = GetParent(hdlg);
HWND hParent = GetParent(hOwner);
UINT nfiles = CommDlg_OpenSave_GetSpec(hOwner, &dummy_buffer, 1);
int cbLength = CommDlg_OpenSave_GetSpec(GetParent(hdlg), NULL, 0);
cbLength += _MAX_PATH;
if(cbLength>(pOfn->lpOFN)->nMaxFile)
{
if((pOfn->lpOFN)->lpstrFile)
HeapFree(GetProcessHeap(),
0,
(pOfn->lpOFN)->lpstrFile);
(pOfn->lpOFN)->lpstrFile = (LPTSTR) HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
cbLength);
(pOfn->lpOFN)->nMaxFile = cbLength;
}
nResult = TRUE;
break;
}
default:
break;
}
break;
}
default:
break;
}
return nResult;
}
void CMultiSelectDlg::OnButton1()
{
#define NAMEBUF 1024
TCHAR szFilters[]= _T("MyType Files (*.doc)|*.doc||");
CFileDialog fileDlg(TRUE, _T("doc"), _T("*.doc"),
OFN_FILEMUSTEXIST | OFN_HIDEREADONLY|OFN_ALLOWMULTISELECT, szFilters);
fileDlg.m_ofn.lpstrFile= (LPTSTR) HeapAlloc(GetProcessHeap(),
HEAP_ZERO_MEMORY,
NAMEBUF);
fileDlg.m_ofn.nMaxFile = NAMEBUF;
fileDlg.m_ofn.lpfnHook = (LPOFNHOOKPROC)MyOFNHookProc;
INT_PTR ret = fileDlg.DoModal();
if (ret == IDOK)
{
int width = 0;
CString str;
CDC *pDC = m_listbox.GetDC();
int saved = pDC->SaveDC();
pDC->SelectObject(GetFont());
UINT count = 0;
POSITION pos = fileDlg.GetStartPosition();
while (pos)
{
str = fileDlg.GetNextPathName(pos);
m_listbox.AddString(str);
CSize size(0, 0);
size = pDC->GetTextExtent(str);
width = width > size.cx ? width : size.cx;
++count;
}
pDC->RestoreDC(saved);
ReleaseDC(pDC);
m_listbox.SetHorizontalExtent(width + 5);
str.Format(_T("%u files selected"), count);
m_static.SetWindowText(str);
}
DWORD dwCode = CommDlgExtendedError();
if (FNERR_BUFFERTOOSMALL==dwCode)
{
int i =0;
}
HeapFree(GetProcessHeap(),0,
(fileDlg.m_ofn.lpstrFile));
}
the code Reference the article as follow :
How To Handle FNERR_BUFFERTOOSMALL in Windows[]
but I found when the file names buffer is enough large , it run successly; but when when the file names buffer is not enough large (it means the program will enter if(cbLength>(pOfn->lpOFN)->nMaxFile) ), when after run INT_PTR ret = fileDlg.DoModal(); the value of ret is IDCANCEL. I catch the error code, it is FNERR_BUFFERTOOSMALL . In the end even I allocate a enough large memory ,the error code still is FNERR_BUFFERTOOSMALL . Why???
|
|
|
|
|
From the last link/example you shared, I notice that the Win-KB example sets the pointer pOfn to the parent of the current window:
lpofn = (LPOPENFILENAME) GetProp(GetParent(hwnd), "OFN");
And then continues with it. You should carefully reread the example and adjust your own code accoringly.
|
|
|
|
|
lpofn = (LPOPENFILENAME) GetProp(GetParent(hwnd), "OFN");
this code I have test,it is Invalid. after run this line,the value of lpofn is NULL.
|
|
|
|
|
Hi all.
I have a memory leak on a C++ MFC app I'm trying to solve.
In the problematc part of code there are some function calls as follows:
void functionA()
{
functionX(new ClassConstructor());
}
Since this unmanaged code, is it safe to do that without freeing the memory allocated by the new operator, or it will be released after exiting the functionA scope?
Shouldn't be something like the following a good solution?
void functionA()
{
ClassConstructor *obj = new ClassContructor();
functionX(obj);
delete obj;
}
Thanks in advance 
|
|
|
|
|
The object instantiated by the new needs a matching delete . It's not clear who's responsible for deleting it from what you've told us, but someone needs to. A comment on this code you posted:
sirtimid wrote: void functionA()
{
ClassConstructor *obj = new ClassContructor();
functionX(obj);
delete obj;
}
In this case there's no reason to use the heap. Do something like this instead:
void functionA()
{
ClassConstructor obj;
functionX(&obj);
}
Steve
|
|
|
|
|
Thanks a lot!
I'll try that out 
|
|
|
|
|
Ok guys... i've been working on this section of code for about a week now and i'm giving up...can someone help me?
I've got the basics down, but the code won't compile:
Argument of type LPWSTR* is incompatible with parameter type of LPWSTR
LPWSTR strPath[ MAX_PATH ];
SHGetSpecialFolderPath(
0,
strPath,
CSIDL_APPDATA,
FALSE );
LPWSTR appDataPath = *strPath;
_tcscat(appDataPath, L"\\SSST\Settings.ini");
MessageBox(NULL,(LPCTSTR)appDataPath, NULL, NULL);
|
|
|
|
|
The problem with your code is as follows:
LPWSTR strPath[ MAX_PATH ];
The "LP" in "LPWSTR" stands for Long Pointer. So the above code declares an array of pointers, NOT an array of WCHARs.
You need to declare it as:
WCHAR strPath[ MAX_PATH ];
Also, this code is wrong:
LPWSTR appDataPath = *strPath;
_tcscat(appDataPath, L"\\SSST\Settings.ini");
You haven't allocated any memory for the appDataPath string. So you must make it something like:
LPWSTR appDataPath = new WCHAR[ 400 ]; I chose 400 arbitrarily to make it big enough.
And be sure to deallocate appDataPath when you are done with it by saying:
delete [] appDataPath;
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Great! that works perfect, the only issue is that now the MessageboxA shows a ton of chinese/gibberish characters at the front.. i'm assuming that these are the buffer characters?
i'm new to C++ (in fact this is only my second attempt at C++)... counting "Hello World!"
|
|
|
|
|
I should have mentioned that you should zero out the buffer before using it:
LPWSTR appDataPath = new WCHAR[ 400 ];
ZeroMemory( appDataPath, sizeof( WCHAR ) * 400 );
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|