Getting HDD serial No in C++/CLI environment
-
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
What other header files are you including? Those errors indicate windows.h is not included.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What other header files are you including? Those errors indicate windows.h is not included.
Mark Salsbery Microsoft MVP - Visual C++ :java:
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)
-
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)
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:
-
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)
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
#endifMark Salsbery Microsoft MVP - Visual C++ :java:
-
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:
-
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
#endifMark Salsbery Microsoft MVP - Visual C++ :java:
-
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. :)
-
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.
-
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.
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:
-
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;