|
Not directly. The code is housed within a COM component that contains a doc-view framework. The user clicks a toolbar button that creates an instance of a modeless dialog. When the mouse is moved over the dialog items (ie. OnMouseMove()), the example code is triggered to determine what control the mouse is over. The error is an 005 Access Violation which usually means a bad pointer. I'm not sure why the code works fine in debug. I suspect it has something to do with the individual controls. I used classwizard to define member variables for each control. I get further into the code now, but, it still crashes later on. In release mode, it appears that the GetDlgItem() call has trouble if the control is not tied to an actual member variable.
|
|
|
|
|
Pretty sure you should use "AFX_MANAGE_STATE (AfxGetStaticModuleState ());" at the beginning of the COM call - especially if your using CWnds or resources (or any MFC!) inside a DLL.
|
|
|
|
|
Thanks to Mike Collins, this problem has been solved. Here is the resolution:
My code uses many user message handlers. I typically use the ON_MESSAGE() macro with a function handler. When defining the function handler, I often code a prototype function like the following:
void OnUserHandler();
However, this is incorrect. Eventhough this code will compile (with no warnings!) and work fine in debug, it will fail in release mode. The resolution is to change the function handlers to the following:
afx_msg LRESULT memberFxn(WPARAM, LPARAM);
Hope this helps all who run across this in the future!
|
|
|
|
|
FWIW, the version of MFC included with VS.NET uses the casting operators to detect when signature mismatches like this occur.
Peace!
-=- James.
"Some People Know How To Drive, Others Just Know How To Operate A Car."
(Try Check Favorites Sometime!)
|
|
|
|
|
I have a CString type variable with a large HTML file in it. When I attempt to replace all occurrances of a character with another characer, it works fine, however, if I attempt to replace a string ("= ") with another string ("="), it appears to get stuck in some endless loop somewhere.
I have left it running for hours, and it is still stuck at the same replace statement. Is there something I'm missing?
|
|
|
|
|
Whats your code?
Mazy
"The more I search, the more my need
For you,
The more I bless, the more I bleed
For you."The Outlaw Torn-Metallica
|
|
|
|
|
It's not a very elegant method, but the code is:
void CParser::StandardiseHTML ( CString* HTMLfile )
{
HTMLfile->Replace ("@", "@");
HTMLfile->Replace ('\n', ' ');
HTMLfile->Replace ('\t', ' ');
HTMLfile->Replace (" ", " ");
while ( HTMLfile->Replace (" ", " ") != 0 );
HTMLfile->Replace (" =", "=");
HTMLfile->Replace ("= ", "=");
HTMLfile->MakeUpper ();
}
It manages to get into trouble with the statement
HTMLfile->Replace (" ", " ");
|
|
|
|
|
What??? No, where it says
HTMLfile->Replace (" ", " ");
the first string is actually a non-braking space character - In the while loop, it's meant to have two spaces between the first seyt of inverted commas, and one in the second set.
|
|
|
|
|
Is it possible the first character is actually a space just like the second? That would cause an infinite loop, as each call to replace will find the same character and replace it with itself.
|
|
|
|
|
Hi,
Sometimes, I feel a little bit lost with COM, and QI AddRef Release, smart pointers, long pointers to...., just two case:
Should I Release this pointer or not ?
LPDISPATCH pDisp = Fmt.GetObject();
And in this case ?
BSREPORTCTRLSLib::IBsMetafile *pIBsMeta;
pDisp->QueryInterface(IID_IBsMetafile, (void **) &pIBsMeta);
Thanks, Greetings
Braulio
|
|
|
|
|
[edited - I shouldn't watch FIFA World Cup and answer questions at the same time]
You should use Release when you're done with interface returned from QueryInterface call.
Have no idea about GetObject.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
QI calls AddRef() on your behalf internally, calling it again on the returned pointer means you now have 2 references on the interface pointer and need to call Release() twice...
See: ATLBase.h 5374 (your line numbers may vary ) for an example QI implementation:
ATLINLINE ATLAPI AtlInternalQueryInterface(
void* pThis,
const _ATL_INTMAP_ENTRY* pEntries,
REFIID iid,
void** ppvObject)
{
ATLASSERT(pThis != NULL);
ATLASSERT(pEntries->pFunc == _ATL_SIMPLEMAPENTRY);
if (ppvObject == NULL)
return E_POINTER;
*ppvObject = NULL;
if (InlineIsEqualUnknown(iid))
{
IUnknown* pUnk = (IUnknown*)((int)pThis+pEntries->dw);
pUnk->AddRef();
*ppvObject = pUnk;
return S_OK;
}
...
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
This happens when you watch a game and surf CP. Anyway, Senegal leads 1 after first half
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
|
Braulio Díez wrote:
Should I Release this pointer or not ?
LPDISPATCH pDisp = Fmt.GetObject();
Yes. A function has returned you an interface, it will have called AddRef() before it returned it to you, you now own a reference to the interface and should call Release() when you're done with it.
Braulio Díez wrote:
And in this case ?
BSREPORTCTRLSLib::IBsMetafile *pIBsMeta;
pDisp->QueryInterface(IID_IBsMetafile, (void **) &pIBsMeta);
Again, yes. You've called QI, that results in the interface that is returned to you being AddRef()'d, you now own a reference to the interface and should call Release().
In both cases you have bare interface pointers so you're responsible for managing the reference counts. Generally, if you have bare pointers and a function returns you an interface you need to call Release() when you're done.
Len Holgate
www.jetbyte.com
The right code, right now.
|
|
|
|
|
Every reference to an interface needs to be released...
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
The alcohol is one of the greatest enemys of man, but a man who flee from his enemys is a coward.
|
|
|
|
|
when I click in my editbox,I want all the contents to be
selected,I used these code:
void CCaculatorDlg::OnSetfocusEDITap1()
{
CEdit* ped=(CEdit*)GetDlgItem(IDC_EDIT_ap1);
ped->SetSel(0, -1, FALSE);
}
but it doesnt work, when I click at the editbox, it
just like havent added these code.
what could I do?
|
|
|
|
|
Did you try handling GetFocus instead of SetFocus?
modified 12-Sep-18 21:01pm.
|
|
|
|
|
but there's no message like GetFocus,
(I look it up in class wizard)
|
|
|
|
|
Use EN_SETSEL
-----
// editHWnd is the handle to your edit control
// from and to are the beginning and end of your select range
SendMessage(editHWnd, EM_SETSEL, static_cast<wparam>(from),
static_cast<lparam>(to));
-----
Kuphryn
|
|
|
|
|
There's no EN_SETSEL.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
I meant EM_SETSEL.
Kuphryn
|
|
|
|
|
And what do you think CEdit::SetSel does?
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|
|
There are more than one way to get it working. Using EM_SETSEL is another method. I recommend trying that method to see if get the design where you want it.
Kuphryn
|
|
|
|
|
Just FYI, CEdit::SetSel is a thin wrapper which sends EM_SETSEL. So there's no difference, unless you want to achieve macho-API posture.
Tomasz Sowinski -- http://www.shooltz.com
- It's for protection - Protection from what? Zee Germans?
|
|
|
|