|
if you memset all A member to '\0', you gonna delete the A class virtual table, ,but that wont crash. it will crash only when a virtualized function gets called, because the adresse of the mapping table can't be reached (trying to access NULL address)...
|
|
|
|
|
In your example both memcpy and memset would be fine.
You have no virtual methods (so no vtable), nor have you specified A/S as having any other complex data types.
If A/S has even 1 virtual method then, as mentioned, memset will hose the vtable.
Likewise if A/S contains any pointers to other A/S objects then memcpy will likely screw them up.
You can likely get around the memset problem by following it with a placement new call.
e.g.
memset(&struc1, 0, sizeof(S));
new(&struc1) S;
...cmk
Save the whales - collect the whole set
|
|
|
|
|
Since you are already using C++, there is no need to initialize nor copy your structure in the way you describe. struct in C++ is no different from class with the exception that its default protection is set to public . Knowing that, you should write your code as follows:
class A
{
public:
A();
A(const A& a);
A& operator= (const A& a);
void foo1();
private:
};
struct S
{
S();
S(const S& s);
S& operator= (const S& s);
A member1;
};
void main()
{
S s1;
S s2 = s1;
}
If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week
Zac
|
|
|
|
|
....for all the replies!
----------------------------------------------
If you need a hammer get C and shut up. If you need a nail gun get C++ and shut up. If you don't need *those* things (and good design should tell you) then by all means get a factory, factory, factory.
--code-frog@codeproject
----------------------------------------------
Why would you need to date, when C++ is your soul mate?!
--Steve Echols@codeproject
----------------------------------------------
|
|
|
|
|
I have a Visual C++ 2005 MFC dialog application that minimizes to a task tray icon on clicking "X". I'd like to be able to change the tooltip message which you see when you hover over the icon dynamically whenever a certain value changes, in my case, temp of a cardbus device.
Right now it just displays the applications name because that's what I entered when i created the icon using this call:
TrayIcon->Create(0, nTrayNotificationMsg_, L"App Name",
m_hIcon, IDR_SYSTRAY_MENU);
Thanks for any help or links.
|
|
|
|
|
I'm sure exactly how this is done in MFC, or if you have used some VC2005 wizard for the minimize to tray feature. But when we minimize an app to the tray we need to create a NOTIFYICONDATA which contains all the info (icon, tooltip etc) then we use the Shell_NotifyIcon() function to add it to the tray. In your case you want to uppdate the tray icon, so you should use the Shell_NotifyIcon() function with the NIM_MODIFY flag.
|
|
|
|
|
waldermort wrote: I'm sure exactly how this is done in MFC,
AFAIK, there is no class associated with same in MFC!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Well that surprised me, there seems to be a class for everything else
|
|
|
|
|
After reading the article:
Enumerating processes : A practical approach By Irfan Dawood.
I found this really helpfull with what I have to do.
However, I only have the name of the application (hello.exe). The processInfo=new PROCESSENTRY32; has a member variable: szExeFile which is a:
"Pointer to a null-terminated string that specifies the name of the executable file for the process. "
I figure after getting all the processes if I just search for my process using the name I can obtain the process ID of the "hello.exe" process therefore then be able to set the priority:
HANDLE hProcess=OpenProcess(PROCESS_ALL_ACCESS,TRUE,processID);<br />
if(hProcess==NULL)<br />
{<br />
cout<<"Unable to get handle of process: "<<processID;<br />
cout<<"Error is: "<<GetLastError();<br />
return 1;<br />
}<br />
<br />
cout<<endl<<"Priority Class: "<<GetPriorityClass(hProcess);<br />
SetPriorityClass(hProcess,HIGH_PRIORITY_CLASS);<br />
CloseHandle(hProcess);
but whenever I try to do: if( processInfo->szExeFile == _T("hello.exe")) it doesn't work. and when I try to print out cout<<endl<<"Name: "<<processInfo->szExeFile; I get "Name: 0036630C"...
Am I completely off my rocker?
Thanks,
-- modified at 11:36 Thursday 24th August, 2006
-- modified at 11:44 Thursday 24th August, 2006
Kitty5
|
|
|
|
|
kitty5 wrote: but whenever I try to do: if( processInfo->szExeFile == _T("hello.exe")) it doesn't work. and when I try to print out cout<<endl<<"name: "<<processinfo-="">szExeFile; I get "Name: 0036630C"...
processInfo->szExeFile is a pointer. When you try comparing it or print it you are really testing the address. You should de-reference it first ie
if( *processInfo->szExeFile == _T("hello.exe"))
cout<<endl<<"Name: "<<*processInfo->szExeFile;
|
|
|
|
|
Hi I would like to make a program that ginen a wave file it filter (bandpass or low and Hi) and play the sample. It's possible? How?
I'm trying to: make FFT -> cut the frequency -> make a IFFT -> then play.
For FFT and IFFT for example I can use this code:
http://www.codeproject.com/cpp/howtofft.asp[^]
But the I load a wave the samples for second it's non a multiple of 2 and no FFT is possible. How can I do?
|
|
|
|
|
ilFrate wrote: But the I load a wave the samples for second it's non a multiple of 2 and no FFT is possible. How can I do?
I think you add/remove some samples to the data set to make it a 2^n one. I don't remember the details though.
Best,
Jun
|
|
|
|
|
Yes, but how resample without distort the wave or without lose too much quality?
|
|
|
|
|
I get LNK2005 errors with the static CRuntimeClass datamember of the specialized template
Why?
I simplified the classes to highlight the problem.
TXBase contains special algorithms and also the CRuntimeClass functions and static classTXBase to make RUNTIME_CLASS things work.
////////////////////////////////////////////////////////////
// TXView template
////////////////////////////////////////////////////////////
#undef CLASS_NAME
#define CLASS_NAME classTXView_##BASE
template < class BASE >
class TXView : public TXBase < BASE >
{
public:
TXView(UINT nIDTemplate = 0);
virtual CRuntimeClass* GetRuntimeClass();
static const CRuntimeClass CLASS_NAME;
};
template < class BASE > TXView< BASE >::TXView(UINT nIDTemplate /*= 0*/)
: TXBase< BASE >::TXBase(nIDTemplate)
{
}
template < class BASE > const CRuntimeClass TXView<base />::CLASS_NAME =
{
"TXView", sizeof(class TXView<base />), 0xFFFF, TXView<base />::CreateObject,
TXView<base />::_GetBaseClass, 0
};
template < class BASE > CRuntimeClass* TXView<base />::GetRuntimeClass()
{
return (CRuntimeClass*)&TXView<base />::CLASS_NAME;
}
/////////////////////////////////////////////////////////////////
// Specialized template for FormView
/////////////////////////////////////////////////////////////////
#undef CLASS_NAME
#define CLASS_NAME classTXView_##CFormView
template <>
class TXView < CFormView > : public TXBase < CFormView >
{
public:
inline TXView(UINT nIDTemplate = 0);
inline virtual CRuntimeClass* GetRuntimeClass();
static const CRuntimeClass CLASS_NAME;
};
template <> inline TXView< CFormView >::TXView(UINT nIDTemplate /*= 0*/)
: TXBase< CFormView >(nIDTemplate)
{
}
template <> const CRuntimeClass TXView<cformview>::CLASS_NAME =
{
"TXView", sizeof(TXView<cformview>), 0xFFFF, TXView<cformview>::CreateObject, &TXView<cformview>::_GetBaseClass, 0
};
template <> inline CRuntimeClass* TXView<cformview>::GetRuntimeClass()
{
return (CRuntimeClass*)&TXView<cformview>::CLASS_NAME;
}
Thanks if you can help!
|
|
|
|
|
Hello
I´m inserting a bitmap image in my dialog with a picture control, and i want it
to be transparent like when you insert an icon in a dialog, and you set the background
colour to some kind of green at visual studio icon editor and it do the trick.
So, what background color should I use with bitmaps?
btw I´m using Visual Studio 2003 IDE.
thank´s.
-- modified at 8:53 Thursday 24th August, 2006
|
|
|
|
|
This is a little work:
http://www.codeproject.com/staticctrl/LayeredBitmapCtrl1.asp
or look yourself for "transparent"
Greetings from Germany
|
|
|
|
|
There ia a GDI function called TransparentBlt() , but it is not very good. The best approach is to use two bitmaps. The first should be black in all areas you want transparent and white in all other areas. The secon, your picture, should be white in all areas you want transparent. You draw these two over the top of each other. The fist bitmap using BitBlt() with SRCAND , the second using BitBlt with SRCPAINT . The result is a transparent bitmap.
|
|
|
|
|
Actually, the easiest possible way of doing this is probably by just using an ImageList to draw your bitmap, specifying a mask color.
|
|
|
|
|
ok thanks all, i will try all the methods, and read the site as well..
thx..
|
|
|
|
|
Hi,
I am making a custom crash handler for application, and just thought about something.
I am using sprintf, strcat and strlen in handler, are they safe to use even after possible heap corruption?
|
|
|
|
|
chilituna wrote: I am using sprintf, strcat and strlen in handler, are they safe to use even after possible heap corruption?
That would depend on if they were operating on heap variables or not.
"Money talks. When my money starts to talk, I get a bill to shut it up." - Frank
"Judge not by the eye but by the heart." - Native American Proverb
|
|
|
|
|
In general, after the heap has been corrupted all bets are off.
Steve
|
|
|
|
|
chilituna wrote: am using sprintf, strcat and strlen in handler, are they safe to use even after possible heap corruption?
better not try that! you will in great trouble!
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
VC Forum Q&A :- I/ IV
Support CRY- Child Relief and You
|
|
|
|
|
Hi, thanks for answers..
Went throught source code of those (sprintf, strcat, strcpy and strlen) and it seems sprintf is unsafe, since it uses malloc, but strcat,strcpy and strlen are so simple and straightforward and they don't use heap so they are probably? ok..
Well, have to replace sprintf with strcpy,strcat,strlen combination..
|
|
|
|
|
i intialised buttons with color and icon on that button in OnIntilaUpdate()
function.
at first running the application the icons and colors are shown. I changed that view with some other view. Now i r eplace the olde view but the icons and colors are not shown . Now what to do show always icon and color
Can u explain PLZ?
|
|
|
|