|
Hi, does anyone know how to obtein the IP of the computer using visual c++?
And the physical direction?
Thanks
|
|
|
|
|
maskaseb wrote:
Hi, does anyone know how to obtein the IP of the computer using visual c++?
gethostname() followed by gethostbyname() .
maskaseb wrote:
And the physical direction?
???
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Thank you David, but I got this message:
"error C2065: 'gethostname' : undeclared identifier"
"error C2065: 'gethostbyname' : undeclared identifier"
Could you tell me the #include I have to put and make an example?
Thank you for your help
For phisical direction I refer to the first information that you get if you do a ipconfig/all in a ms-dos window.
Thank you another time
|
|
|
|
|
maskaseb wrote:
Could you tell me the #include I have to put...
See here and here.
maskaseb wrote:
For phisical direction I refer to the first information that you get if you do a ipconfig/all in a ms-dos window.
Don't you mean physical address?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Yes, you are ok.
Sorry, but I don´t have a very good english.
Thanks.
|
|
|
|
|
here is an example:
//AdaptersInfo.h
#if !defined __ADAPTERSINFO_H
#define __ADAPTERSINFO_H
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <string.h>
#include <assert.h>
#include <windows.h>
#include <Iphlpapi.h>
#define MYLIB_IP_MAX 5 // Max # of IP bind on ONE-adapter
#define MYLIB_GATEWAY_MAX 3 //Max # of Gateway for ONE-adapter
struct AdapterInfo{
char name[MAX_ADAPTER_NAME_LENGTH + 4];
char des[MAX_ADAPTER_DESCRIPTION_LENGTH + 4];//Description
UINT mac_len;
BYTE mac[MAX_ADAPTER_ADDRESS_LENGTH];
DWORD index;
UINT type;
int ips;
char ip[MYLIB_IP_MAX][16];
char ip_mask[MYLIB_IP_MAX][16];
int gateways;
char gateway[MYLIB_GATEWAY_MAX][16];
char gateway_mask[MYLIB_GATEWAY_MAX][16];
};
DWORD GetAdaptersInfo(struct AdapterInfo infos[], int& nArraySize);
#endif // !defined __ADAPTERSINFO_H
//AdaptersInfo.cpp
#include "AdaptersInfo.h"
DWORD GetAdaptersInfo(struct AdapterInfo infos[], int& nArraySize)
{
DWORD dwRet;
IP_ADAPTER_INFO pai[10];
ULONG ulSize = sizeof(pai);
int nAdapters = 0;
memset(infos, 0, sizeof(struct AdapterInfo) * nArraySize);
dwRet = ::GetAdaptersInfo(pai, &ulSize);
if(dwRet == ERROR_SUCCESS){
IP_ADAPTER_INFO* p = &pai[0];
while(p){
//Fill general info
strcpy(infos[nAdapters].name, p->AdapterName);
strcpy(infos[nAdapters].des, p->Description);
//Fill mac-address info
infos[nAdapters].mac_len = p->AddressLength;
memcpy(infos[nAdapters].mac, p->Address, p->AddressLength);
infos[nAdapters].index = p->Index;
infos[nAdapters].type = p->Type;
//Get IP info
int nIPs = 0;
IP_ADDR_STRING* pipList = &p->IpAddressList;
while(pipList && nIPs < MYLIB_IP_MAX){
strcpy(infos[nAdapters].ip[nIPs], pipList->IpAddress.String);
strcpy(infos[nAdapters].ip_mask[nIPs], pipList->IpMask.String);
nIPs++;
pipList = pipList->Next;
}
infos[nAdapters].ips = nIPs;
//Get gateway info
int nGateways = 0;
IP_ADDR_STRING* pGatewayList = &p->GatewayList;
while(pGatewayList && nGateways < MYLIB_GATEWAY_MAX){
strcpy(infos[nAdapters].gateway[nGateways], pGatewayList->IpAddress.String);
strcpy(infos[nAdapters].gateway_mask[nGateways], pGatewayList->IpMask.String);
nGateways++;
pGatewayList = pGatewayList->Next;
}
infos[nAdapters].gateways = nGateways;
nAdapters++;
p = p->Next;
}
}
nArraySize = nAdapters;
return dwRet;
}
//main.cpp
#include <iostream.h>
#include "../AdaptersInfo.h"
//DWORD GetHostIPs(struct AdapterInfo infos[], int& nArraySize)
int main()
{
struct AdapterInfo infos[10];
int n = 10;
DWORD dwEC;
dwEC = GetAdaptersInfo(infos, n);
for(int i = 0; i < n; i++){
int j;
cout << "Adapter [" << i + 1 <<"] info:" << endl;
cout << "\tName:" << infos[i].name << endl;
cout << "\tDescription:" << infos[i].des << endl;
cout << "\tMac address:";
cout.flush ();
for(j = 0; j < infos[i].mac_len ; j++)
printf("%02x%c", infos[i].mac[j], (j == (infos[i].mac_len - 1)) ? '\n' : ':');
cout << "\tIndex:" << infos[i].index << endl;
cout << "\tType:" << infos[i].type << endl;
for(j = 0; j < infos[i].ips; j++){
cout << "\tIP[" << j << "]:" << infos[i].ip[j];
cout << "(" << infos[i].ip_mask [j] << ")" << endl;
}
for(j = 0; j < infos[i].gateways; j++){
cout << "\tGateway[" << j << "]:" << infos[i].gateway[j];
cout << "(" << infos[i].gateway_mask [j] << ")" << endl;
}
cout << "-------------------------------------------" << endl;
}
return 0;
}
//---------- The End -----------------
|
|
|
|
|
Thank you very much. I´ll try it
|
|
|
|
|
It really works!!
Thank you very much.
Only one thing. It doesn´t work under Windows NT
Do you know if it will be possible to make it work under this OS?
Thanks another time
|
|
|
|
|
Hi All!
Problem in VC++ 6.0 with such error:
tmp2.obj : error LNK2005: "struct VLCtabTag * TMNMVtab0" (?TMNMVtab0@@3PAUVLCtabTag@@A) already defined in tmp1.obj
I got such files:
tmp1.cpp
<br />
#include "tmp1.h"<br />
VLCtab l;<br />
int main()<br />
{<br />
return 0;<br />
}<br />
------------------
tmp2.cpp
<br />
#include "tmp1.h"<br />
------------------
tmp1.h
#ifndef _TMP1_H<br />
#define _TMP1_H<br />
<br />
<br />
typedef struct VLCtabTag<br />
{<br />
int val, len;<br />
} VLCtab;<br />
<br />
VLCtab TMNMVtab0[] = { {1,1}, {2,2}, {3,3} };<br />
<br />
#endif // _TMP1_H
------------------
...uff that's all.
Any ideas? I'm really confused since #ifndef is used!
|
|
|
|
|
Ares2 wrote:
I'm really confused since #ifndef is used!
Which only matters when you are pre-compiling, not linking. tmp1.obj and tmp2.obj both have definitions for VLCtab TMNMVtab0 .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
...so what should i do in order to go on without this error?
|
|
|
|
|
Initialize the structure from one file only (e.g., tmp1.cpp or tmp2.cpp).
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
i moved line:
VLCtab TMNMVtab0[] = { {1,1}, {2,2}, {3,3} };
to tmp2.cpp file.
everything goes fine THANKS!!
Now i also added to tmp2.cpp file such line in main()
l[0].len = TMNMVtab0[0].len
...now structure is not visible for functions in tmp1.cpp some errors were displayed that he doesn't know what is it TMNVtab
i can add to tmp1.cpp file one more line:
extern VLCtab TMNMVtab0[];
but this is what i wanted to avoid.
i tried to manage such thing that after including eg. tmp1.h in several files, each file will see typedefs and declared variables. Is it possible somehow?
initialisation of these structures could be done in one of files that include it.
|
|
|
|
|
..ups sorry my mistake and missunderstanding
everything is now correct.
according to files described in my first post:
i moved with Your recommendation to tmp2.cpp
<br />
VLCtab TMNMVtab0[] = { {1,1}, {2,2}, {3,3} };<br />
i left in tmp1.h :
VLCtab TMNMVtab0[]
and everything works fine
Thank You verry much David!
|
|
|
|
|
I didn't compile this, but what about something like:
tmp1.cpp
#include "tmp1.h"
VLCtabTag l;
int main()
{
return 0;
}
------------------
tmp2.cpp
#include "tmp1.h"
extern struct VLCtabTag l;
VLCtabTag TMNMVtab0[] = { {1,1}, {2,2}, {3,3} };
l[0].len = TMNMVtab0[0].len;
------------------
tmp1.h
#ifndef _TMP1_H
#define _TMP1_H
typedef struct VLCtabTag
{
int val;
int len;
};
#endif // _TMP1_H
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
StretchDIBits problem with 16-bit (65536) colours
hello all,
my name is durval and i've the following problem in my project:
when the color-palette from the windows-desktop (properties)
16-bit (65536) is set. on ms-c++ print-preview (mfc) the
::StretchBlt(...)/::StretchDIBits(...)/::::BitBlt(...)
doesn't work properly. the bitmap is dividing in 2 parts, the
right (1/3 from the bitmap) will be put on the left place and
the left is displaced to the right.
at all the other color-settings there's no problem: 8-bit, 24-bit...
do you know this problem?
please, if everybody could help me, it would be very nice.
thanx a lot,
durval.
the code:
BOOL CDib::Draw(CDC* pDC, CPoint origin, CSize size)
{
if(m_lpBMIH == NULL) return FALSE;
if(m_hPalette != NULL)
::SelectPalette(pDC->GetSafeHdc(), m_hPalette, TRUE);
pDC->SetStretchBltMode(COLORONCOLOR);
// ::BitBlt( pDC->GetSafeHdc(), origin.x, origin.y, m_lpBMIH->biWidth, m_lpBMIH->biHeight, memDC.m_hDC, 0, 0, SRCCOPY );
// ::StretchBlt( pDC->GetSafeHdc(), origin.x, origin.y, size.cx, size.cy, memDC.m_hDC, 0, 0, m_lpBMIH->biWidth, m_lpBMIH->biHeight , SRCCOPY );
::StretchDIBits(pDC->GetSafeHdc(), origin.x, origin.y, size.cx, size.cy,
0, 0, m_lpBMIH->biWidth, m_lpBMIH->biHeight,
m_lpImage, (LPBITMAPINFO) m_lpBMIH, DIB_RGB_COLORS, SRCCOPY);
return TRUE;
}
-------------------------------------------------------------------
system:
Microsoft (R) Windows NT (TM) Workstation
Version 4.0 (Build 1381: Service Pack 6) x86 Uniprocessor Free
-------------------------------------------------------------------
graphic:
BIOS-Datum: 11/17/20
BIOS-Version: Video memory: 1 MB Device Revision: 2.0
Hardware Version 0.0
Adapter:
Setting: 1280 x 1024 x 65536 75 Hz
Typ: i81xnt4-kompatible Grafikkarte
Description: Intel815 Video Accelerator
Memory: 4 MB
Chip-Typ: Intel815
DAC-Typ: Internal
Driver:
Company: <n a="">
Datei(en): i81xnt4.sys, i81xdnt4.dll
Version: <n a="">, 4.0.32
|
|
|
|
|
Hello.
Is there a portable way to obtain cpu usage counter
on Win32 platform ? "portable" means it will work
on NT as well as on '9x.
Thanks,
Max.
|
|
|
|
|
Simple answer AFAIK is no.
However, if I remember correctly there is that tool in win 98 system tools which will montior and optionally record to a log file all the data you would ever want to know, including CPU usage. If i'm not loosing my mind and this tool does exist (it's been a while since I used 98) you could parse it's log file and get CPU usage that way. Other than that I think it's next to impossible under 98 without using VxD's or something. Unless there is some undocumented API in 98 that the tool uses, I dunno
Cheers
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
OK, thanks. And further question - how to do it
in WinNT/2k/xp ? The easiest way ? (phd funcs
are quite complex)
Max.
|
|
|
|
|
I create a form in VC like this
CHECKBOX1 TEXTBOX1
CHECKBOX2 TEXTBOX2
....
CHECKBOX9 TEXTBOX9
in init, i want all that objects are disable, whenever user checks on any check box, the next textbox will be enable. Becase i have many checkbox and textbox, i don't know to create a function which i can use for all the group (checkbox and textbox)
Please help me!!
Thien Thanh
azury_thanh@yahoo.com
|
|
|
|
|
If all you have is 9 checkboxes, using the ON_BN_CLICKED() handler is not out-of-line. Or you can look at the ON_CONTROL_RANGE() handler.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hey, I've createt an axtiveX Control which shows a modeless dialog. Now my Control should notify the containerapp when there a changes in dialogs items. I tried to send a message from my dialogclass to the parent (ControlClass) but nothing happend. How can I notify my ControlClass from within my DialogClass?
|
|
|
|
|
You can notify the container application of an ActiveX control by fireing events to it. In order to create them, you should create an Event Map (very much like a Message Map in a "normal" MFC app) between your events and functions.
Look up BEGIN_EVENT_MAP, END_EVENT_MAP macros , and Add Event Wizard.
Peter Molnar
|
|
|
|
|
Thank you,
but only the Controll_Class can fire event's. My problem is to notify the controll_class from within my dialog_class. I tried to send messages but it didn't work. I created a PreTranslation -function in my controll-class, but no messages from the dialog_class reached the controll_class.
|
|
|
|
|
Sorry, I must have misunderstood you.
Your problem can then be led to communicating between modeless dialog and its creator thread.
For this you will have to be able to call the creator thread's functions, which is only possible if you pass a pointer of your creator thread to the modeless dialog. Using this pointer you post messages from the modeless dialog which can be caught in the control class.
Try the following:
1.Add to your modeless dialog (in the header file):
#define WM_SEND_MY_MESSAGE (WM_USER + 1)
COleControl* m_pCreator;
void inline SetCreatorThreadPointer(COleControl* pCreator) {m_pCreator = pCreator;};
2.Add to your control class a message handler:
ON_MESSAGE(WM_SEND_MY_MESSAGE, OnModelessDialogSend)
and also implement the function with prototype OnModelessDialogSend(WPARAM wParam, LPARAM lParam); From here you will fire your events.
3.In your control class:
m_pDialog->SetCreatorThreadPointer(this);
m_pDialog->Create(...);
4.In your modeless dialog, when your message occurs, post a message to your control class:
m_pCreator->PostMessage( WM_SEND_MY_MESSAGE, (WPARAM)"Hi!");
Peter Molnar
|
|
|
|
|