#include "stdafx.h"
#include <windows.h>
#include <iostream>
#include <strsafe.h>
#define IP_ADDRESS_KEY _T("SOFTWARE\\SCANER\\IP_SETUP")
BOOL GetLocalFaxFilePath(LPTSTR lpszPath, int nSize)
{
DWORD dwDisposition;
HKEY hKey;
ZeroMemory(lpszPath, nSize*sizeof(TCHAR));
if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER, IP_ADDRESS_KEY,
0, 0, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition))
{
return FALSE;
}
DWORD dwType;
DWORD dwcbData;
dwcbData = nSize*sizeof(TCHAR);
LSTATUS lStatus = RegQueryValueEx(hKey, _T("IP Address"), NULL, &dwType, (LPBYTE)lpszPath, &dwcbData);
RegCloseKey(hKey);
return (lStatus == ERROR_SUCCESS);
}
BOOL SetLocalFaxFilePath(LPTSTR lpszPath)
{
DWORD dwDisposition;
HKEY hKey;
if (ERROR_SUCCESS != RegCreateKeyEx(HKEY_CURRENT_USER, IP_ADDRESS_KEY,
0, 0, 0, KEY_ALL_ACCESS, NULL, &hKey, &dwDisposition))
{
return FALSE;
}
DWORD dwcbData;
dwcbData = (_tcslen(lpszPath)+1)*sizeof(TCHAR);
if (ERROR_SUCCESS == RegSetValueEx(hKey, _T("IP Address"), 0, REG_SZ, (LPBYTE)lpszPath, dwcbData))
{
}
RegCloseKey(hKey);
return TRUE;
}
int __cdecl wmain(int argc, LPWSTR *argv)
{
#if 0
SetLocalFaxFilePath(TEXT("192.168.0.124"));
#else
LPTSTR pIp = new WCHAR[20];
ZeroMemory(pIp, 20);
GetLocalFaxFilePath(pIp, 20);
#endif
return 1;
}
注册表 读写练习
最新推荐文章于 2019-08-22 21:05:23 发布