|
CRegKey regkey;
TCHAR modbuffer[MAX_PATH];
DWORD dwModPathLen = ::GetModuleFileName(NULL, modbuffer, _countof(modbuffer));
if (dwModPathLen == 0 || dwModPathLen == _countof(modbuffer))
return;
CString strCanonFileName = modbuffer;
strCanonFileName.Replace(_T("%"), _T("%%"));
CString regbuffer;
regbuffer.Format(_T("\"%s\""), strCanonFileName);
CString csKeyName = _T("MyProgram");
HKEY hkeyCR = HKEY_LOCAL_MACHINE;
if (bAutoRun)
{
if (regkey.Open(hkeyCR, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"),
KEY_ALL_ACCESS) != ERROR_SUCCESS)
{
regkey.SetStringValue(csKeyName, regbuffer);
regkey.Close();
}
}
else
{
if (regkey.Open(hkeyCR, _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run"), KEY_READ) != ERROR_SUCCESS)
{
regkey.RecurseDeleteKey(csKeyName);
regkey.Close();
}
}
}
The Exception is m_Key is NULL. My system is windows 7. Is it the Priviledge problem?
modified on Tuesday, January 25, 2011 8:54 PM
|
|
|
|
|
Check what Open returns, it should explain the problem.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
>Nothing is free in the universe.<
|
|
|
|
|
yu-jian wrote: The Exception is m_Key is NULL.
There isn't an 'm_key ' in posted code.
yu-jian wrote: s it the Priviledge problem?
Probably. However, Checking API calls return values would help.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
yu-jian wrote: Is it the Priviledge problem?
If you run the program as admin and it works, then the answer is Yes.
|
|
|
|
|
yu-jian wrote: Is it the Priviledge problem?
No it's the coding problem. In both of your Open() statements you are checking if the return code is not equal to ERROR_SUCCESS , and proceeding if it is not. These tests should be reversed so you only proceed if the return is equal to ERROR_SUCCESS . Also you should capture the returned value as it will help you to diagnose what has gone wrong.
I must get a clever new signature for 2011.
|
|
|
|
|
OK. The return value was 5.
Now this problem resolved. Under win7 it needs Administrator priviledge to run. Under the xp, It can operate register directly.
|
|
|
|
|
|
what is a bitwise copy in c++ done by default constructor and what is shadow copy and deep copy ?
|
|
|
|
|
Please, Let Me Google That For You[^].
BTW It is 'shallow' copy.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Bitwise copy (AKA shallow copy) copies the bits of the struct/class, including arrays. So the destruction of either may cause problems if they are not destroyed together.
A deep copy contains its own definition of all data including array to avoid this negative consequence.
|
|
|
|
|
aesthetic.crazy wrote: what is a bitwise copy in c++ done by default constructor
You mean by a compiler-generated copy constructor? It is not a bitwise copy of the object. It copies each member by invoking its copy constructor.
|
|
|
|
|
If your class/struct contains pointers (i.e. dynamically allocated data) a shallow/bitwise copy will copy the value of the pointer so that both classes point to the same data object.
While this is great for performance issues, it means that if 1 class modifies or deletes the data, the data will be changed or invalidated in the other copy of the class (as per T2102's answer).
A deep copy on the other hand will allocate a new chunk of memory and copy the contents from the memory pointed to by pointers so that the copy will have its own copy of the dynamic data to modify and delete.
Just to clarify on the use of a deep copy, you must provide the copy constructor yourself like
class MyClass : public BaseClass {
MyClass(const MyClass &objOther) : BaseClass(objOther) {
}
};
Note the parameter const MyClass &objOther , you must pass the other class in as a reference (preferable) or a pointer, otherwise the copy constructor would need to be called in order to call the copy constructor resulting in infinite recursion.
If the class has a base class, you also need to call its copy constructor in order to give it a chance to copy any memory that it may have dynamically allocated. Even if you know it doesn't this is still good style and will save you hassles if you add it in later on.
If your class has a statically allocated array by use of the square brackets [] in the class definition, and no dynamic pointers that need explicit copying, then you don't need a copy constructor, as the syntax char szMyString[20]; will allocate 20x char inside the class, so a bitwise copy will copy that.
If you provide a copy constructor, only what you explicitly copy will be copied, that is an int variable will not be copied unless you tell it to. Anything not copied should be initialised, usually by means of an initialiser list. The bitwise copy will only be provided if you don't provide a copy constructor.
If you don't want a class to be copied, simply declare its copy constructor under a private tag, then just provide no code for the function body (although you still need the code MyClass::MyClass(const MyClass &objOther) { } ) so that the function is defined.
|
|
|
|
|
Hi,
My application is MDI application.But im making one window as SDI.In that window i want Menu,Customized toolbar(DialogBar).
What i did.
in app class
pAlarmViewTemplate = new CSingleDocTemplate(
IDR_ALARMMENU,
RUNTIME_CLASS(CFoxboroDoc),
RUNTIME_CLASS(CFrameWnd),
RUNTIME_CLASS(CAlarmView));
AddDocTemplate(pAlarmViewTemplate);
For loading DialogBar in Oncreate function
// Create the Alarm view dialog bar
if( !m_wndAlarmDlg.Create(this, IDD_ALARM_DIALOGBAR, CBRS_BOTTOM |CBRS_FLYBY|CBRS_SIZE_DYNAMIC, IDD_ALARM_DIALOGBAR))
{
TRACE0("Failed to create the Alarm\n");
return -1;
}
where m_wndAlarmDlg is a dialogbar class object.
But when executing ,it doesnot show dialog bar.when i check this variable in Create function,it shows
this = 0x0624ca70 {CAlarmView hWnd=0x00000000}
I dont know how to do that.
--------------------------------------
I choose this only one SDI window in MDI window for getting customized menu for AlarmView .But i dont know how to get customized menu in childwindow of MDI.If i get this one,then i dont want to go for SDI.
Anu
|
|
|
|
|
i am trying to delete Cookies and History directories programmatically but not Possible because of index.dat file... How do i come out from this problem..?
|
|
|
|
|
|
This solution only works for your personal desktop... I run CCleaner from the command line (scheduled task on shutdown) to delete histories, etc.
|
|
|
|
|
Not able to debug my project it is shown as 'The breakpoint will not currently be hit.No symbols have been loaded for this document.'The break point is shown as an error symbol.Along with it showing another project's function name.I am using VC2005.How to solve this?
|
|
|
|
|
1) Are you sure the location where you are placing a breakpoint is in the relevant project and not a dll that it depends on?
2) Have you compiled your add-in(s) recently and made sure the latest version in your path match the versions that you just compiled.
3) Do you have debug information enabled?
|
|
|
|
|
|
I understand that the breakpoints are set; this is a common problem most often due to #1 - 3 I mentioned before.
Does your program rely on any dlls? Is it an exe or dll supporting excel for instance?
|
|
|
|
|
|
My guess is that you need to recompile your dlls that you are using.
|
|
|
|
|
A bit hard to say without seeing the code.
If none of the previous suggestions helped:
Have you checked that the code you want to look at is in fact not dead - as in, the control flow can actually reach it? Maybe the code is inaccessible. Or you tried to set the breakpoint in a function that is no longer used, or has been replaced by another function.
Check your code for locations that call the function you're interested in and try setting your breakpoint there. If that works, step into the function call from there. If not then maybe repeat to get to the next higher level in the call hierarchy.
On a sidenote, what language is it? In C/C++, setting a breakpoint within makro definitions might not work at all, since to the compiler this is technically just plain text. Also breakpoints in templated functions can occasionally be tricky, although I haven't encountered any problems for a long time.
|
|
|
|
|
|
Jia100 wrote: rebuild the project & also deleted .obj files
I am assuming you first deleted the obj files and then rebuilt the project, not the other way round? Just trying to make sure, because if the object files no longer exist, the application will still run, but the debugger might not be able to recognize how the binary executable is linked to the source code! Which would explain what the debugger meant by 'No symbols have been loaded for this document.'...
Not sure what else to suggest, other than checking the messages being sent to output during startup: look if there are similar messages denoting symbol files that are not being loaded, and for which modules.
One more idea: is the function you want to debug being called externally? If so, have you checked whether it's properly declared as external?
|
|
|
|