|
I add some error checking.. it seems having no problem..
#include<windows.h>
int main(void)
{
HKEY hKey;
char szFile[] = "D:\\prog.exe";
RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", &hKey);
RegSetValueEx(hKey, "regkey", 0, REG_SZ, szFile, strlen(szFile));
RegCloseKey(hKey);
return 0;
}
with these codes, I try to add my program in registry, I used these codes in my program's codes, but it does not work..
can you try to use these codes please..
|
|
|
|
|
mgbrain wrote: I add some error checking
Really? Can't see it - try this:
#include <Windows.h>
#include <stdio.h>
int main(void)
{
HKEY hKey;
char szFile[] = "D:\\prog.exe";
LONG status = RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", &hKey);
if (ERROR_SUCCESS==status)
{
status = RegSetValueEx(hKey, "regkey", 0, REG_SZ, szFile, strlen(szFile));
if (ERROR_SUCCESS!=status)
else
{
fprintf(stderr, "RegSetValueEx failed - %d\n", (int)status);
}
RegCloseKey(hKey);
}
else
{
fprintf(stderr, "RegOpenKey failed - %d\n", (int)status);
}
return 0;
}
mgbrain wrote: can you try to use these codes please
Sorry, no - I don't have or use Windows except at work (and I'm at home currently).
|
|
|
|
|
It didn't work.. there is no error message..
|
|
|
|
|
|
I'm sorry but how can I use process monitor
|
|
|
|
|
Download it and run it? Look in the help file if you can't work it out?
|
|
|
|
|
thank you very much for your helping
|
|
|
|
|
Stuart Dootson wrote: Try using Process Monitor[^] to see exactly what your program's writing to the registry.
Regmon might be a tad simpler for the OP at this stage.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
Except that I'm not sure regmon is available to download any more - I think it and filemon were superseded by ProcMon. I agree, though - I'd rather use RegMon or FileMon
[edit]I'm wrong - you can download it[^] - but that's a version that's over 2 years old Is it compatible with Vista?[/edit]
|
|
|
|
|
What part of "your program does not have sufficient privileges" are you not getting? Your code might have worked on Windows XP and earlier, but Vista now prohibits you from accessing places in the registry and in the file system by default. You must elevate those privileges if you want this code to work with Vista.
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"The brick walls are there for a reason...to stop the people who don't want it badly enough." - Randy Pausch
|
|
|
|
|
do you wanna explain what you mean, please?
|
|
|
|
|
Hi all,
I am working on a plugin that takes coordinates and sends them via socket to a receiving application. To do this, I need to package the coordinates. To make life on the receiving end easier, I want to package them as a string and send as a const char*. However, I cannot get the latitude string and the longitude string to concatenate, it just throws linker errors... any ideas what the problem is? Here is the code snippit in question:
std::stringstream sSLat;
std::stringstream sSLon;
std::string strLat;
std::string strLon;
std::string coordPack;
//package data to string
const char* sendCoords;
sSLat << lat ;
sSLon << lon;
strLat = sSLat.str();
strLon = sSLon.str();
coordPack = strLat + strLon; <---- this line seems to be causing the errors, when I comment out, it builds
sendCoords = coordPack.c_str();
Here are the errors I am getting:
1>------ Build started: Project: 2DMapPlugin, Configuration: Release Win32 ------
1>Linking...
1>2DMapPlugin.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: char * __thiscall stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >::_M_append_fast_pos(struct stlp_std::priv::__bstr_wrapper<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >,char *,unsigned int,unsigned int)" (__imp_?_M_append_fast_pos@?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@AAEPADU?$__bstr_wrapper@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@priv@2@PADII@Z)
1>2DMapPlugin.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: char * __thiscall stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >::_M_append_fast(struct stlp_std::priv::__bstr_wrapper<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >,char *)" (__imp_?_M_append_fast@?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@AAEPADU?$__bstr_wrapper@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@priv@2@PAD@Z)
1>2DMapPlugin.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: char * __thiscall stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >::_M_append_fast_pos(struct stlp_std::priv::__sum_storage_elem<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,char *,unsigned int,unsigned int)" (__imp_?_M_append_fast_pos@?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@AAEPADABU?$__sum_storage_elem@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@priv@2@PADII@Z)
1>2DMapPlugin.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: char * __thiscall stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >::_M_append_fast(struct stlp_std::priv::__sum_storage_elem<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> > const &,char *)" (__imp_?_M_append_fast@?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@AAEPADABU?$__sum_storage_elem@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@priv@2@PAD@Z)
1>2DMapPlugin.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) private: unsigned int __thiscall stlp_std::basic_string<char,class stlp_std::char_traits<char>,class stlp_std::allocator<char> >::_M_get_additional_size(unsigned int,struct stlp_std::__true_type const &)const " (__imp_?_M_get_additional_size@?$basic_string@DV?$char_traits@D@stlp_std@@V?$allocator@D@2@@stlp_std@@ABEIIABU__true_type@2@@Z)
1>C:\Documents and Settings\lundg\My Documents\Visual Studio 2005\Projects\2DMapPlugin\Release\2DMapPlugin.dll : fatal error LNK1120: 5 unresolved externals
1>Build log was saved at "file://c:\Documents and Settings\lundg\My Documents\Visual Studio 2005\Projects\2DMapPlugin\2DMapPlugin\Release\BuildLog.htm"
1>2DMapPlugin - 6 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Any help you can give will be appreciated!
Thanks!
modified on Thursday, February 5, 2009 1:27 PM
|
|
|
|
|
What if you do instead of this:
coordPack = strLat + strLon;
this:
coordPack = strLat;
coordPack += strLon;
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Life: great graphics, but the gameplay sux. <
|
|
|
|
|
That's a linker error - for some reason, your build is not pulling in the C++ run-time library by the look of it.
Looking at the namespace in the linker errors - "stlp_std " - are you using STLPort rather than Microsoft's STL implementation? If so, you need to link in the STLPort import libraries before the Microsoft ones.
|
|
|
|
|
Thanks for the help guys! I was using std instead of stlp_std, so I made the adjustment, and now it compiles fine!
I appreciate it!
|
|
|
|
|
Hi,
I can not find out how to read what is in a VARIANT, which is the result of calling a method GetAllProperties. The doc of this method only specifies that a VARIANT is returned. It should contain some kind of strings. I tried this :
VARIANT names;
_variant_t v1;
VARTYPE vtype;
long ix;
...
x->GetAllProperties(&names);
if (V_ISARRAY(&names)) {
SafeArrayGetVartype(names.parray,&vtype);
// this returns 0x0800 in vtype, so I assume it is an array of _variant_t !!!
for (ix=0;ix<nprops;ix++) {
SafeArrayGetElement(names.parray,&ix,&v1);
_bstr_t s1(v1);
printf("name=%s\n",(char *)s1);
}
}
But this ends in an exception during the statement "_bstr_t s1(v1);"
What do I do wrong ???
Linde Ackermans
|
|
|
|
|
You're assuming v1 is a string. It maybe something else (you have to check the VARIANT 's vt field). Moreover, why don't you check the SafeArrayGetElement return value?
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]
|
|
|
|
|
I did what you suggest :
the return value of SafeArrayGetElement is S_OK
v1.vt = 0x95d4
I have seen a VB example using this GetAllProperties method, and there they simply access it with names(i), and treat it as a string ( it stands for a Property Name )
How can I translate this into C++ ?
|
|
|
|
|
LindeA wrote: _bstr_t s1(v1);
In addition to checks suggested by CPallini , I suggest to you to read VARIANT's doucmentation.
If it really contains strings, it can be used as v1.bstr .
|
|
|
|
|
hi guys,
i been writing a program that connect to a remote database in speedhosting.co.cc .But i been having problem to connect its showing error when i run it...
Error message :
An unhandled exception of type 'MySql.Data.MySqlClient.MySqlException' occurred in MySql.Data.dll
Additional information: Unable to connect to any of the specified MySQL hosts.
below is my coding :-
#pragma once
namespace trialcpp {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace MySql::Data::MySqlClient;
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
}
protected:
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ cmdLogin;
private: System::Windows::Forms::Button^ cmdExit;
protected:
private:
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
this->cmdLogin = (gcnew System::Windows::Forms::Button());
this->cmdExit = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
this->cmdLogin->Location = System::Drawing::Point(52, 190);
this->cmdLogin->Name = L"cmdLogin";
this->cmdLogin->Size = System::Drawing::Size(75, 23);
this->cmdLogin->TabIndex = 0;
this->cmdLogin->Text = L"Login";
this->cmdLogin->UseVisualStyleBackColor = true;
this->cmdLogin->Click += gcnew System::EventHandler(this, &Form1::cmdLogin_Click);
this->cmdExit->Location = System::Drawing::Point(175, 190);
this->cmdExit->Name = L"cmdExit";
this->cmdExit->Size = System::Drawing::Size(75, 23);
this->cmdExit->TabIndex = 1;
this->cmdExit->Text = L"Exit";
this->cmdExit->UseVisualStyleBackColor = true;
this->cmdExit->Click += gcnew System::EventHandler(this, &Form1::Exit_Click);
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(326, 266);
this->Controls->Add(this->cmdExit);
this->Controls->Add(this->cmdLogin);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
}
private: System::Void Exit_Click(System::Object^ sender, System::EventArgs^ e) {
this->Close();
}
private: System::Void cmdLogin_Click(System::Object^ sender, System::EventArgs^ e) {
MySqlConnection ^conDatabase = gcnew MySqlConnection("DataSource = 'sql304.xxxx.xxx'; User Name='username'; Password='password'; database='database_name'");
conDatabase->Open();
System::Windows::Forms::MessageBox::Show("Connection Successful");
conDatabase->Close();
}
};
Kindly help me guys plz.. thanks a lot.
Regards,
Thilek
|
|
|
|
|
It's obviously escaped your notice that this isn't the C++/CLI forum[^] - I'd ask your question there...
|
|
|
|
|
i am new to this forum so i not sure the different between C++/MFC and C++/CLI..
Kindly explain to me plz...
|
|
|
|
|
C++/CLI = C++ for .NET
C++/MFC = C++ without using .NET
|
|
|
|
|
|
Hi everybody,
can anyone help me ?
i'm developing a MFC Dialog based app which can <u>simulate 'Windows Desktop' upto limited functionalities</u>,
using Shell API, IContexMenu etc.
While Renaming a file or folder onto desktop, all i could do is; just rename Virtual folders.
When attempting to rename normal files, folders, or link onto desktop, it renames '<b>My Computer</b>' only.
Rename operation executing into 'LVN_ENDLABELEDIT' with appropriate handler
My code snap-shot are:
<pre></pre>
void CClinckDlg::OnRenameLabelEnd(NMHDR *pNMHDR, LRESULT *pResult)
{
NMLVDISPINFO *pDispInfo = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);
LPCWSTR pwStrNewItem = T2CW(pDispInfo->item.pszText);
LPITEMIDLIST pidlNewItem = NULL;
IShellFolder *pshFolder ;
HRESULT hr = NULL ;
SHGetDesktopFolder( &pshFolder ) ;
DWORD dwAttrFlag = SFGAO_CANRENAME;
// m_pidlOldItem was stored as current PIDL, while Right-click onto ClistCtrl item
hr = pshFolder->GetAttributesOf( 1, (LPCITEMIDLIST*)&m_pidlOldItem, &dwAttrFlag ) ;
if( ( dwAttrFlag & SFGAO_CANRENAME ) == 0 )
{
::MessageBox(NULL,
_T("IShellFolder::GetAttributesOf failed, File/Folder can not 'Rename'"),_T("Error"),MB_OK);
return ;
}
hr = pshFolder->SetNameOf(NULL, m_pidlOldItem, pwstr, /*0*/ SHGDN_FOREDITING, &pidlNewItem);
if( FAILED(hr) || (pidlNewItem==NULL) )
{
::MessageBox(NULL,
_T("IShellFolder::SetNameOf failed"),_T("Error"),MB_OK);
return ;
}
// Notify, that item has been renamed successfully
SHChangeNotify( SHCNE_RENAMEFOLDER, SHCNF_IDLIST | SHCNF_FLUSH, m_pidlOldItem, pidlNewItem ) ;
// Set the new PIDL structure
......... .........
..
pshFolder->Release() ;
}
<pre></pre>
Properties of my CListCtrl are,
View = Icon
Edit Labels = True
Thanks a lot in Advance !!
ab4rum
|
|
|
|
|