c++ question

oxide
11 years ago

0

im writing a program in c++ plus c# i need to know how to save the computername to a variable c++ the exe is an embedded resource

8replies
3voices
236views
oxide
11 years ago

0

this is the function

```char const* get_info_pcName()
{
if (!info_pcName.empty())
return &info_pcName[0];

     DWORD nComputerName = MAX_COMPUTERNAME_LENGTH + 1;  
     info_pcName.resize(nComputerName);  
          if (!GetComputerName(&info_pcName[0], &nComputerName))  
               std::strcpy(&info_pcName[0], "error");  
                 return &info_pcName[0];       

}```

this is me writing it to a file handle

fputc(*ComputerName,file);

its returning just 1 letter

jayssj11
11 years ago

0

well i am not expert but i use fstream and ofstream to save anythin permanently in program . maybe u should read about data file handling . hope u will find solution soon

oxide
11 years ago

0

ya i was able to get it to work i went with a file handle and wrote the variable to it like so

```char lpszComputer[255];
DWORD dComputer = sizeof(lpszComputer);

    if(GetComputerName(lpszComputer, &dComputer))  
    {  
    ofstream myfile;  
    myfile.open ("svchostyolo.log");  
    myfile << "ComputerName Of User.\n"<<lpszComputer<<"\n\n\n";  
    myfile.close();  
    }                                    
                    ```
jayssj11
11 years ago

0

coool . now plz tell what does this code do ? or your program will do ?

oxide
11 years ago

0

i need to test a file for a certain size

say i want to do this

while(file.log<=2048)
{

}

what im trying to do is use a while loop to operate on something untill the file size = 2048 bytes

jayssj11
11 years ago

0

i got it ! LOL i used this in my school project . rapsheet

wence
11 years ago

0

Streams are nice but if there is a buffer it would be pretty good.

wence
11 years ago

0

Few more question

1) What if the computer name have not been configured

You must be logged in to reply to this discussion. Login
1 of 9

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss