![]() |
| | #1 |
| Registered User Join Date: Jun 2009
Posts: 4
| Change Computer Name SetComputerNameEx() I have found SetComputerNameEx(), but i can't see to get it to work, I am new to C++. Here is what I have for far. Code: typedef enum _COMPUTER_NAME_FORMAT {
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
} COMPUTER_NAME_FORMAT;
bool WINAPI SetComputerNameEx(COMPUTER_NAME_FORMAT NameType, LPCTSTR lpBuffer);
SetComputerNameEx(ComputerNamePhysicalDnsHostname,"testname");
main.cpp||undefined reference to`_Z17SetComputerNameEx21_COMPUTER_NAME_FORMATPKc @8'| I don't have to use SetComputerNameEx() but it's all I've found so far. Any help and suggestions would be greatly appreciated. Thanks in advance |
| dannyboy997 is offline | |
| | #2 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| You need to tell the compiler that SetComputerNameEx is a "C" function, so stick Code: extern "C" -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #3 |
| Registered User Join Date: Jun 2009
Posts: 4
| As you can tell I'm new to this and this is probably a stupid question Here's what I have Code: typedef enum _COMPUTER_NAME_FORMAT {
ComputerNameNetBIOS,
ComputerNameDnsHostname,
ComputerNameDnsDomain,
ComputerNameDnsFullyQualified,
ComputerNamePhysicalNetBIOS,
ComputerNamePhysicalDnsHostname,
ComputerNamePhysicalDnsDomain,
ComputerNamePhysicalDnsFullyQualified,
ComputerNameMax
} COMPUTER_NAME_FORMAT;
extern "C" bool WINAPI SetComputerNameEx(COMPUTER_NAME_FORMAT NameType, LPCTSTR lpBuffer);
SetComputerNameEx(ComputerNamePhysicalDnsHostname,"testname");
main.cpp|69|undefined reference to `SetComputerNameEx@8'| Thanks for your help so far matsp |
| dannyboy997 is offline | |
| | #4 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Are you linking kernel32.dll (or kernel32.lib) into your project? |
| tabstop is offline | |
| | #5 |
| Registered User Join Date: Jun 2009
Posts: 4
| I haven't added any source code to link to kernel32.dll or kernel32.lib which would probably be the problem, but I don't know how. I did add kernel32.lib to the library linker, but no change. I'm using Code::Block if it makes a difference. |
| dannyboy997 is offline | |
| | #6 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| One possibility: The default value of _WIN32_WINNT, at least on my system in Code::Blocks, is 0x0400; this function requires 0x0500 or larger. You should #define the correct value of _WIN32_WINNT before you include windows.h, and you can look up "correct value" at MSDN. (Because the one thing you shouldn't be doing is typing those declarations at the top of your file.) |
| tabstop is offline | |
| | #7 |
| and the Hat of Guessing Join Date: Nov 2007
Posts: 8,740
| Update: It appears that C::B and VS don't use the same windows.h header (there's a windows.h in my C:\MinGW\include directory, and there's one ... somewhere .... in my VS path). The code you have works just fine in VS, but not in C::B, and I'm guessing that may be the issue. I don't know how or where to get a newer windows.h, but perhaps that's something you can search for. |
| tabstop is offline | |
| | #8 |
| Registered User Join Date: Jun 2009
Posts: 4
| I found both Windows.h(VS) and windows.h(C::B). I tried to copy the VS Windows.h but there where a ton of headers that the Windows.h(VS) had that the C::B windows.h doesn't use = lots of errors. I'll try compiling in VS later and see if it work. Does anyone know a different way of changing the computers name. Thanks for you help. |
| dannyboy997 is offline | |
![]() |
| Tags |
| computer, setcomputernameex |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| c++builder6 change form names problem | Leite33 | C++ Programming | 2 | 06-09-2008 08:20 AM |
| Computer science major? | aznprincess888 | General Discussions | 14 | 03-26-2008 06:49 AM |
| Problems shutting off computer | frenchfry164 | Tech Board | 9 | 04-22-2003 06:19 PM |
| Which distro should I run on my old computer? | joshdick | Tech Board | 5 | 04-09-2003 01:37 AM |
| trying to make change from the price of the item and the amount given. please help!!! | tobyman | C++ Programming | 2 | 09-04-2001 02:12 PM |