Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Managed C++/CLI
  4. Getting HDD serial No in C++/CLI environment

Getting HDD serial No in C++/CLI environment

Scheduled Pinned Locked Moved Managed C++/CLI
helpc++winformstutorialworkspace
13 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J J_E_D_I

    Thanks, I do not get that error anymore...but I get all those ones! Error 1 error C2065: 'MAX_PATH' : undeclared identifier Error 2 error C2065: 'DWORD' : undeclared identifier Error 3 error C2146: syntax error : missing ';' before identifier 'volumeSerialNumber' Error 4 error C2065: 'DWORD' : undeclared identifier Error 5 error C2146: syntax error : missing ';' before identifier 'maxNameLength' Error 6 error C2065: 'maxNameLength' : undeclared identifier Error 7 error C2065: 'DWORD' : undeclared identifier Error 8 error C2146: syntax error : missing ';' before identifier 'fileSystemFlags' Error 9 error C2065: 'fileSystemFlags' : undeclared identifier Error 10 error C2065: 'MAX_PATH' : undeclared identifier Error 11 error C2065: 'maxNameLength' : undeclared identifier Error 12 error C2065: 'fileSystemFlags' : undeclared identifier Error 13 error C2065: 'systemName' : undeclared identifier Error 14 error C2065: 'MAX_PATH' : undeclared identifier Error 15 error C2078: too many initializers

    M Offline
    M Offline
    Mark Salsbery
    wrote on last edited by
    #4

    What other header files are you including? Those errors indicate windows.h is not included.

    Mark Salsbery Microsoft MVP - Visual C++ :java:

    J 1 Reply Last reply
    0
    • M Mark Salsbery

      What other header files are you including? Those errors indicate windows.h is not included.

      Mark Salsbery Microsoft MVP - Visual C++ :java:

      J Offline
      J Offline
      J_E_D_I
      wrote on last edited by
      #5

      Actually, windows.h is already included in the .cpp file... These are the other header files I've got:

      #include "stdafx.h"
      #include "Form1.h"
      #include tchar.h
      #include vector
      #include ctime
      #include math.h
      #include fstream
      #include string
      #include iostream
      #include sstream
      using std::dec;
      using std::hex;
      #include iomanip
      using std::setprecision;
      using std::setbase;
      #include cstdlib
      using std::atof;
      #include windows.h
      #pragma comment(lib, "user32.lib")
      #include stdio.h
      #include cstdio
      #include strsafe.h
      using namespace Ex22_01;

      (Note: I had to remove < and > from the directives as otherwise it would not show up in this message)

      L M 2 Replies Last reply
      0
      • J J_E_D_I

        Actually, windows.h is already included in the .cpp file... These are the other header files I've got:

        #include "stdafx.h"
        #include "Form1.h"
        #include tchar.h
        #include vector
        #include ctime
        #include math.h
        #include fstream
        #include string
        #include iostream
        #include sstream
        using std::dec;
        using std::hex;
        #include iomanip
        using std::setprecision;
        using std::setbase;
        #include cstdlib
        using std::atof;
        #include windows.h
        #pragma comment(lib, "user32.lib")
        #include stdio.h
        #include cstdio
        #include strsafe.h
        using namespace Ex22_01;

        (Note: I had to remove < and > from the directives as otherwise it would not show up in this message)

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #6

        Hi, it may come as a surprise, but the order of the includes matters too. i.e. if tchar.h relies on windows.h, then windows.h must precede tchar.h; normally if you suddenly need another include, you put it at the end of the list. BTW: the behavior of message editing regarding < and > depends on the checked state of "Ignore HTML tags in this message" checkbox. :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Fixturized forever. :confused:


        J 1 Reply Last reply
        0
        • J J_E_D_I

          Actually, windows.h is already included in the .cpp file... These are the other header files I've got:

          #include "stdafx.h"
          #include "Form1.h"
          #include tchar.h
          #include vector
          #include ctime
          #include math.h
          #include fstream
          #include string
          #include iostream
          #include sstream
          using std::dec;
          using std::hex;
          #include iomanip
          using std::setprecision;
          using std::setbase;
          #include cstdlib
          using std::atof;
          #include windows.h
          #pragma comment(lib, "user32.lib")
          #include stdio.h
          #include cstdio
          #include strsafe.h
          using namespace Ex22_01;

          (Note: I had to remove < and > from the directives as otherwise it would not show up in this message)

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #7

          As Luc mentioned, the order of the #includes can be a factor. Another recent post asked about tchar.h and I tested it - it can be used all by itself and it pulls in any additional header files it needs, so I wouldn't think that's an issue here.. In your stdafx.h file, you may be missing the Windows versioning macros. The macros have changed a bit in recent SDK versions, but if you create a dummy project (MFC or Win32) you can look at the stdafx.h file and see the defaults. For example, here's a stdafx.h file from one of my projects, using the latest SDK on VS 2008:

          // stdafx.h : include file for standard system include files,
          // or project specific include files that are used frequently,
          // but are changed infrequently

          #pragma once

          #define WIN32_LEAN_AND_MEAN

          #include "targetver.h"

          #include <stdio.h>
          #include <tchar.h>

          #ifndef VC_EXTRALEAN
          #define VC_EXTRALEAN
          #endif

          // Windows Header Files:
          #include <windows.h>

          // targetver.h

          #pragma once

          #ifndef NTDDI_VERSION
          #define NTDDI_VERSION NTDDI_WINXPSP2
          #endif

          #ifndef WINVER
          #define WINVER _WIN32_WINNT_WINXP
          #endif

          #ifndef _WIN32_WINNT
          #define _WIN32_WINNT _WIN32_WINNT_WINXP
          #endif

          #ifndef _WIN32_WINDOWS
          #define _WIN32_WINDOWS 0x0410
          #endif

          #ifndef _WIN32_IE
          #define _WIN32_IE 0x0600
          #endif

          Mark Salsbery Microsoft MVP - Visual C++ :java:

          J 1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, it may come as a surprise, but the order of the includes matters too. i.e. if tchar.h relies on windows.h, then windows.h must precede tchar.h; normally if you suddenly need another include, you put it at the end of the list. BTW: the behavior of message editing regarding < and > depends on the checked state of "Ignore HTML tags in this message" checkbox. :)

            Luc Pattyn [Forum Guidelines] [My Articles]


            Fixturized forever. :confused:


            J Offline
            J Offline
            J_E_D_I
            wrote on last edited by
            #8

            Luc, you are absolutely right! I've changed the order of the include directives and it works like a breeze. Thank you so much for this, I admit I would have never thought about it. :)

            L 1 Reply Last reply
            0
            • M Mark Salsbery

              As Luc mentioned, the order of the #includes can be a factor. Another recent post asked about tchar.h and I tested it - it can be used all by itself and it pulls in any additional header files it needs, so I wouldn't think that's an issue here.. In your stdafx.h file, you may be missing the Windows versioning macros. The macros have changed a bit in recent SDK versions, but if you create a dummy project (MFC or Win32) you can look at the stdafx.h file and see the defaults. For example, here's a stdafx.h file from one of my projects, using the latest SDK on VS 2008:

              // stdafx.h : include file for standard system include files,
              // or project specific include files that are used frequently,
              // but are changed infrequently

              #pragma once

              #define WIN32_LEAN_AND_MEAN

              #include "targetver.h"

              #include <stdio.h>
              #include <tchar.h>

              #ifndef VC_EXTRALEAN
              #define VC_EXTRALEAN
              #endif

              // Windows Header Files:
              #include <windows.h>

              // targetver.h

              #pragma once

              #ifndef NTDDI_VERSION
              #define NTDDI_VERSION NTDDI_WINXPSP2
              #endif

              #ifndef WINVER
              #define WINVER _WIN32_WINNT_WINXP
              #endif

              #ifndef _WIN32_WINNT
              #define _WIN32_WINNT _WIN32_WINNT_WINXP
              #endif

              #ifndef _WIN32_WINDOWS
              #define _WIN32_WINDOWS 0x0410
              #endif

              #ifndef _WIN32_IE
              #define _WIN32_IE 0x0600
              #endif

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              J Offline
              J Offline
              J_E_D_I
              wrote on last edited by
              #9

              Hi Mark, thanks for this detailed suggestion. Luc's advice however solved the problem easily and for the time being I'll stick with it. I'll definitely look into your solution if a similar problem happens in the future. Cheers :-D

              1 Reply Last reply
              0
              • J J_E_D_I

                Luc, you are absolutely right! I've changed the order of the include directives and it works like a breeze. Thank you so much for this, I admit I would have never thought about it. :)

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #10

                You're welcome. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Fixturized forever. :confused:


                J 1 Reply Last reply
                0
                • L Luc Pattyn

                  You're welcome. :)

                  Luc Pattyn [Forum Guidelines] [My Articles]


                  Fixturized forever. :confused:


                  J Offline
                  J Offline
                  J_E_D_I
                  wrote on last edited by
                  #11

                  Hi again Luc, I was wondering if you had any hint on how to solve this problem which is somehow linked to the previous one. I need to save the value obtained with the previous code (which is a DWORD: DesiredValue) in a registry key and this was the syntax I was using (successfully) in console environment.

                  DWORD DesiredValue;

                  // Creates Desired Registry Key
                  HKEY Xtmpkey;
                  DWORD dwDisp = 0;
                  LPDWORD xlpdwDisposition = &dwDisp;
                  DWORD dwVal = DesiredValue;
                  // Desired Path for the Registry Key
                  RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\MyPath", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &Xtmpkey,xlpdwDisposition);

                  // Creates Desired Value
                  RegSetValueEx (Xtmpkey, L"Desired_Value_Name", 0L, REG_DWORD,(CONST BYTE*) &dwVal, sizeof(DWORD));

                  Now that I am porting the software into C++/CLI environment it returns the following errors: Error 1 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES * const,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKQAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) Error 2 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegSetValueExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExW@@$$J224YGJPAUHKEY__@@PB_WKKPBEK@Z) Error 3 fatal error LNK1120: 2 unresolved externals What am I doing wrong? I thank you in advance.

                  L 1 Reply Last reply
                  0
                  • J J_E_D_I

                    Hi again Luc, I was wondering if you had any hint on how to solve this problem which is somehow linked to the previous one. I need to save the value obtained with the previous code (which is a DWORD: DesiredValue) in a registry key and this was the syntax I was using (successfully) in console environment.

                    DWORD DesiredValue;

                    // Creates Desired Registry Key
                    HKEY Xtmpkey;
                    DWORD dwDisp = 0;
                    LPDWORD xlpdwDisposition = &dwDisp;
                    DWORD dwVal = DesiredValue;
                    // Desired Path for the Registry Key
                    RegCreateKeyEx(HKEY_CURRENT_USER, L"SOFTWARE\\MyPath", 0L,NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &Xtmpkey,xlpdwDisposition);

                    // Creates Desired Value
                    RegSetValueEx (Xtmpkey, L"Desired_Value_Name", 0L, REG_DWORD,(CONST BYTE*) &dwVal, sizeof(DWORD));

                    Now that I am porting the software into C++/CLI environment it returns the following errors: Error 1 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegCreateKeyExW(struct HKEY__ *,wchar_t const *,unsigned long,wchar_t *,unsigned long,unsigned long,struct _SECURITY_ATTRIBUTES * const,struct HKEY__ * *,unsigned long *)" (?RegCreateKeyExW@@$$J236YGJPAUHKEY__@@PB_WKPA_WKKQAU_SECURITY_ATTRIBUTES@@PAPAU1@PAK@Z) Error 2 error LNK2001: unresolved external symbol "extern "C" long __stdcall RegSetValueExW(struct HKEY__ *,wchar_t const *,unsigned long,unsigned long,unsigned char const *,unsigned long)" (?RegSetValueExW@@$$J224YGJPAUHKEY__@@PB_WKKPBEK@Z) Error 3 fatal error LNK1120: 2 unresolved externals What am I doing wrong? I thank you in advance.

                    L Offline
                    L Offline
                    Luc Pattyn
                    wrote on last edited by
                    #12

                    Hi, there are two ways to solve this: 1. most registry operations are supported in .NET by the Registry class things not supported include special key types (not REG_SZ) 2. when the Registry class does not offer what you need, you have to call the native functions (such as RegCreateKeyEx). I don't know the details for C++, but you somehow must tell it where the library functions can be found, and how they should be called. This article[^] probably contains all you need and more. FYI: in C# there is only one way to access native code, that is thru P/Invoke. Remark: you would better have started a new thread for a question that hardly is connected to an old topic... that would have improved your chances for someone else to pick it up. :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Fixturized forever. :confused:


                    1 Reply Last reply
                    0
                    • J J_E_D_I

                      Hi, I had this code which worked beautifully in console mode, but now I am trying to convert the program into windows forms and the compiler returns the following error: Error 1 error C3861: '_T': identifier not found Any advice on how to solve this problem would be highly appreciated.

                      int GetHDDserialNo;

                      //// Gets HDD serial No
                      TCHAR volumeName\[MAX\_PATH\];
                      DWORD volumeSerialNumber;
                      DWORD maxNameLength;
                      DWORD fileSystemFlags;
                      TCHAR systemName\[MAX\_PATH\];
                      
                      GetHDDserialNo = GetVolumeInformation
                      	(
                      	\_T("c:\\\\"),
                      	volumeName, MAX\_PATH,
                      	&volumeSerialNumber,
                      	&maxNameLength,
                      	&fileSystemFlags,
                      	systemName, MAX\_PATH
                      	);
                      
                      int SerialNumber = volumeSerialNumber;
                      
                      A Offline
                      A Offline
                      adi0990
                      wrote on last edited by
                      #13

                      Use #include "atlstr.h" or #include "afx.h" header file.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups