|
Might just come in Handy
Click ME[^]
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
hello everybody,
here is a problem..
how to enumerate the name & it's IP addresses of devices(both Input & Output) in the personal system as well as to the network using WIN32 APIs & VC++ ???
if any body have snipet of code ,please give ...
thanking
skpanda
|
|
|
|
|
hello sir,
here is the bit clarification what i need actually.
i have to enumerate all the devices(both input as well as output devices) like printer,cdrom,flopy disk,monitor,keyboard,mouse etc... .with all the network resources like switch,modem,router...etc...
i have to enumerate these with IP address or without ...if it is not available with name .so please carify which win32 api function is suitable to this...please inform me earlier...
here r some function which i have gone through msdn
wnetenumresource
WNetOpenEnum
shall i use these...
if yes how just give me a snipet of code ....
waiting
skpanda
|
|
|
|
|
is the function call in main correct ???
please rectify it...
// iodevices.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "windows.h"
#include "Winnetwk.h"
//#include "display.h"
BOOL WINAPI NetErrorHandler(HWND hwnd,
DWORD dwErrorCode,
LPSTR lpszFunction);
BOOL WINAPI EnumerateFunc(HWND hwnd,
HDC hdc,
LPNETRESOURCE lpnr);
int main(int argc, char* argv[])
{
// NETRESOURCE nr;
EnumerateFunc(NULL,NULL,NULL);
return 0;
}
BOOL WINAPI NetErrorHandler(HWND hwnd,
DWORD dwErrorCode,
LPSTR lpszFunction)
{
DWORD dwWNetResult, dwLastError;
CHAR szError[256];
CHAR szCaption[256];
CHAR szDescription[256];
CHAR szProvider[256];
// The following code performs standard error-handling.
if (dwErrorCode != ERROR_EXTENDED_ERROR)
{
wsprintf((LPSTR) szError, "%s failed; \nResult is %ld",
lpszFunction, dwErrorCode);
wsprintf((LPSTR) szCaption, "%s error", lpszFunction);
MessageBox(hwnd, (LPSTR) szError, (LPSTR) szCaption, MB_OK);
return TRUE;
}
// The following code performs error-handling when the
// ERROR_EXTENDED_ERROR return value indicates that the
// WNetGetLastError function can retrieve additional information.
else
{
dwWNetResult = WNetGetLastError(&dwLastError, // error code
(LPSTR) szDescription, // buffer for error description
sizeof(szDescription), // size of error buffer
(LPSTR) szProvider, // buffer for provider name
sizeof(szProvider)); // size of name buffer
//
// Process errors.
//
if(dwWNetResult != NO_ERROR) {
wsprintf((LPSTR) szError,
"WNetGetLastError failed; error %ld", dwWNetResult);
MessageBox(hwnd, (LPSTR) szError,
"WNetGetLastError", MB_OK);
return FALSE;
}
//
// Otherwise, print the additional error information.
//
wsprintf((LPSTR) szError,
"%s failed with code %ld;\n%s",
(LPSTR) szProvider, dwLastError, (LPSTR) szDescription);
wsprintf((LPSTR) szCaption, "%s error", lpszFunction);
MessageBox(hwnd, (LPSTR) szError, (LPSTR) szCaption, MB_OK);
return TRUE;
}
}
BOOL WINAPI EnumerateFunc(HWND hwnd,
HDC hdc,
LPNETRESOURCE lpnr)
{
DWORD dwResult, dwResultEnum;
HANDLE hEnum;
DWORD cbBuffer = 16384; // 16K is a good size
DWORD cEntries = -1; // enumerate all possible entries
LPNETRESOURCE lpnrLocal; // pointer to enumerated structures
DWORD i;
//
// Call the WNetOpenEnum function to begin the enumeration.
//
dwResult = WNetOpenEnum(RESOURCE_CONNECTED, // all network resources
RESOURCETYPE_ANY, // all resources
0, // enumerate all resources
NULL, // NULL first time the function is called
&hEnum); // handle to the resource
if (dwResult != NO_ERROR)
{
//
// Process errors with an application-defined error handler.
//
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetOpenEnum");
return FALSE;
}
//
// Call the GlobalAlloc function to allocate resources.
//
lpnrLocal = (LPNETRESOURCE) GlobalAlloc(GPTR, cbBuffer);
do
{
//
// Initialize the buffer.
//
ZeroMemory(lpnrLocal, cbBuffer);
//
// Call the WNetEnumResource function to continue
// the enumeration.
//
dwResultEnum = WNetEnumResource(hEnum, // resource handle
&cEntries, // defined locally as -1
lpnrLocal, // LPNETRESOURCE
&cbBuffer); // buffer size
//
// If the call succeeds, loop through the structures.
//
if (dwResultEnum == NO_ERROR)
{
for(i = 0; i < cEntries; i++)
{
// Call an application-defined function to
// display the contents of the NETRESOURCE structures.
//
// DisplayStruct(hdc, &lpnrLocal[i]);
// If the NETRESOURCE structure represents a container resource,
// call the EnumerateFunc function recursively.
if(RESOURCEUSAGE_CONTAINER == (lpnrLocal[i].dwUsage
& RESOURCEUSAGE_CONTAINER))
if(!EnumerateFunc(hwnd, hdc, &lpnrLocal[i]))
TextOut(hdc, 10, 10, "EnumerateFunc returned FALSE.", 29);
}
}
// Process errors.
//
else if (dwResultEnum != ERROR_NO_MORE_ITEMS)
{
NetErrorHandler(hwnd, dwResultEnum, (LPSTR)"WNetEnumResource");
break;
}
}
//
// End do.
//
while(dwResultEnum != ERROR_NO_MORE_ITEMS);
//
// Call the GlobalFree function to free the memory.
//
GlobalFree((HGLOBAL)lpnrLocal);
//
// Call WNetCloseEnum to end the enumeration.
//
dwResult = WNetCloseEnum(hEnum);
if(dwResult != NO_ERROR)
{
//
// Process errors.
//
NetErrorHandler(hwnd, dwResult, (LPSTR)"WNetCloseEnum");
return FALSE;
}
return TRUE;
}
skpanda
|
|
|
|
|
Pande ji ,
try this
Click ME[^]
Live as if your were to die tomorrow. Learn as if you were to live forever.
-Mahatma Gandhi
|
|
|
|
|
hello monty sir,
Click Me[^] is not working ...
please give the url correctly and please tell me how to enumerate all input /output devices in a network as well as local computer ...where the application is running...
waiting your response now ...
skpanda
|
|
|
|
|
|
hello,
but i want to enumerate all network resources, like SWITCH,ROUTER connected , etc....how to do that ??any idea ??
please guide...
thanking u ...
skpanda
|
|
|
|
|
I use below code:
HWND hdesk = ::FindWindow("Progman", NULL);
hdesk = ::FindWindowEx(hdesk, 0, "SHELLDLL_DefView", NULL);
hdesk = ::FindWindowEx(hdesk, 0, "SysListView32", NULL);
HIMAGELIST hImageList = (HIMAGELIST)::SendMessage(hdesk, LVM_GETIMAGELIST, 0, 0);
but the hImageList count always return 0, why?
|
|
|
|
|
Thanks buddy. but a small problem i couldn't get "drw_dxf.h" which U've included.
awaiting Ur reply
|
|
|
|
|
Im working on app that will keep lists of things in a ini file from edit boxes on a dialogs.
I already know about CEdit and WritePrivateProfileStrings things.
but I need things to be listed like this. also I will add ability to delete.
mIRC does this same way with the servers.ini and alias.ini
[thing]
n0=here
n1=food
n2=metal
n3=hotdogs
n4=metals
n5=pencils
n6=pens
n7=paint
for your info. Im using MFC to make my program in Visual C++ 6.0.
here is my example of program
http://adamc.hypermart.net/TESTSTRINGS.zip
|
|
|
|
|
Not sure I understand, why is WritePrivateProfileString() insufficient for your app? The INI file looks like you describe, and WritePrivateProfileString() can delete entries or whole sections.
--Mike--
Ericahist | CP SearchBar v2.0.2 | Homepage | 1ClickPicGrabber New v2.0! | RightClick-Encrypt
There is a saying in statistics that a million monkeys pounding on typewriters would eventually create a work of Shakespeare. Thanks to the Internet, we now know that this is not true.
|
|
|
|
|
http://adamc.hypermart.net/TESTINI.zip
here is my app
my friend told me to use loop in that testini() section.
it do not work.
look for this section.
void CINIFileTestDlg::OnTestini()
{
// TODO: Add your control notification handler code here
char sIniFile[MAX_PATH];
GetModuleFileName( NULL, sIniFile, MAX_PATH );
strcpy( strrchr( sIniFile, '\\' ) + 1, "TESTTT.ini" );
char buffer[1024];
///for(int x=0; x < GetnCount(); ++x)
for(int x=0; x < GetnCount(); ++x)
{
sprintf(buffer,"n%d",x);
WritePrivateProfileString("TEST", buffer, "STRING", sIniFile);
}
m_ncount++;
|
|
|
|
|
Ok. I am assuming that in your OnTestini() method, you want to READ from the .INI file, to test out the fact that it was created?
So, if that is the case. What you need to do is a call to GetPrivateProfileString(). That will read the .INI file for you and populate a variable.
It appears as though you are using a class that someone else created to do your Write/Get to the .INI file. If you are trying to do a basic .INI file, this is unnecessary because you can use the built in methods GetPrivateProfileString() and WritePrivateProfileString() yourself to do the task!
So, first off, lets take the code that you have now, and make a little modification to the OnTestini() method. Lets make this method actually read values from the .INI file. I am adapting this so it looks just like your current code. How this works is this. You run your app. Type in c:\test.ini in the filename.ini editbox (You must use a relative path or GetPrivateProfileString() may fail depending on where it gets run from). Type in something for the section/name and value fields. Then, press MAKE INI. It will create c:\test.ini for you. (That part in your code worked OK). Next, if you want to be sure, delete out the value that you typed in for the key value. Then, press TEST INI button. What happens is the following code figures out which key you want from your editboxes and then tries a GetPrivateProfileString() to get that data for you. (And it will succeed too!). It'll then give you a MessageBox with the key value. The code modification is below...
Also, what I would recommend is doing something like this. Start a new MFC dialog based app. Add a test ini and a make ini button along with your edit boxes. After you've created the editboxes, right click anywhere on the dialog you are creating, and select ClassWizard from the menu that pops up. Then, click on the Member Variables Tab. Scroll down to your IDC_EDIT1 and click on Add Variable. It'll ask for the member variable name, type something in there like m_fileName. Leave the default values in there for the rest (Category: Value and Variable Type: CString) Then, do that for each of your editboxes, do some variables like m_secName, m_keyName, m_keyValue. Once you do that, you can then access m_fileName,m_secName,m_keyName,m_keyValue from any member method of your class. So currently you have things like this:
CEdit* getsection = (CEdit*)GetDlgItem(IDC_EDIT7);
getsection->GetWindowText(putsection);
MessageBox(putsection); // Shows whatever was in IDC_EDIT7 edit box
If you do what I am suggesting, you can then do this in your code.
UpdateData(TRUE); // Do this ONCE before you try to access this variable.
MessageBox(m_keyName); // Shows whatever was in that edit box!
Then, once you have that in place, you can create your INI file like this
WritePrivateProfileString(m_secName,m_keyName,m_keyValue,m_fileName);
Then, when you want to read a value:
char buf[80];
GetPrivateProfileString(m_secName,m_keyName,"A DEFAULT VALUE",buf,80,m_fileName);
MessageBox(m_keyName + " in the ini file has a value of " + buf);
It's as simple as that! The "A DEFAULT VALUE" is a default value to use in case the read failed. (IE It can't find the section or key that you are looking for, so it returns a default value)
Drop a line if something does not make sense. Hopefully I explained it enough!
-Shultas
void CINIFileTestDlg::OnTestini()
{
// TODO: Add your control notification handler code here
char buffer[1024];
char sIniFile[MAX_PATH];
CEdit* getfilename = (CEdit*)GetDlgItem(IDC_EDIT1);
CString putfilename;
getfilename->GetWindowText(putfilename);
CEdit* getsection = (CEdit*)GetDlgItem(IDC_EDIT7);
CEdit* getname = (CEdit*)GetDlgItem(IDC_EDIT2);
CString putsection;
CString putname;
char myBuf[80];
getsection->GetWindowText(putsection);
getname->GetWindowText(putname);
//WritePrivateProfileString(putsection,putname,"key value here","test.ini");
GetPrivateProfileString(putsection,putname,"default value",myBuf,80,putfilename);
MessageBox(myBuf);
}
|
|
|
|
|
Please again check out my new program....
there is problem with loop ;/
it should only do that thing ONE time each time you press 'add string' button.
at this time im not using anyone's class.
http://adamc.hypermart.net/TESTSTRINGS.zip
|
|
|
|
|
Okie. I had a look and I see the problem. First off, what exactly is it that you are trying to do with your program? Then I can be direct and show you the code necessary.
For now, I'll show you what is wrong with the loop.
Here's your code:
int m_ncount = 1;
CString KeyName;
for(int x=0; x < m_ncount; ++x)
{
KeyName.Format("n%ld", x);
///WritePrivateProfileString("TEST", buffer, putstring, sIniFile);
WritePrivateProfileString("TEST", KeyName, putstring, sIniFile);
m_ncount++;
}
If you look carefully, you will see the reason your program locks up is because you have created an infinate loop! The condition "x < m_ncount" will never be true, because you are incrementing the m_ncount variable at the end of the loop! So, the first time that the loop runs,
m_ncount=1 and x=0. The second pass, m_ncount=2; x=1 ... Third pass, m_ncount=3;x=2. So each pass, the variable x gets incremented and so does the variable m_ncount! So therefore the loop will run forever!
Post back and let me know what you are trying to do and I'll throw something together for you real fast to take example of!
Shultas
|
|
|
|
|
Im trying to make it increament the strings like this each time you press the button.
n0=string1
n1=string2
n2-string3
n3=string4
I know what problem im having ;/
Im not sure how to do it right way.
|
|
|
|
|
Okay. Gotcha.
What I would do is this. Open up your classview and add a new member to the declaration of your CTESTINI2Dlg.
class CTESTINI2Dlg : public CDialog
{
.......
.......
protected:
HICON m_hIcon;
int topKeyValue; // <------ Add this in there
Then, expand the view for the CTESTINI2Dlg. Double click on the OnInitDialog() method.
Look for the following lines (at the end of this method)
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
topKeyValue = 0; // <----------- Add that in there
Then, double click on your OnAddStrings() method. This should go in there INSTEAD of the for{} loop. Get rid of that loop.
void CTESTINI2Dlg::OnAddstrings()
{
char sIniFile[MAX_PATH];
GetModuleFileName( NULL, sIniFile, MAX_PATH );
strcpy( strrchr( sIniFile, '\\' ) + 1, "strings.ini" );
CEdit* getstring = (CEdit*)GetDlgItem(IDC_EDIT4);
CString putstring;
getstring->GetWindowText(putstring);
CString KeyName;
topKeyValue++;
KeyName.Format("n%ld", topKeyValue);
WritePrivateProfileString("TEST", KeyName, putstring, sIniFile);
MessageBox("Added...");
}
Okay. What this does is add an integer variable to your CTESTINI2Dlg class named topKeyValue. Then, in your OnInitDialog() code, topKeyValue = 0; that is initializing it to 0 when the program starts up. Then, in your OnAddstrings() method, topKeyValue++ increments the member variable by one, formats it in the KeyName.Format string, and writes that number accordingly. Each time you press the add strings button, topKeyValue gets incremented by 1, thus allowing you to write a new line into the file!
So, what are you trying to do, screw with someones MIRC INI files?
|
|
|
|
|
[quote] So, what are you trying to do, screw with someones MIRC INI files? [/quote]
Nope
Im working on making my own irc client.
thats why Im trying to figure out those stuff.
|
|
|
|
|
Im trying to build same application as Zion mirc editor
http://adamc.hypermart.net/Zion.zip
look carefully and see how it does with writing and saving ini files.
I know its in spanish ? but you can understand how the program works.
I think its MFC app.
I cant find source codes of similar programs.
|
|
|
|
|
lol. One heck of a guess on my part, huh?
I did get a chance to look at the app but really don't know what it is supposed to do and whatnot? Is it that you are maybe looking to add entries to server names, or channel names or something like that? What you have to do is look at the INI (as you've already done, obviously) and figure out exactly which fields you want to be able to modify. Take the mirc.ini for example. Lets say you wanted to modify [chanfolder] and add/edit/delete entries in there.
I'll give you a starting point. First you would need to perform GetPrivateProfileString() on the [chanfolder] section until you reached the end. I would do that with some code like this:
void CYOUR_DIALOG_NAME_HEREDlg::OnButton1()
{
char curKey[80], keyName[80];
m_topChanEntries = 0;
while (1) {
sprintf(keyName,"n%d",m_topChanEntries);
GetPrivateProfileString("chanfolder",keyName,"DEFAULT",curKey,80,"c:\\program files\\mirc\\mirc.ini");
if (strstr(curKey,"DEFAULT")) {
// MessageBox("Reached the top number...");
m_topChanEntries--;
break;
}
// populate whatever controls you want to here with the current values
m_topChanEntries++;
}
// Out of the loop -- variable "m_topChanEntries" now contains the # of entries in the
//[chanfolders] section.
}
Of course, during the run, you will want to populate your editbox, listbox, or whatever boxes you are choosing to perform the editing on. If there are 30 entries in there, the while loop will go 30 times, then the strstr() portion will figure out that there are no more entries (because "DEFAULT" will be in there, because GetPrivateProfileString() could not get #31).
That should be a good starting point for you to work with. What you would have to do for this to work is create an int member variable in your class delcaration under the protected section. Also, in your OnInitDialog() method, be sure to initialize this variable to 0. This way, after this button press code is finished executing, that variable will hold the number of entries currently in that [chanfolders] section. This way, you could add another button to, lets say, add another channel to the list, and then in that code you would just do something such as:
sprintf(keyName,"n%d",++m_topChanEntries); // this increments the topChanEntries number first
WritePrivateProfileString(...);
Hope that helps!
Shultas
|
|
|
|
|
now i figured out how to do addstrings and stuff
now I have one problem is
how to delete strings correctly onuce you selected the string in combobox ?
here is my updated app.
http://adamc.hypermart.net/TESTSTRINGS2.zip
|
|
|
|
|
int npick;
npick = m_list.GetCurSel();
That's what you have so far. To get the actual TEXT of the string that is in the listbox, you would do
char keyName[80];
m_ListBox.GetText(npick,keyName);
keyName will then have whatever value you selected in the listbox.
You can then use the WriteProfileString() with a NULL in the value field to delete that keyName
Shultas
|
|
|
|
|
Do you know how to use serialization and stuff to do those stuff..
I was reading the sams book and serialization would do similar job.
I think khaled use serialization in mIRC for alias.ini and servers.ini and mirc.ini
|
|
|
|
|
Compiling...
TESTINI2Dlg.cpp
E:\-= IRC CLIENTS =-\TESTSTRINGS2\TESTINI2Dlg.cpp(410) : error C2039: 'GetText' : is not a member of 'CComboBox'
d:\microsoft visual studio\vc98\mfc\include\afxwin.h(2893) : see declaration of 'CComboBox'
Error executing cl.exe.
TESTINI2.exe - 1 error(s), 0 warning(s)
hmmmmmmmmmm
|
|
|
|
|