这段代码在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;
}

解决方案 »

  1.   

    你的用法不对!改成:#include "stdafx.h"
    #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;
    }
      

  2.   

    谢谢!
    但是MSDN的Sample就是这样的。
    在VC2003里是正常的。
    而且,如果我用别的调试器调试Release的exe,结果也是正常的,但是就是直接运行不行。
      

  3.   

    我的刚好相反,去掉第一行后在Release下运行正常,在Debug下出现如下错误:
    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)期待楼下的回复!
      

  4.   

    同意倒之.msdn中对ReadQueryValue最后一个参数的解释是这样的:
    [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.
      

  5.   

    project->setting
    左上角下拉框选择win32 debug
    右边属性而Link->Object/Library modules 的输入框后面追加 Advapi32.lib
      

  6.   

    看来以后看见[in, out]参数就要小心一点了,MSDN有时候也靠不住啊
      

  7.   

    楼上的,你的工程设置里面是不是用了MFC支持啊?选NOT Using MFC就好了
      

  8.   

    程设置里面选NOT Using MFC,把#include "stdafx.h"改为#include "afx.h"在VC6.0下RELEASE测试有数据
      

  9.   

    debug时long dwBufLen;
    dwBufLen初始值为)0xCC,所以可以读出来。而Release时为0。