|
Thanks for your reply; but it only finds files not give you a total file count in a dir.
|
|
|
|
|
Here's an example using MFC CFileFind.
<br />
#include <afx.h><br />
<br />
void main()<br />
{<br />
CFileFind find;<br />
BOOL notdone = find.FindFile("E:\\test\\*.*");<br />
int files = 0;<br />
int directories = 0;<br />
<br />
if (!notdone)<br />
printf("No files found\n");<br />
<br />
while (notdone)<br />
{<br />
notdone = find.FindNextFile();<br />
<br />
if (find.IsDots())<br />
continue;<br />
<br />
if (find.IsDirectory())<br />
directories++;<br />
else<br />
files++;<br />
}<br />
find.Close();<br />
printf("Files:\t%d\n", files);<br />
printf("Directories:\t%d\n", directories);<br />
}
Greba,
My lack of content on my home page should be entertaining.
|
|
|
|
|
Thank you for the code example. Is there a API that supplies us with the file count in a directory?
|
|
|
|
|
Haven't used this, but this might be what your looking for:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiodirectoryclassgetfilestopic2.asp[^]
specifically this section:
<br />
[C++] <br />
#using <mscorlib.dll><br />
<br />
using namespace System;<br />
using namespace System::IO;<br />
<br />
int main() {<br />
try {<br />
String* dirs[] = Directory::GetFiles(S"c:\\", S"c*");<br />
Console::WriteLine(S"The number of files starting with c is {0}.", __box(dirs->Length));<br />
Collections::IEnumerator* myEnum = dirs->GetEnumerator();<br />
while (myEnum->MoveNext()) {<br />
Console::WriteLine(myEnum->Current);<br />
}<br />
} catch (Exception* e) {<br />
Console::WriteLine(S"The process failed: {0}", e);<br />
}<br />
}<br />
Greba,
My lack of content on my home page should be entertaining.
|
|
|
|
|
I'm having trouble using a CSliderCtrl. I'm trying to set the range from 0 -> 16384 by calling: m_sliderZoom.SetRange(0, 16384, FALSE); in the OnInitDialog() func.
Two strange things are happening. First, if I immediately call GetRange() on the control, it returns both min and max values as 0. Secondly, when I call GetRange() later in the code, the range is always from 0 -> 100.
So, why doesn't GetRange() at least return 0 -> 100 immediately after setting the range? And, more importantly, why am I unable to change the range from 0 -> 100? I've tried setting it to 0 -> 25, as well, with no difference in the final range.
Any help is greatly appreciated.
Here's what I think is the relevant code:
BOOL CSMRLocatorDlg::OnInitDialog()
{
// other stuff
m_sliderZoom.SetRange(0, 16384, FALSE);
int min;
int max;
m_sliderZoom.GetRange( min, max );
CString message;
message.Format( "Min: %d Max: %d", min, max );
AfxMessageBox( message );
// always "Min: 0 Max: 0"
// other stuff
}
// later in the code
void CSMRLocatorDlg::OnOut()
{
m_nZoomLevel = m_sliderZoom.GetPos();
CString message;
int min;
int max;
m_sliderZoom.GetRange( min, max );
message.Format( "Min: %d Max: %d", min, max );
AfxMessageBox( message );
// always "Min: 0 Max: 100"
}
|
|
|
|
|
OK. I figured it out and I'm feeling very stupid right now. The base version of CDialog::OnInitDialog() was being called, but not until after I was trying to SetRange() and GetRange(). This explains the bogus results of GetRange() and the fact that my desired range had no effect. I can offer as an excuse the fact that I was handed this code after somebody else wrote it
I am still wondering how this code worked before, though. According to the previous developer, he had no problems setting the range, even with the call coming before CDialog::OnInitDialog(). Does anyone know if different platforms or versions of MFC DLLs or something else could have allowed the code to work this way?
Thanks.
|
|
|
|
|
Hi,
I have a mysql database on a Redhat linux system.I want to access that database using VC++ as the front end.How should I do?Can someone provide a sample example code for this.
Karteek
|
|
|
|
|
|
just use odbc
there is an odbc driver for mysql on their website
"there is no spoon" biz stuff about me
|
|
|
|
|
Hi,
Thanks a lot.
But still I have a problem.I got the ODBC driver and created a DSN and wrote a sample WIN32 Console appln to test it .But it is not working.Please check this code.
#include "stdafx.h"
#include<afx.h>
#include<afxdb.h>
int main(int argc, char* argv[])
{
printf("Hello World!\n");
CDatabase c;
c.Open(_T("test"),FALSE,FALSE,_T("ODBC"),TRUE);
return 0;
}
It is giving the following errors.
--------------------Configuration: kardb - Win32 Debug--------------------
Compiling...
kardb.cpp
Linking...
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __endthreadex
nafxcwd.lib(thrdcore.obj) : error LNK2001: unresolved external symbol __beginthreadex
Debug/kardb.exe : fatal error LNK1120: 2 unresolved externals
Error executing link.exe.
kardb.exe - 3 error(s), 0 warning(s)
|
|
|
|
|
Hello guys,
do you know if it is possible to get a file name from a file handle?
I tried the code below and strFileName its empty. I've tried to find some info into the MSDN and I cannot manage to find out a method that take in input the file handle and gives me back the file name.
Thanx,
Fabio
CFile* file = new CFile(_T("C:\\test.txt"), CFile::modeCreate|CFile::modeWrite|CFile::shareDenyNone);
CFile newFile((int) file->m_hFile);
newFile.Write("C", 1);
strFileName = newFile.GetFilePath();
file->Close();
|
|
|
|
|
i know that there is a way in kernel mode... but i don't know if it is exported
to user mode.
Don't try it, just do it!
|
|
|
|
|
Highly coupled code is code where the dependencies between things are dense, lots of things depend on other things.
On Unix i know makedepend can give u the dependecies of your classes.
Do any of you have experience in such tool under windows? (better to be opensource)
Thanks and regards,
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
I do not know if this helps, but Visual C++ comes with Depends that will tell you what you application depends on. There is also an add on that you can get (may be open source) called BeSweet. You can also use Doxygen to genterate documentation for your project, I beleive it will show all the dependencies in your project (read the article on Doxygen at codeproject).
INTP
|
|
|
|
|
Below are the code for encrypt and decrypt a text file by supplying a source file, destination file and password.
The problem is if I encrypt the file in Win2000 and decrypt it in WinXP the result is junk and vise versa. Win2000 to Win2000 or WinXP to WinXP work ok. Can anyone tell me what the problem is? Thanks alot.
Encrypt.c
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <wincrypt.h>
#ifdef USE_BLOCK_CIPHER
// defines for RC2 block cipher
#define ENCRYPT_ALGORITHM CALG_RC2
#define ENCRYPT_BLOCK_SIZE 8
#else
// defines for RC4 stream cipher
#define ENCRYPT_ALGORITHM CALG_RC4
#define ENCRYPT_BLOCK_SIZE 1
#endif
static BOOL CAPIEncryptFile(PCHAR szSource, PCHAR szDestination, PCHAR szPassword);
/ **************************************************
***************************/
static BOOL CAPIEncryptFile(PCHAR szSource, PCHAR szDestination, PCHAR szPassword)
{
FILE *hSource = NULL;
FILE *hDestination = NULL;
INT eof = 0;
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
HCRYPTKEY hXchgKey = 0;
HCRYPTHASH hHash = 0;
PBYTE pbKeyBlob = NULL;
DWORD dwKeyBlobLen;
PBYTE pbBuffer = NULL;
DWORD dwBlockLen;
DWORD dwBufferLen;
DWORD dwCount;
BOOL status = FALSE;
// Open source file.
if((hSource = fopen(szSource,"rb")) == NULL) {
printf("Error opening Plaintext file!\n");
goto done;
}
// Open destination file.
if((hDestination = fopen(szDestination,"wb")) == NULL) {
printf("Error opening Ciphertext file!\n");
goto done;
}
// Get handle to the default provider.
if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) {
printf("Error %x during CryptAcquireContext!\n", GetLastError());
goto done;
}
if(szPassword == NULL) {
// Encrypt the file with a random session key.
// Create a random session key.
if(!CryptGenKey(hProv, ENCRYPT_ALGORITHM, CRYPT_EXPORTABLE, &hKey)) {
printf("Error %x during CryptGenKey!\n", GetLastError());
goto done;
}
// Get handle to key exchange public key.
if(!CryptGetUserKey(hProv, AT_KEYEXCHANGE, &hXchgKey)) {
printf("Error %x during CryptGetUserKey!\n", GetLastError());
goto done;
}
// Determine size of the key blob and allocate memory.
if(!CryptExportKey(hKey, hXchgKey, SIMPLEBLOB, 0, NULL, &dwKeyBlobLen)) {
printf("Error %x computing blob length!\n", GetLastError());
goto done;
}
if((pbKeyBlob = malloc(dwKeyBlobLen)) == NULL) {
printf("Out of memory!\n");
goto done;
}
// Export session key into a simple key blob.
if(!CryptExportKey(hKey, hXchgKey, SIMPLEBLOB, 0, pbKeyBlob, &dwKeyBlobLen)) {
printf("Error %x during CryptExportKey!\n", GetLastError());
goto done;
}
// Release key exchange key handle.
CryptDestroyKey(hXchgKey);
hXchgKey = 0;
// Write size of key blob to destination file.
fwrite(&dwKeyBlobLen, sizeof(DWORD), 1, hDestination);
if(ferror(hDestination)) {
printf("Error writing header!\n");
goto done;
}
// Write key blob to destination file.
fwrite(pbKeyBlob, 1, dwKeyBlobLen, hDestination);
if(ferror(hDestination)) {
printf("Error writing header!\n");
goto done;
}
} else {
// Encrypt the file with a session key derived from a password.
// Create a hash object.
if(!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
printf("Error %x during CryptCreateHash!\n", GetLastError());
goto done;
}
// Hash in the password data.
if(!CryptHashData(hHash, szPassword, strlen(szPassword), 0)) {
printf("Error %x during CryptHashData!\n", GetLastError());
goto done;
}
// Derive a session key from the hash object.
if(!CryptDeriveKey(hProv, ENCRYPT_ALGORITHM, hHash, 0, &hKey)) {
printf("Error %x during CryptDeriveKey!\n", GetLastError());
goto done;
}
// Destroy the hash object.
CryptDestroyHash(hHash);
hHash = 0;
}
// Determine number of bytes to encrypt at a time. This must be a multiple
// of ENCRYPT_BLOCK_SIZE.
dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
// Determine the block size. If a block cipher is used this must have
// room for an extra block.
if(ENCRYPT_BLOCK_SIZE > 1) {
dwBufferLen = dwBlockLen + ENCRYPT_BLOCK_SIZE;
} else {
dwBufferLen = dwBlockLen;
}
// Allocate memory.
if((pbBuffer = malloc(dwBufferLen)) == NULL) {
printf("Out of memory!\n");
goto done;
}
// Encrypt source file and write to Source file.
do {
// Read up to 'dwBlockLen' bytes from source file.
dwCount = fread(pbBuffer, 1, dwBlockLen, hSource);
if(ferror(hSource)) {
printf("Error reading Plaintext!\n");
goto done;
}
eof = feof(hSource);
// Encrypt data
if(!CryptEncrypt(hKey, 0, eof, 0, pbBuffer, &dwCount, dwBufferLen)) {
printf("bytes required:%d\n",dwCount);
printf("Error %x during CryptEncrypt!\n", GetLastError());
goto done;
}
// Write data to destination file.
fwrite(pbBuffer, 1, dwCount, hDestination);
if(ferror(hDestination)) {
printf("Error writing Ciphertext!\n");
goto done;
}
} while(!feof(hSource));
status = TRUE;
printf("OK\n");
done:
// Close files.
if(hSource) fclose(hSource);
if(hDestination) fclose(hDestination);
// Free memory.
if(pbKeyBlob) free(pbKeyBlob);
if(pbBuffer) free(pbBuffer);
// Destroy session key.
if(hKey) CryptDestroyKey(hKey);
// Release key exchange key handle.
if(hXchgKey) CryptDestroyKey(hXchgKey);
// Destroy hash object.
if(hHash) CryptDestroyHash(hHash);
// Release provider handle.
if(hProv) CryptReleaseContext(hProv, 0);
return(status);
}
/ **************************************************
***************************/
void init(void)
{
HCRYPTPROV hProv;
HCRYPTKEY hKey;
CHAR szUserName[100];
DWORD dwUserNameLen = 100;
// Attempt to acquire a handle to the default key container.
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0)) {
// Some sort of error occured.
// Create default key container.
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
printf("Error creating key container!\n");
exit(1);
}
// Get name of default key container.
if(!CryptGetProvParam(hProv, PP_CONTAINER, szUserName, &dwUserNameLen, 0)) {
// Error getting key container name.
szUserName[0] = 0;
}
printf("Create key container '%s'\n",szUserName);
}
// Attempt to get handle to signature key.
if(!CryptGetUserKey(hProv, AT_SIGNATURE, &hKey)) {
if(GetLastError() == NTE_NO_KEY) {
// Create signature key pair.
printf("Create signature key pair\n");
if(!CryptGenKey(hProv,AT_SIGNATURE,0,&hKey)) {
printf("Error %x during CryptGenKey!\n", GetLastError());
exit(1);
} else {
CryptDestroyKey(hKey);
}
} else {
printf("Error %x during CryptGetUserKey!\n", GetLastError());
exit(1);
}
}
// Attempt to get handle to exchange key.
if(!CryptGetUserKey(hProv,AT_KEYEXCHANGE,&hKey)) {
if(GetLastError()==NTE_NO_KEY) {
// Create key exchange key pair.
printf("Create key exchange key pair\n");
if(!CryptGenKey(hProv,AT_KEYEXCHANGE,0,&hKey)) {
printf("Error %x during CryptGenKey!\n", GetLastError());
exit(1);
} else {
CryptDestroyKey(hKey);
}
} else {
printf("Error %x during CryptGetUserKey!\n", GetLastError());
exit(1);
}
}
CryptReleaseContext(hProv,0);
// printf("OK\n");
}
/ **************************************************
***************************/
void _cdecl main(int argc, char *argv[])
{
PCHAR szSource = NULL;
PCHAR szDestination = NULL;
PCHAR szPassword = NULL;
init();
// Validate argument count.
if(argc != 3 && argc != 4) {
printf("USAGE: encrypt <dest file=""> [ <password> ]\n");
exit(1);
}
// Parse arguments.
szSource = argv[1];
szDestination = argv[2];
if(argc == 4) {
szPassword = argv[3];
}
if(!CAPIEncryptFile(szSource, szDestination, szPassword)) {
printf("Error encrypting file!\n");
exit(1);
}
exit(0);
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Decrypt.c
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <wincrypt.h>
#ifdef USE_BLOCK_CIPHER
// defines for RC2 block cipher
#define ENCRYPT_ALGORITHM CALG_RC2
#define ENCRYPT_BLOCK_SIZE 8
#else
// defines for RC4 stream cipher
#define ENCRYPT_ALGORITHM CALG_RC4
#define ENCRYPT_BLOCK_SIZE 1
#endif
static BOOL CAPIDecryptFile(PCHAR szSource, PCHAR szDestination, PCHAR szPassword);
/ **************************************************
***************************/
static BOOL CAPIDecryptFile(PCHAR szSource, PCHAR szDestination, PCHAR szPassword)
{
FILE *hSource = NULL;
FILE *hDestination = NULL;
INT eof = 0;
HCRYPTPROV hProv = 0;
HCRYPTKEY hKey = 0;
HCRYPTHASH hHash = 0;
PBYTE pbKeyBlob = NULL;
DWORD dwKeyBlobLen;
PBYTE pbBuffer = NULL;
DWORD dwBlockLen;
DWORD dwBufferLen;
DWORD dwCount;
BOOL status = FALSE;
// Open source file.
if((hSource = fopen(szSource,"rb")) == NULL) {
printf("Error opening Ciphertext file!\n");
goto done;
}
// Open destination file.
if((hDestination = fopen(szDestination,"wb")) == NULL) {
printf("Error opening Plaintext file!\n");
goto done;
}
// Get handle to the default provider.
if(!CryptAcquireContext(&hProv, NULL, NULL, PROV_RSA_FULL, 0)) {
printf("Error %x during CryptAcquireContext!\n", GetLastError());
goto done;
}
if(szPassword == NULL) {
// Decrypt the file with the saved session key.
// Read key blob length from source file and allocate memory.
fread(&dwKeyBlobLen, sizeof(DWORD), 1, hSource);
if(ferror(hSource) || feof(hSource)) {
printf("Error reading file header!\n");
goto done;
}
if((pbKeyBlob = malloc(dwKeyBlobLen)) == NULL) {
printf("Out of memory or improperly formatted source file!\n");
goto done;
}
// Read key blob from source file.
fread(pbKeyBlob, 1, dwKeyBlobLen, hSource);
if(ferror(hSource) || feof(hSource)) {
printf("Error reading file header!\n");
goto done;
}
// Import key blob into CSP.
if(!CryptImportKey(hProv, pbKeyBlob, dwKeyBlobLen, 0, 0, &hKey)) {
printf("Error %x during CryptImportKey!\n", GetLastError());
goto done;
}
} else {
// Decrypt the file with a session key derived from a password.
// Create a hash object.
if(!CryptCreateHash(hProv, CALG_MD5, 0, 0, &hHash)) {
printf("Error %x during CryptCreateHash!\n", GetLastError());
goto done;
}
// Hash in the password data.
if(!CryptHashData(hHash, szPassword, strlen(szPassword), 0)) {
printf("Error %x during CryptHashData!\n", GetLastError());
goto done;
}
// Derive a session key from the hash object.
if(!CryptDeriveKey(hProv, ENCRYPT_ALGORITHM, hHash, 0, &hKey)) {
printf("Error %x during CryptDeriveKey!\n", GetLastError());
goto done;
}
// Destroy the hash object.
CryptDestroyHash(hHash);
hHash = 0;
}
// Determine number of bytes to decrypt at a time. This must be a multiple
// of ENCRYPT_BLOCK_SIZE.
dwBlockLen = 1000 - 1000 % ENCRYPT_BLOCK_SIZE;
dwBufferLen = dwBlockLen;
// Allocate memory.
if((pbBuffer = malloc(dwBufferLen)) == NULL) {
printf("Out of memory!\n");
goto done;
}
// Decrypt source file and write to destination file.
do {
// Read up to 'dwBlockLen' bytes from source file.
dwCount = fread(pbBuffer, 1, dwBlockLen, hSource);
if(ferror(hSource)) {
printf("Error reading Ciphertext!\n");
goto done;
}
eof = feof(hSource);
// Decrypt data
if(!CryptDecrypt(hKey, 0, eof, 0, pbBuffer, &dwCount)) {
printf("Error %x during CryptDecrypt!\n", GetLastError());
goto done;
}
// Write data to destination file.
fwrite(pbBuffer, 1, dwCount, hDestination);
if(ferror(hDestination)) {
printf("Error writing Plaintext!\n");
goto done;
}
} while(!feof(hSource));
status = TRUE;
printf("OK\n");
done:
// Close files.
if(hSource) fclose(hSource);
if(hDestination) fclose(hDestination);
// Free memory.
if(pbKeyBlob) free(pbKeyBlob);
if(pbBuffer) free(pbBuffer);
// Destroy session key.
if(hKey) CryptDestroyKey(hKey);
// Destroy hash object.
if(hHash) CryptDestroyHash(hHash);
// Release provider handle.
if(hProv) CryptReleaseContext(hProv, 0);
return(status);
}
/ **************************************************
***************************/
void init(void)
{
HCRYPTPROV hProv;
HCRYPTKEY hKey;
CHAR szUserName[100];
DWORD dwUserNameLen = 100;
// Attempt to acquire a handle to the default key container.
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, 0)) {
// Some sort of error occured.
// Create default key container.
if(!CryptAcquireContext(&hProv, NULL, MS_DEF_PROV, PROV_RSA_FULL, CRYPT_NEWKEYSET)) {
printf("Error creating key container!\n");
exit(1);
}
// Get name of default key container.
if(!CryptGetProvParam(hProv, PP_CONTAINER, szUserName, &dwUserNameLen, 0)) {
// Error getting key container name.
szUserName[0] = 0;
}
printf("Create key container '%s'\n",szUserName);
}
// Attempt to get handle to signature key.
if(!CryptGetUserKey(hProv, AT_SIGNATURE, &hKey)) {
if(GetLastError() == NTE_NO_KEY) {
// Create signature key pair.
printf("Create signature key pair\n");
if(!CryptGenKey(hProv,AT_SIGNATURE,0,&hKey)) {
printf("Error %x during CryptGenKey!\n", GetLastError());
exit(1);
} else {
CryptDestroyKey(hKey);
}
} else {
printf("Error %x during CryptGetUserKey!\n", GetLastError());
exit(1);
}
}
// Attempt to get handle to exchange key.
if(!CryptGetUserKey(hProv,AT_KEYEXCHANGE,&hKey)) {
if(GetLastError()==NTE_NO_KEY) {
// Create key exchange key pair.
printf("Create key exchange key pair\n");
if(!CryptGenKey(hProv,AT_KEYEXCHANGE,0,&hKey)) {
printf("Error %x during CryptGenKey!\n", GetLastError());
exit(1);
} else {
CryptDestroyKey(hKey);
}
} else {
printf("Error %x during CryptGetUserKey!\n", GetLastError());
exit(1);
}
}
CryptReleaseContext(hProv,0);
// printf("OK\n");
}
/ **************************************************
***************************/
void _cdecl main(int argc, char *argv[])
{
PCHAR szSource = NULL;
PCHAR szDestination = NULL;
PCHAR szPassword = NULL;
init();
// Validate argument count.
if(argc != 3 && argc != 4) {
printf("USAGE: decrypt <dest file=""> [ <password> ]\n");
exit(1);
}
// Parse arguments.
szSource = argv[1];
szDestination = argv[2];
if(argc == 4) {
szPassword = argv[3];
}
if(!CAPIDecryptFile(szSource, szDestination, szPassword)) {
printf("Error encrypting file!\n");
exit(1);
}
exit(0);
}
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
|
All of a sudden, Visual Studio started to give me the message "One or more files are out of date or do not exist" and list all my obj files (and bsc and exe too), everytime I click Execute Program (Ctrl-F5) or Go (F5). It's ok if the files are really outdated, but the problem occurs after I Rebuild All and then Execute. And it compiles and build all the sources over and over. It is happening only with the project I'm working on. I tried others and it works fine. Any suggestions ?
Thanks
Geraldo
|
|
|
|
|
Check the date of files in sourcesafe, I once changed my system date and then changed it back, and as a result I had that problem until the date went past the date I ran at for a day.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
I'm not using sourcesafe. I solved the problem this way: I created a new project, created every cpp and h file empty (it must have been 12 files) and then copied and pasted the source files one by one and after. It took me all day long, but now I have a working copy again. Very strange. I kept the old copy to play with when I got time. I hope it won't happen again.
Thanks.
|
|
|
|
|
someone changed ur system date to a forward date and then you edited the files (and changed the date back) and saved it happens to me all the time , just edit the files once more and their modifed date will be taken care of (after changing the time)
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
Hi,
How can I get the IP address of the system in which the executable is running using C functions(both for linux and windows).
Karteek
|
|
|
|
|
gethostbyname() and so on
|
|
|
|
|
Anonymous wrote:
gethostbyname()...
Preceded by gethostname() .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
Can you give an example?I tried it but it did not work.
Thank you
Karteek
|
|
|
|
|
http://tinyurl.com/3df5s[^]
char szHost[128];
gethostname(szHost, sizeof(szHost));
struct hostent *pHost;
pHost = gethostbyname(szHost);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I did the same thing and I tried to print pHost->h_addr_list[0].But I am not getting the ip address of the system
Karteek
|
|
|
|
|