这段代码在DEBUG下结果正常,在RELEASE下没结果?#include "stdafx.h"
#include "stdio.h"
#include "windows.h"int main(int argc, char* argv[])
{
HKEY hKey;
char szProductType[80] = {0};
long dwBufLen;
RegOpenKeyEx( HKEY_CLASSES_ROOT,"CLSID\\{000C101C-0000-0000-C000-000000000046}\\ProgId",0, KEY_QUERY_VALUE, &hKey );
RegQueryValue(hKey , NULL , szProductType , &dwBufLen);
RegCloseKey(hKey); printf(szProductType);
printf("\n");
return 0;
}
#include "stdio.h"
#include "windows.h"int main(int argc, char* argv[])
{
HKEY hKey;
char szProductType[80] = {0};
long dwBufLen;
RegOpenKeyEx( HKEY_CLASSES_ROOT,"CLSID\\{000C101C-0000-0000-C000-000000000046}\\ProgId",0, KEY_QUERY_VALUE, &hKey );
RegQueryValue(hKey , NULL , szProductType , &dwBufLen);
RegCloseKey(hKey); printf(szProductType);
printf("\n");
return 0;
}
#include "stdio.h"
#include "windows.h"int main(int argc, char* argv[])
{
HKEY hKey;
char szProductType[80] = {0};
long dwBufLen = 80;
RegOpenKeyEx( HKEY_CLASSES_ROOT,"CLSID\\{000C101C-0000-0000-C000-000000000046}\\ProgId",0, KEY_QUERY_VALUE, &hKey );
RegQueryValue(hKey , NULL , szProductType , &dwBufLen);
RegCloseKey(hKey); printf(szProductType);
printf("\n");
return 0;
}
但是MSDN的Sample就是这样的。
在VC2003里是正常的。
而且,如果我用别的调试器调试Release的exe,结果也是正常的,但是就是直接运行不行。
Linking...
MyC.obj : error LNK2001: unresolved external symbol __imp__RegCloseKey@4
MyC.obj : error LNK2001: unresolved external symbol __imp__RegQueryValueA@16
MyC.obj : error LNK2001: unresolved external symbol __imp__RegOpenKeyExA@20
Debug/MyC.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.MyC.exe - 4 error(s), 0 warning(s)期待楼下的回复!
[in, out] Pointer to a variable that specifies the size of the buffer pointed to by the lpValue parameter, in bytes. When the function returns, this variable contains the size of the data copied to lpValue, including any terminating null characters.
左上角下拉框选择win32 debug
右边属性而Link->Object/Library modules 的输入框后面追加 Advapi32.lib
dwBufLen初始值为)0xCC,所以可以读出来。而Release时为0。