Ninjakreborn Posted July 26, 2009 Share Posted July 26, 2009 I found the following code example based off of the windows API. i already know a good bit about the windows API and already can make windows, windows inside of windows, dialogs, modeless dialogs, and quite a few controls. Right now I was trying to get together some of the information from the users computer, but this is throwing a lot of C++ compiler errors. #include <string> #include <iostream.h> string GetLocalComputerName() { TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1]; string strRetVal; DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1; if(GetComputerName(chrComputerName,&dwBufferSize)) { // We got the name, set the return value. strRetVal = chrComputerName; } else { // Failed to get the name, call GetLastError here to get // the error code. strRetVal = ""; } return(strRetVal); } [compilererrors] C:\Program Files\CodeBlocks\MinGW\bin\..\lib\gcc\mingw32\3.4.5\..\..\..\..\include\c++\3.4.5\backward\backward_warning.h|32|warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.| C:\xampp\htdocs\cpp projects\Personal Multi-Tool\main.cpp|7|error: `string' does not name a type| C:\xampp\htdocs\cpp projects\Personal Multi-Tool\main.cpp||In function `LRESULT WndProc(HWND__*, UINT, WPARAM, LPARAM)':| C:\xampp\htdocs\cpp projects\Personal Multi-Tool\main.cpp|44|error: `string' was not declared in this scope| C:\xampp\htdocs\cpp projects\Personal Multi-Tool\main.cpp|44|error: expected `;' before "tmp"| C:\xampp\htdocs\cpp projects\Personal Multi-Tool\main.cpp|44|warning: unused variable 'string'| ||=== Build finished: 3 errors, 2 warnings ===| [/compilererrors] That was what happened when I used his code directly. I already knew enough about to change over from the deprecated headers so I fixed that by changing the header to reflect the undeprecated version, rebuilt, and got this. I also fixed a few othre errors I knew had to fix but I was left with: [compilererrors] C:\xampp\htdocs\cpp projects\Personal Multi-Tool\main.cpp|7|error: `string' does not name a type| ||=== Build finished: 1 errors, 0 warnings ===| [/compilerrrors] My new function is [function] string GetLocalComputerName() { TCHAR chrComputerName[MAX_COMPUTERNAME_LENGTH + 1]; string strRetVal; DWORD dwBufferSize = MAX_COMPUTERNAME_LENGTH + 1; if(GetComputerName(chrComputerName,&dwBufferSize)) { // We got the name, set the return value. strRetVal = chrComputerName; } else { // Failed to get the name, call GetLastError here to get // the error code. strRetVal = ""; } return(strRetVal); } [/function] Any advice? Quote Link to comment https://forums.phpfreaks.com/topic/167528-solved-why-doesnt-this-get-the-name-c/ Share on other sites More sharing options...
corbin Posted July 27, 2009 Share Posted July 27, 2009 I'm guessing the error was just either forgotten std:: or "using namespace std;"? Quote Link to comment https://forums.phpfreaks.com/topic/167528-solved-why-doesnt-this-get-the-name-c/#findComment-883756 Share on other sites More sharing options...
Highlander Posted August 10, 2009 Share Posted August 10, 2009 And replace #include <iostream.h> with #include <iostream> The first one is meant for C-compiler, not C++ Quote Link to comment https://forums.phpfreaks.com/topic/167528-solved-why-doesnt-this-get-the-name-c/#findComment-894845 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.