03-22-2012, 07:07 PM
(03-10-2012, 07:47 AM)gakperlukperluwong Wrote: slam kenal smwx para master,,
sya newbie, pngen buat program sperti berikut,,,
pada saat sya compile source code di atas tidak muncul apa2 mlah kluar pringatan stop working ganti.exe ,,,Code:#include <iostream> #include <cstring> #include <windows.h> #include <cstdlib> using namespace std; HKEY hkey; LONG lresult; void information() { cout << "ganti path" << endl << endl << "Example " << endl << "ganti C:\picture.jpg" << endl; } int main(int argc, char* argv[]) { unsigned int len = strlen(argv[1]); char *szpath = (char *) malloc(len+1); if (szpath != NULL) { strcpy(szpath, argv[1]); } if (argc == 2) { lresult = RegOpenKeyEx(HKEY_CURRENT_USER, "ControlPanel\\Dekstop", 0, KEY_ALL_ACCESS, &hkey); if(lresult == ERROR_SUCCESS) { lresult = RegSetValueEx((HKEY)hkey, "Wallpaper", 0, REG_SZ, (BYTE *) szpath, strlen(argv[1])); if(lresult == ERROR_SUCCESS) { cout << "succes" << endl; } } else { return false; } } else { information(); } RegCloseKey(hkey); system("pause"); return 0; }
tyz pada saat sya debug muncul peringatan An acces violation(segmentation fault) rased in your program
tlong pencerahannya para master,,,
terima kasih,,,
kalau fungsinya untuk mengedit registry, cba aj script berikut, mungkin bsa membantu,,
Code:
#include <iostream>
#include <windows.h>
#include <cstring>
using namespace std;
int main()
{
LONG lresult;
HKEY hkey;
unsigned long len;
char *lpdata = (char *)malloc(len+1);
len = strlen(lpdata);
cout << "Masukkan file JPG ="; cin >> lpdata;
lresult = RegOpenKeyEx(HKEY_CURRENT_USER, "Control Panel\\Desktop", 0, KEY_ALL_ACCESS, &hkey);
if(lresult == ERROR_SUCCESS)
{
cout << "Registry berhasil dibuka" << endl;
if(RegDeleteValue(hkey, "Wallpaper") == ERROR_SUCCESS)
{
cout << "data berhasil di hapus"<< endl;
}
if(RegSetValueEx(hkey, "Wallpaper", 0, REG_SZ, (LPBYTE) lpdata, strlen(lpdata)+1) == ERROR_SUCCESS)
{
cout << "Penamabahan data berhasil" << endl;
}
}
system("pause");
return 0;
}





