Yes I know its a long code and it will get longer but there is a compiler error in the int main ()

First Visual C++ 2008 Express edition error

------ Build started: Project: MAC ADDRESS, Configuration: Debug Win32 ------
Compiling...
MAC ADDRESS.cpp
warning C4603: '_WIN32_WINNT' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
(3) : use of precompiled header
(2) : warning C4603: '_WIN32_IE' : macro is not defined or definition is different after precompiled header use
Add macro to precompiled header instead of defining here
(3) : use of precompiled header
(53) : warning C4996: 'swscanf': This function or variable may be unsafe. Consider using swscanf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(575) : see declaration of 'swscanf'
(81) : warning C4996: 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(252) : see declaration of 'freopen'
(86) : warning C4996: 'freopen': This function or variable may be unsafe. Consider using freopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(252) : see declaration of 'freopen'
(165) : error C2664: 'SHGetSpecialFolderPathW' : cannot convert parameter 2 from 'LPSTR' to 'LPWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
(181) : error C2664: 'CreateDirectoryW' : cannot convert parameter 1 from 'const char *' to 'LPCWSTR'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

MAC ADDRESS - 2 error(s), 5 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

And For Dev C++ Which I PREFER but for what ever reason the code will never compile in it and i think it may be due to the stdafx but i dont know... this is the error

[Linker error] undefined reference to `NetWkstaTransportEnum@28'
[Linker error] undefined reference to `NetApiBufferFree@4'
ld returned 1 exit status

#define _WIN32_WINNT	0x0500
#define _WIN32_IE		0x0500
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>
#pragma comment(lib, "Netapi32.lib")

using namespace std;

// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
	printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 
		MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}

// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
	unsigned char MACData[8];						// Allocate data structure for MAC (6 bytes needed)

	WKSTA_TRANSPORT_INFO_0 *pwkti;					// Allocate data structure for Netbios
	DWORD dwEntriesRead;
	DWORD dwTotalEntries;
	BYTE *pbBuffer;
    
	// Get MAC address via NetBios's enumerate function
	NET_API_STATUS dwStatus = NetWkstaTransportEnum(
		NULL,						// [in]  server name
		0,							// [in]  data structure to return
		&pbBuffer,					// [out] pointer to buffer
		MAX_PREFERRED_LENGTH,		// [in]  maximum length
		&dwEntriesRead,				// [out] counter of elements actually enumerated
		&dwTotalEntries,			// [out] total number of elements that could be enumerated
		NULL);						// [in/out] resume handle
	assert(dwStatus == NERR_Success);

	pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer;		// type cast the buffer

	for(DWORD i=1; i< dwEntriesRead; i++)			// first address is 00000000, skip it
	{												// enumerate MACs and print
		swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx", 
			&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
		PrintMACaddress(MACData);
	}

	// Release pbBuffer allocated by above function
	dwStatus = NetApiBufferFree(pbBuffer);
	assert(dwStatus == NERR_Success);
}

int _tmain(int argc, _TCHAR* argv[])
{   
	cout<<"Please Type the Letter of the Removable Drive followed by [Enter]: \n";
    char * buffer5;  //Allows user to Input Drive Letter
	char name5[1];
	cin>> name5;
	

     string base5="C:/Physical-Address.txt";
     string str5=base5;
     str5.replace(0,1,name5,0,100);
     const char *name6;
     name6=str5.c_str();





	FILE *stream ;		//Redirect Output from console to a TextFile
	if((stream = freopen(name6, "w", stdout)) == NULL)
       exit(-1);

	GetMACaddress();							// Obtain MAC address of adapters
	
	stream = freopen("CON", "w", stdout);  //Redirect Output to the Screen
	
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
	cout<<"Welcome to Brandon's Installation Helper\n";
	cout<<"Press Enter to begin the program installation\n";
	cin.get();

	cout<<"Please Wait Reading Address...\n\n";



//Put HostID Into String
 
   
    
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
string HostID;
      ifstream in("D:\\Physical-Address.txt");
      if (!in)
      {
      cout << "There was a problem with opening the file for reading." << endl;
      }
      else
      {
      getline (in,HostID);
      cout<<"Your Host Id is: "<< HostID << endl;
      }
	Sleep(1000);
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
	cout<<"Now Creating Hacked License File... Do Not Exit...\n";
	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
	cout<<"License File Created.\n\n";
    
    


                        //Allows user to Input Removable Drive Letter
   	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
    cout<<"Do This Step CAREFULLY Or Else The Program will Just Exit\n";
   	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
    cout<<"Please Type the Letter of the Removable Drive followed by [Enter]: \n";
    char * buffer2;  //Allows user to Input Drive Letter
	char name[1];
	cin>> name;
	

     string base2="E:\\Pro. Engineering F000\\ProELicense\\license.dat";
     string str1=base2;
     str1.replace(0,1,name,0,100);
     const char *name2;
     name2=str1.c_str();
     
     
    std::ifstream ifile(name2,std::ios::binary);
	ifile.seekg(0,std::ios_base::end);
	long s=ifile.tellg();
	char *buffer=new char[s];
	ifile.seekg(0);
	ifile.read(buffer,s);
	ifile.close();
	std::string txt(buffer,s);
	delete[] buffer;
	delete[] buffer2;
	size_t off=0;
	while ((off=txt.find("YOUR_HOST_ID",off))!=std::string::npos)
		txt.replace(off,sizeof("YOUR_HOST_ID")-1,HostID);
	std::ofstream ofile("D:\\license.dat");
	ofile.write(txt.c_str(),txt.size());


                  
	
	//Create "ProELicense" Folder
  
    cout<<"Creating ProELicense Folder!\n";  
                  
    // get the path to the current users my documents folder
    // storing it in an LPSTR
    LPSTR userDocsPath = new CHAR[MAX_PATH];
    SHGetSpecialFolderPath(0, userDocsPath, CSIDL_PERSONAL, 0);

    // now copy the path into a std::string
    std::string path = std::string(userDocsPath);

    // delete the LPSTR as we don't need it any more...
    delete userDocsPath;

    // Now you've got the path to your users 'My Documents' folder
    // stored in path, you can append any further directories onto it. 
    // e.g.
    path.append("/ProELicense2"); 
    // NOTE: using forward slashes works in file paths, double backslashes are not necessary!

    // Not sure you need to bother creating an 
    // LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
    CreateDirectory(path.c_str(), 0);
    cout << "\nFolder Created!\n";
     
     
     
	Sleep(2000);


 return (0);     
}

I dont UnderStand why it still wont compile in VC++ 2008 express edition.... someone pls help =( Also why wont the above code work in Dev C++

#define _WIN32_WINNT	0x0500
#define _WIN32_IE		0x0500
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>

using namespace std;
                  
int main()
{
    cout<<"Creating ProELicense Folder!\n";  
                  
    // get the path to the current users my documents folder
    // storing it in an LPSTR
    LPSTR userDocsPath = new CHAR[MAX_PATH];
    SHGetSpecialFolderPath(0, userDocsPath, CSIDL_PERSONAL, 0);

    // now copy the path into a std::string
    std::string path = std::string(userDocsPath);

    // delete the LPSTR as we don't need it any more...
    delete userDocsPath;

    // Now you've got the path to your users 'My Documents' folder
    // stored in path, you can append any further directories onto it. 
    // e.g.
    path.append("/ProELicense2"); 
    // NOTE: using forward slashes works in file paths, double backslashes are not necessary!

    // Not sure you need to bother creating an 
    // LPSECURITY_ATTRIBUTES object seeing as you're setting it to null!
    CreateDirectory(path.c_str(), 0);
    cout << "\nFolder Created!\n";

 Sleep(2000);
 return (0);     
}

Your smaller code compiled fine in VC++ 2008 Express, once I commented out the #include "stdafx.h" .

Similarly, commenting out stdafx.h and a couple other minor changes to allow compiling as console app rather than a windows app, ( _tmain to main, TCHAR to char) it compiled, with some warnings.

So, what do you have in the stdafx.h?

This is my stdafx header file but when i comment out the header file it says at the end of the error part that I forgot to add stdafx.h to my code and it didnt compile... also when i comment out that header file it says it skipped all the other headerfiles looking for a precompiled header: stdafx

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

#pragma once

#include "targetver.h"

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


// TODO: reference additional headers your program requires here

the small piece of code is the lower part of the large code but I cant get the small one to compile in VC++ and cant get the large part to compile in DEV C++ dunnno y

Edited 7 Years Ago by triumphost: n/a

the piece that wont compile in dev c++ is this piece it gives two simple errors but i cant figure out how to fix it

#define _WIN32_WINNT	0x0500
#define _WIN32_IE		0x0500
#include "stdafx.h"
#include <Windows.h>
#include <lm.h>
#include <assert.h>
#include <iostream>
#include <winuser.h>
#include <stdlib.h>
#include <string>
#include <stdio.h>
#include <fstream>
#include <algorithm>
#include <shlobj.h>
#include <direct.h>
#pragma comment(lib, "Netapi32.lib")

using namespace std;

// Prints the MAC address stored in a 6 byte array to stdout
static void PrintMACaddress(unsigned char MACData[])
{
	printf("MAC Address: %02X-%02X-%02X-%02X-%02X-%02X\n", 
		MACData[0], MACData[1], MACData[2], MACData[3], MACData[4], MACData[5]);
}

// Fetches the MAC address and prints it
static void GetMACaddress(void)
{
	unsigned char MACData[8];						// Allocate data structure for MAC (6 bytes needed)

	WKSTA_TRANSPORT_INFO_0 *pwkti;					// Allocate data structure for Netbios
	DWORD dwEntriesRead;
	DWORD dwTotalEntries;
	BYTE *pbBuffer;
    
	// Get MAC address via NetBios's enumerate function
	NET_API_STATUS dwStatus = NetWkstaTransportEnum(
		NULL,						// [in]  server name
		0,							// [in]  data structure to return
		&pbBuffer,					// [out] pointer to buffer
		MAX_PREFERRED_LENGTH,		// [in]  maximum length
		&dwEntriesRead,				// [out] counter of elements actually enumerated
		&dwTotalEntries,			// [out] total number of elements that could be enumerated
		NULL);						// [in/out] resume handle
	assert(dwStatus == NERR_Success);

	pwkti = (WKSTA_TRANSPORT_INFO_0 *)pbBuffer;		// type cast the buffer

	for(DWORD i=1; i< dwEntriesRead; i++)			// first address is 00000000, skip it
	{												// enumerate MACs and print
		swscanf((wchar_t *)pwkti[i].wkti0_transport_address, L"%2hx%2hx%2hx%2hx%2hx%2hx", 
			&MACData[0], &MACData[1], &MACData[2], &MACData[3], &MACData[4], &MACData[5]);
		PrintMACaddress(MACData);
	}

	// Release pbBuffer allocated by above function
	dwStatus = NetApiBufferFree(pbBuffer);
	assert(dwStatus == NERR_Success);
}

I'm not a Windows programmer, so I can't help debug, but is there anything in the program that requires you to use all of these Windows-specific headers? Will the regular C and C++ standard libraries not do what you need? I'm pretty sure nothing but Visual Studio uses "stdafx.h", and even there, I don't think you HAVE to use it. I've used Visual C++, but I've mostly started with an empty project, so it doesn't add that "stdafx.h" line. It's just a matter of using pre-compiled headers versus compiling them every time. Get that "stdafx.h" line out of there and try recompiling it in Dev C++. Again, I'm not a Windows programmer, so I have no idea what a lot of that stuff is.

OMG OMG I got it to work with u guys tips!! I kept getting error about undefined reference to winMain@16 so i took out what that guy above you told me to take out then I removed the stdafx.h header and added these two things to Project -> Project Options (Alt+P) -> Parameters -> Linker:

-lIphlpapi
-lNetapi32

And clicked Ok and now when I compile it works perfect!! TY GUYS SO MUCH!!! Ive been trying that for days

This question has already been answered. Start a new discussion instead.