|
(using VS.net 2003 and boundschecker 7.2 )
I have a weird behaviour with bounschecker and my simple statically linked MFC application.
I created a basic MFC application from VS.net wizard; then, I selected in the project settings to "Use MFC in a Static Library".
when running the application I get "allocation conflicts" when closing a the document ( when closing the application ) telling me that in the method void CView::PostNcDestroy() the line that contains delete this; I have a conflict (for example ) :
"Allocation Conflict: Attempting to call CObject::operator delete on 0x027D7CA0; pointer was allocated by _malloc_dbg."
If I use the "Use MFC in a Shared DLL" I have no such allocation conflict.
Do I have to set another project setting somewhere ?
Anyone have an Idea before trying to contact compuware ?
thanks.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
When I have a C++ class, let's call it CCLassX,
I construct one on the heap using
CClassX* pC = new CClassX();
versus
CClassX* pC = new CCLassX;
what is the difference?
|
|
|
|
|
I think this is a ClassX case of the same behaviour.
Maximilien Lincourt
Your Head A Splode - Strong Bad
|
|
|
|
|
Blake Miller wrote:
what is the difference?
None. It's just syntactic sugar.
Good music: In my rosary[^]
|
|
|
|
|
I think, both are same only as both will allocate different memory.
|
|
|
|
|
No, they'll produce the exact same code and will behave exactly the same.
Good music: In my rosary[^]
|
|
|
|
|
Both expressions are equal. You can remove the brackets when the constructor of CClassX does not have any parameters.
Don't try it, just do it!
|
|
|
|
|
i think about one more think anybody evoked in the previous answers :
if the constructor is declared as explicit , the compiler may need you to call explicitely the constructor (for example with new class() )...
if some can confirm/infirm my assertion...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Explicit only says that stuff like this:
void function(const CString& str);
function(_T("A LPCTSTR which is an accepted constructor parameter for CString")); will fail, because you have to be explicit about constructing CString objects (assuming that CString(LPCTSTR) was indeed marked as explicit).
Good music: In my rosary[^]
|
|
|
|
|
Blake Miller wrote:
When I have a C++ class, let's call it CCLassX,
I construct one on the heap using
CClassX* pC = new CClassX();
versus
CClassX* pC = new CCLassX;
the difference is that in second line CCLassX is written with 'L'
and in first line with 'l'
to be more serious ...
I think if we have class , for example :
CClassX
{
int x;
double y;
};
and
1 . CClassX* pC = new CClassX();
2 . CClassX* pC = new CClassX;
then
in first case x and y variables will be initialized and be equal to 0
in second case x and y variables will not be initialized.
is there anything more
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
-- modified at 18:17 Friday 23rd September, 2005
|
|
|
|
|
Giorgi Moniava wrote:
in first case x and y variables will be initialized and be equal to 0
in second case x and y variables will not be initialized.
never...
i think you didn't read the other poster answers (or you have a bad knowledge about implicit compiler actions, but calling new CClassX (without parenthesis) will call the default constructor (wich is more often the one with no parameters).
i say "more often" because consider the following :
class X {
int i;
double d;
public:
X(i = 1; d = 1.) {
}
};
here, we explicitely define only one constructor, but it is the one that will be the default constructor...
calling both new X() or new X will cause the following assertions :
X* p = new X;
p->i == 1
p->d == 1.
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
never...
just try ,
Declare class
CClassX
{
public :
int x;
double y;
};
and then in main construct two objects on the heap
...
CClassX* pC1 = new CClassX();
CClassX* pC2 = new CClassX;
...
and try
cout<<pC1->x<<" "<<pC1->y; //here output will be 0 0
cout<<pC2->x<<" "<<pC2->y; //here output will be random numbers
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
Then that is a compiler specific detail. It's not in the standard! The Visual C++ compiler for instance, initializes all members to seemingly "garbage" values in debug mode. The garbage however, is useful, as it gives the programmer a good hint on what is wrong (uninitialized variables are easily detected). IIRC, the compiler initializes member variables with byte strings containing repeating the pattern 0xcd . Members of deleted objects are given 0xfe .
I wouldn't rely on this behaviour, because it's probably subject to change with any release, and it is not portable.
--
Keep talking! You're the fool, I'm the preacher.
|
|
|
|
|
Ye , maybe it's compiler dependant...
But then do you know exactly the difference between
CClassX* pC = new CClassX();
CClassX* pC = new CClassX;
i don't think that there is no difference at all
"Success is the ability to go from one failure to another with no loss of enthusiasm." - W.Churchill
|
|
|
|
|
Hello
I want to record sound from Sound card to memory(buffer).
That sound is generated by people using microphone.
How can I decide it?
I am not have any Idea now.
If you have any suggestion, help me pls?
Thank you so much for you help.
Thank you
|
|
|
|
|
There are articles about that on CodeProject!
Don't try it, just do it!
|
|
|
|
|
I used the code bellow to Initialize COM. but It always says that Establishes the spatial documents is defeated when the program run.
I used app wizard to create a MDI project Test(vc6).
I only changed the base class of CTestView into CMyView. CMyView is my own definition.It was derived from CListView.
Code in InitInstance:
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);
if (FAILED(hres))
{
CString csErr;
csErr.Format( _T("Failed to initialize COM library. Error code = %d"),hres);
AfxMessageBox(csErr);
return FALSE;
}
hres = CoInitializeSecurity(NULL, -1, NULL, NULL,
RPC_C_AUTHN_LEVEL_CONNECT,
RPC_C_IMP_LEVEL_IDENTIFY,
NULL, EOAC_NONE, 0
);
if(FAILED(hres))
{
AfxMessageBox(_T("CoInitializeSecurity Failed"));
}
and Code in ExitInstance:
CoUninitialize();
for a test,you must define _WIN32_DCOM
Please,give me a help. Thank you very much.
|
|
|
|
|
how to copy a BSTR to char array? :-?
char sz[20];
BSTR *bstr;
[i tried the below code, but didn't work]
strcpy(sz,W2T(bstr));
Err:
D:\PROJ\CTI MFC FW\ATL53\AT53.cpp(16) : error C2065: '_lpw' : undeclared identifier
D:\PROJ\CTI MFC FW\ATL53\AT53.cpp(16) : error C2440: '=' : cannot convert from 'unsigned short ** ' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\PROJ\CTI MFC FW\ATL53\AT53.cpp(16) : error C2065: '_convert' : undeclared identifier
thanks
v
|
|
|
|
|
You need to add
USES_CONVERSION;
somewhere in your source. See MSDN for details.
The opinions expressed in this communication do not necessarily represent those of the author (especially if you find them impolite, discourteous or inflammatory).
|
|
|
|
|
Use
BSTR bstrName=::SysAllocString(L"prasad");
char *charPointer=new char[256];
WideCharToMultiByte(CP_OEMCP, 0, bstrName, -1, charPointer, 256, NULL, NULL );
Alternatively you can use wrapper _bstr_t
_bstr_
|
|
|
|
|
oops! sorry i'm confused a bit.. that removal of * didn't work. .. sorry. i'll try your way now
|
|
|
|
|
I'm using
USES_CONVERSION;
strncpy(sz,OLE2T(bstr), 25);
please note that is not secure to use strcpy, due buffer overflow attacks.
Thats why you should use strncpy
|
|
|
|
|
Hi, I notice many 3D CAD systems have treeviews on top of the 3D view of the drawings(rendered by OpenGL or Direct3D), and I would like to know how it is being done.
I believe the pixels are blitted from the bitmap of the treeview onto the framebuffer of the 3D view, and this is the part I am familar with.
What I don't know is whether the treeview is just the standard treeview in Windows, and how to program it so that the actual treeview is invisible, and how all the mouse clicking stuff works.
Does anyone have any idea?
TIA
|
|
|
|
|
This is a simple code to insert some string at
a given cursor position for CEdit
CPoint point;
::GetCursorPos( &point );
m_ScriptWin.ScreenToClient(&point);
int CharPos = m_ScriptWin.CharFromPos( point );
m_ScriptWin.SetSel(CharPos,CharPos,TRUE);
m_ScriptWin.ReplaceSel(" ***This is the inserted text*** \r\n");
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
this is one more method but havent tested it
POINT point;
::GetCursorPos( &point );
m_Edit.ScreenToClient(&point);
int CharPos = m_Edit.CharFromPos( point );
WORD charind = LOWORD(CharPos);
CString s;
m_Edit.GetWindowText(s);
s = s.Left(charind)+"mystring"+s.Right(s.GetLength()-charind);
m_Edit.SetWindowText(s);
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|