Advertisement

03.08.2005 at 07:33PM PST, ID: 21343129
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.8

Test_registry.obj : error LNK2001: unresolved external symbol

Asked by durgaprasad_j in Microsoft Visual C++.Net

Tags: , ,


Main program test_registry.cpp
----------------------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include "CFRegistry.h"

int main(int argc, char* argv[])
{
      DWORD dw;
      CFRegistry *obj = new CFRegistry(NULL,NULL,NULL);
      obj->Write("key","value",NULL);
      obj->Read("key",NULL,dw,NULL);
      printf("Read %s\n",dw);
      printf("Hello World!\n");
      return 0;
}

------------------------------------------------------------------------------------------------------------------------

CFRegistry.h contains the declaration of the class CFRegistry

------------------------------------------------------------------------------------------------------------------------
#ifndef CFREGISTRY_H
#define CFREGISTRY_H

#include "SysDef.h"

/**************************************************************************

CFRegistry class definition

**************************************************************************/
class CFRegistry
{
protected:
      LPVOID mhKey;

      BOOL CopyString(LPTSTR lpDest, DWORD dwDestSize, LPTSTR lpSrc);
public:
      CFRegistry(LPTSTR lpName=NULL, LPTSTR lpSection=NULL, LPTSTR lpVendor=NULL);
      CFRegistry(CFRegistry* pParent, LPTSTR lpName);
      ~CFRegistry(void);

      BOOL Write(LPTSTR lpEntry, DWORD dwValue, LPTSTR lpSection=NULL);
      BOOL Read(LPTSTR lpEntry, LPDWORD lpdwValue, DWORD dwDefault, LPTSTR lpSection=NULL);

      BOOL Write(LPTSTR lpEntry, WORD wValue, LPTSTR lpSection=NULL);
      BOOL Read(LPTSTR lpEntry, LPWORD lpwValue, WORD wDefault, LPTSTR lpSection=NULL);

      BOOL Write(LPTSTR lpEntry, BOOL bValue, LPTSTR lpSection=NULL);
      BOOL Read(LPTSTR lpEntry, BOOL* lpbValue, BOOL bDefault, LPTSTR lpSection=NULL);

      BOOL Write(LPTSTR lpEntry, LPTSTR lpValue, LPTSTR lpSection=NULL);
      BOOL Read(LPTSTR lpEntry, DWORD dwStringBuffSize, LPTSTR lpValue, LPTSTR lpDefault, LPTSTR lpSection=NULL);
};

#endif

/* eof */

------------------------------------------------------------------------------------------------------------------------------



CFRegistry.cpp contains the body of the class CFRegistry
-----------------------------------------------------------------------------------------------------------------------------
#include "CFRegistry.h"

/***************************************************************************
** CFRegistry                                                            **
***************************************************************************/
CFRegistry::CFRegistry(LPTSTR lpName, LPTSTR lpSection, LPTSTR lpVendor)
{
      LPTSTR lpTemp = NULL;
      DWORD dwLen = 0;

      if(lpName)
            dwLen = lstrlen(lpName);

      if(lpSection)
            dwLen += lstrlen(lpSection);

      if(lpVendor)
            dwLen += lstrlen(lpVendor);

      lpTemp = new TCHAR[dwLen+255];
      if(!lpTemp)
            mhKey = NULL;
      else
      {
            DWORD dwStatus;
            DWORD dwDummy;

            if(!lpVendor)
                  lstrcpy(lpTemp, TEXT("SOFTWARE\\FINDANT\\"));
            else
            {
                  lstrcpy(lpTemp, TEXT("SOFTWARE\\"));
                  lstrcat(lpTemp, lpVendor);
                  lstrcat(lpTemp, TEXT("\\"));
            }
            if(lpName)
            {
                  lstrcat(lpTemp, lpName);
                  lstrcat(lpTemp, TEXT("\\"));
            }
            if(lpSection)
            {
                  lstrcat(lpTemp, lpSection);
                  lstrcat(lpTemp, TEXT("\\"));
            }

            dwStatus = RegCreateKeyEx(HKEY_LOCAL_MACHINE,
                  lpTemp,
                  NULL, TEXT(""),
                  REG_OPTION_NON_VOLATILE, (KEY_READ|KEY_WRITE),
                  NULL, (HKEY*)&mhKey, &dwDummy);

            delete lpTemp;

            if(dwStatus!=ERROR_SUCCESS)
                  mhKey = NULL;
      }
}

/***************************************************************************
** CFRegistry                                                            **
***************************************************************************/
CFRegistry::CFRegistry(CFRegistry* pParent, LPTSTR lpName)
{
      DWORD dwStatus;
      DWORD dwDummy;

      dwStatus = RegCreateKeyEx((HKEY)pParent->mhKey,
            lpName, NULL, TEXT(""),
            REG_OPTION_NON_VOLATILE, (KEY_READ|KEY_WRITE),
            NULL, (HKEY*)&mhKey, &dwDummy);

      if(dwStatus!=ERROR_SUCCESS)
            mhKey = NULL;
}

/***************************************************************************
** ~CFRegistry                                                           **
***************************************************************************/
CFRegistry::~CFRegistry(void)
{
      if(mhKey)
            RegCloseKey((HKEY)mhKey);
}

/***************************************************************************
** Write                                                                 **
***************************************************************************/
BOOL CFRegistry::Write(LPTSTR lpEntry, DWORD dwValue, LPTSTR lpSection)
{
      BOOL bSuccess = TRUE;

      if(!mhKey)
            bSuccess = FALSE;
      else if(lpSection)
      {
            CFRegistry cfReg(this, lpSection);

            bSuccess = cfReg.Write(lpEntry, dwValue, NULL);
      }
      else if(RegSetValueEx((HKEY)mhKey, lpEntry, NULL, REG_DWORD, (LPBYTE)&dwValue, sizeof(dwValue))!=ERROR_SUCCESS)
            bSuccess = FALSE;

      return bSuccess;
}

/***************************************************************************
** Read                                                                  **
***************************************************************************/
BOOL CFRegistry::Read(LPTSTR lpEntry, LPDWORD lpdwValue, DWORD dwDefault, LPTSTR lpSection)
{
      BOOL bSuccess = TRUE;
      BYTE  bBuff[4];
      DWORD dwType;
      DWORD dwSize = sizeof(bBuff);

      if(!mhKey)
      {
            *lpdwValue = dwDefault;
            bSuccess = FALSE;
      }
      else if(lpSection)
      {
            CFRegistry cfReg(this, lpSection);

            bSuccess = cfReg.Read(lpEntry, lpdwValue, dwDefault, NULL);
      }
      else if(RegQueryValueEx((HKEY)mhKey, lpEntry, NULL, &dwType, bBuff, &dwSize)!=ERROR_SUCCESS)
            *lpdwValue = dwDefault;
      else if(dwType==REG_DWORD)
            *lpdwValue = *(LPDWORD)&bBuff;
      else
            bSuccess = FALSE;

      return bSuccess;
}

/***************************************************************************
** Write                                                                 **
***************************************************************************/
BOOL CFRegistry::Write(LPTSTR lpEntry, WORD wValue, LPTSTR lpSection)
{
      BOOL bSuccess = TRUE;

      if(!mhKey)
            bSuccess = FALSE;
      else if(lpSection)
      {
            CFRegistry cfReg(this, lpSection);

            bSuccess = cfReg.Write(lpEntry, wValue, NULL);
      }
      else if(RegSetValueEx((HKEY)mhKey, lpEntry, NULL, REG_DWORD, (LPBYTE)&wValue, sizeof(wValue))!=ERROR_SUCCESS)
            bSuccess = FALSE;

      return bSuccess;
}

/***************************************************************************
** Read                                                                  **
***************************************************************************/
BOOL CFRegistry::Read(LPTSTR lpEntry, LPWORD lpwValue, WORD wDefault, LPTSTR lpSection)
{
      BOOL bSuccess = TRUE;
      BYTE  bBuff[4];
      DWORD dwType;
      DWORD dwSize = sizeof(bBuff);

      if(!mhKey)
      {
            *lpwValue = wDefault;
            bSuccess = FALSE;
      }
      else if(lpSection)
      {
            CFRegistry cfReg(this, lpSection);

            bSuccess = cfReg.Read(lpEntry, lpwValue, wDefault, NULL);
      }
      else if(RegQueryValueEx((HKEY)mhKey, lpEntry, NULL, &dwType, bBuff, &dwSize)!=ERROR_SUCCESS)
            *lpwValue = wDefault;
      else if(dwType==REG_DWORD)
            *lpwValue = (WORD)(*(LPDWORD)&bBuff);
      else
            bSuccess = FALSE;

      return bSuccess;
}

/***************************************************************************
** Write                                                                 **
***************************************************************************/
BOOL CFRegistry::Write(LPTSTR lpEntry, BOOL bValue, LPTSTR lpSection)
{
      return CFRegistry::Write(lpEntry, (bValue?1:0), lpSection);
}

/***************************************************************************
** Read                                                                  **
***************************************************************************/
BOOL CFRegistry::Read(LPTSTR lpEntry, BOOL* lpbValue, BOOL bDefault, LPTSTR lpSection)
{
      BOOL bSuccess;
      DWORD dwValue = 0;

      bSuccess = CFRegistry::Read(lpEntry, &dwValue, (bDefault?1:0), lpSection);
      if(bSuccess)
            *lpbValue = (dwValue!=0);

      return bSuccess;
}

/***************************************************************************
** Write                                                                 **
***************************************************************************/
BOOL CFRegistry::Write(LPTSTR lpEntry, LPTSTR lpValue, LPTSTR lpSection)
{
      BOOL bSuccess = TRUE;

      if(!mhKey)
            bSuccess = FALSE;
      else if(lpSection)
      {
            CFRegistry cfReg(this, lpSection);

            bSuccess = cfReg.Write(lpEntry, lpValue, NULL);
      }
      else if(RegSetValueEx((HKEY)mhKey, lpEntry, NULL, REG_SZ, (LPBYTE)lpValue, lstrlen(lpValue))!=ERROR_SUCCESS)
            bSuccess = FALSE;

      return bSuccess;
}

/***************************************************************************
** Read                                                                  **
***************************************************************************/
BOOL CFRegistry::Read(LPTSTR lpEntry, DWORD dwStringBuffSize, LPTSTR lpValue, LPTSTR lpDefault, LPTSTR lpSection)
{
      BOOL bSuccess = TRUE;
      BYTE  bBuff[256];
      DWORD dwType;
      DWORD dwSize = sizeof(bBuff);

      lpValue[0] = 0;

      if(!mhKey)
      {
            CopyString(lpValue, dwStringBuffSize, lpDefault);
            bSuccess = FALSE;
      }
      else if(lpSection)
      {
            CFRegistry cfReg(this, lpSection);

            bSuccess = cfReg.Read(lpEntry, dwStringBuffSize, lpValue, lpDefault, NULL);
      }
      else if(RegQueryValueEx((HKEY)mhKey, lpEntry, NULL, &dwType, bBuff, &dwSize)!=ERROR_SUCCESS)
            CopyString(lpValue, dwStringBuffSize, lpDefault);
      else if(dwType==REG_SZ)
            CopyString(lpValue, dwStringBuffSize, (LPTSTR)bBuff);
      else
            bSuccess = FALSE;

      lpValue[dwStringBuffSize-1] = 0;

      return bSuccess;
}

/***************************************************************************
** CopyString                                                            **
***************************************************************************/
BOOL CFRegistry::CopyString(LPTSTR lpDest, DWORD dwDestSize, LPTSTR lpSrc)
{
      BOOL bSuccess = TRUE;

      if((lpDest==NULL) || (lpSrc==NULL) || (dwDestSize<=sizeof(TCHAR)))
            bSuccess = FALSE;
      else
      {
            DWORD dwSrcSize = (lstrlen(lpSrc)*sizeof(TCHAR))+sizeof(TCHAR);
            DWORD dwToCopy = dwSrcSize;

            if(dwToCopy>=dwDestSize)
                  dwToCopy = dwDestSize - sizeof(TCHAR);

            memcpy(lpDest, lpSrc, dwToCopy);
            lpDest[dwToCopy] = 0;
      }

      return bSuccess;
}

/* eof */
-----------------------------------------------------------------------------------------------------------------------------------------

When I do rebuild all, it gives the following error

d:\jags\find ant\test_registry\test_registry.cpp(12) : warning C4700: local variable 'dw' used without having been initialized
Linking...
Test_registry.obj : error LNK2001: unresolved external symbol "public: int __thiscall CFRegistry::Read(char *,unsigned long *,unsigned long,char *)" (?Read@CFRegistry@@QAEHPADPAKK0@Z)
Test_registry.obj : error LNK2001: unresolved external symbol "public: int __thiscall CFRegistry::Write(char *,char *,char *)" (?Write@CFRegistry@@QAEHPAD00@Z)
Test_registry.obj : error LNK2001: unresolved external symbol "public: __thiscall CFRegistry::CFRegistry(char *,char *,char *)" (??0CFRegistry@@QAE@PAD00@Z)
Debug/Test_registry.exe : fatal error LNK1120: 3 unresolved externals
Error executing link.exe.

The object files test_registry.obj, CFRegistry.obj, Stdafx.obj are created after the compilation

How Can I get out of this?
Any help is admired

Thanks,
DuragaprasadStart Free Trial
[+][-]03.08.2005 at 10:22PM PST, ID: 13493441

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.08.2005 at 11:54PM PST, ID: 13493753

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]03.10.2005 at 04:21AM PST, ID: 13505154

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.10.2005 at 08:39AM PST, ID: 13507885

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.13.2005 at 04:23AM PST, ID: 13528269

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.13.2005 at 01:57PM PST, ID: 13530496

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Microsoft Visual C++.Net
Tags: external, unresolved, symbol
Sign Up Now!
Solution Provided By: rcarlan
Participating Experts: 2
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32