Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > Visual C++
|
Visual C++ Questions specific to Microsoft's Visual C++. For questions not specific to this Microsoft version, use the C++ Programming forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual C++ section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 25th, 2009, 11:29 PM
Registered User
 
Join Date: Jan 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Visual Studio C++ 2008 Express using RegQueryValueEx

Hello,

I am new to C++ so forgive me if my question is rather lenghty. I am running Vista Home Premium and using Visual Studio C++ 2008 Express (free from Microsoft but without the MFC and ATL libraries).

I wish to access the system registry keys. I downloaded the following test program from Microsoft from http://msdn.microsoft.com/en-us/libr...11(VS.85).aspx

#include <windows.h>
#include <malloc.h>
#include <stdio.h>

#define TOTALBYTES 8192
#define BYTEINCREMENT 4096

void main()
{
DWORD BufferSize = TOTALBYTES;
DWORD cbData;
DWORD dwRet;

PPERF_DATA_BLOCK PerfData = (PPERF_DATA_BLOCK) malloc( BufferSize );
cbData = BufferSize;

printf("\nRetrieving the data...");

dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
TEXT("Global"),
NULL,
NULL,
(LPBYTE) PerfData,
&cbData );
while( dwRet == ERROR_MORE_DATA )
{
// Get a buffer that is big enough.

BufferSize += BYTEINCREMENT;
PerfData = (PPERF_DATA_BLOCK) realloc( PerfData, BufferSize );
cbData = BufferSize;

printf(".");
dwRet = RegQueryValueEx( HKEY_PERFORMANCE_DATA,
TEXT("Global"),
NULL,
NULL,
(LPBYTE) PerfData,
&cbData );
}
if( dwRet == ERROR_SUCCESS )
printf("\n\nFinal buffer size is %d\n", BufferSize);
else printf("\nRegQueryValueEx failed (%d)\n", dwRet);
}

When I try to compile and link this program from the Command Line Prompt with

C:\>cl -EHsc proogram-name.cpp

I get a link error LNK2019 unresolved symbol _imp_ RegQueryValueExA referenced in function main

What am I missing ??

Thanks for any advice.

Gabriela
 
Old February 25th, 2009, 06:47 PM
Registered User
 
Join Date: Feb 2009
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default missing library

You need to link to a library containing the missing function. The function is present in a header (otherwise you would get a compile error).





Similar Threads
Thread Thread Starter Forum Replies Last Post
Visual Web Developer 2008 Express jjc9809 Visual Web Developer 2008 2 December 23rd, 2008 12:06 PM
Help with Visual Studio 2008 IDE dotnetDeveloper Visual Studio 2005 1 December 6th, 2008 12:55 PM
very new to Visual Studio 2008 Joel Saren Visual Basic 2008 Essentials 2 June 6th, 2008 03:27 PM
Does Visual Studio 2008 contains .NET3.5? sikanderwaheed C# 1 March 30th, 2008 04:41 AM
Visual Studio 2008 looks juzjess Intro Programming 0 October 26th, 2007 03:35 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.