Click here to Skip to main content
15,895,084 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralMessages problems Pin
Atlence25-Dec-03 22:20
Atlence25-Dec-03 22:20 
GeneralRe: Messages problems Pin
valikac26-Dec-03 5:38
valikac26-Dec-03 5:38 
GeneralRe: Messages problems Pin
Atlence26-Dec-03 14:06
Atlence26-Dec-03 14:06 
Generalabout ScrollBar... Pin
Grrrr25-Dec-03 20:56
Grrrr25-Dec-03 20:56 
GeneralRe: about ScrollBar... Pin
Monty225-Dec-03 21:23
Monty225-Dec-03 21:23 
Questionhow to enumerate Input/Output devices ??? Pin
skpanda25-Dec-03 20:43
skpanda25-Dec-03 20:43 
AnswerRe: how to enumerate Input/Output devices ??? Pin
skpanda26-Dec-03 18:36
skpanda26-Dec-03 18:36 
GeneralRe: how to enumerate Input/Output devices ??? Pin
skpanda26-Dec-03 21:22
skpanda26-Dec-03 21:22 
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
AnswerRe: how to enumerate Input/Output devices ??? Pin
Monty226-Dec-03 23:35
Monty226-Dec-03 23:35 
GeneralRe: how to enumerate Input/Output devices ??? Pin
skpanda28-Dec-03 18:31
skpanda28-Dec-03 18:31 
GeneralRe: how to enumerate Input/Output devices ??? Pin
Monty228-Dec-03 21:01
Monty228-Dec-03 21:01 
GeneralRe: how to enumerate Input/Output devices ??? Pin
skpanda1-Jan-04 23:08
skpanda1-Jan-04 23:08 
QuestionHow to get all desktop icons? Pin
ioat25-Dec-03 19:16
ioat25-Dec-03 19:16 
GeneralRegarding drw_dxf.h Pin
cithu25-Dec-03 18:22
cithu25-Dec-03 18:22 
Questionhow to write and save ini files like some apps do with their ini's Pin
ELY M.25-Dec-03 18:04
ELY M.25-Dec-03 18:04 
AnswerRe: how to write and save ini files like some apps do with their ini's Pin
Michael Dunn25-Dec-03 19:12
sitebuilderMichael Dunn25-Dec-03 19:12 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
ELY M.25-Dec-03 21:24
ELY M.25-Dec-03 21:24 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
shultas26-Dec-03 4:27
shultas26-Dec-03 4:27 
AnswerRe: how to write and save ini files like some apps do with their ini's Pin
ELY M.26-Dec-03 12:49
ELY M.26-Dec-03 12:49 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
shultas26-Dec-03 14:01
shultas26-Dec-03 14:01 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
ELY M.26-Dec-03 14:44
ELY M.26-Dec-03 14:44 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
shultas26-Dec-03 16:10
shultas26-Dec-03 16:10 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
ELY M.26-Dec-03 18:42
ELY M.26-Dec-03 18:42 
AnswerRe: how to write and save ini files like some apps do with their ini's Pin
ELY M.26-Dec-03 16:01
ELY M.26-Dec-03 16:01 
GeneralRe: how to write and save ini files like some apps do with their ini's Pin
shultas26-Dec-03 17:03
shultas26-Dec-03 17:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.