|
Hi
I am calling a dialog box including a list control window.
This dialog box has computer names in local network.
I'ts using 'WNetOpenEnum' and 'WNetEnumResource' APIs.
Now I have used this code successfully in Windows 2000/XP.
But these codes got empty in Windows 98.
Nothing in list control.
Is a problem of network setting or not enough APIs to get names?
How can I do that?
anyone any ideas ?
Help me plz.
---- source list ---
void CNetworkDlg::SearchLocalPc(void)
{
// WNetOpenEnum parameter
DWORD dwScope = RESOURCE_CONTEXT;
NETRESOURCE *NetResource = NULL;
HANDLE hEnum;
// WNetOpenEnum for Windows 98. but Nothing in return value
unsigned long strWNetMSG = WNetOpenEnum(dwScope, RESOURCETYPE_ANY, NULL, NULL, &hEnum);
// for error
switch(strWNetMSG)
{
case NO_ERROR:
break;
case ERROR_NOT_CONTAINER:
AfxMessageBox("ERROR");
break;
case ERROR_INVALID_PARAMETER:
AfxMessageBox("ERROR");
break;
case ERROR_NO_NETWORK:
AfxMessageBox("ERROR");
break;
case ERROR_EXTENDED_ERROR:
AfxMessageBox("ERROR");
break;
default :
AfxMessageBox("ERROR");
return ;
}
// SOCKET creation
WSADATA wsaData;
WSAStartup(MAKEWORD(1, 1),&wsaData);
// if WNetOpenEnum success
if (hEnum)
{
// for WNetEnumResource
DWORD dwCount = 0xFFFFFFFF;
DWORD dwBufferSize = 16384;
LPVOID lpBuffer = new char[16384];
// continues a network-resource enumeration but Nothing in return value
unsigned long strWNetResourceMSG = WNetEnumResource(hEnum, &dwCount, lpBuffer, &dwBufferSize);
NetResource = (NETRESOURCE*)lpBuffer;
// for error
switch(strWNetResourceMSG)
{
case ERROR_MORE_DATA:
AfxMessageBox("ERROR");
break;
case ERROR_INVALID_HANDLE:
AfxMessageBox("ERROR");
break;
case ERROR_NO_NETWORK:
AfxMessageBox("ERROR");
break;
case ERROR_EXTENDED_ERROR:
AfxMessageBox("ERROR");
break;
default:
break;
}
if(m_ListSearchPc.GetItemCount() != 0)
m_ListSearchPc.DeleteAllItems();
m_dwCountTotalPc = 0;
for(unsigned int i = 0; i < dwCount; i++, NetResource++)
{
if (NetResource->dwUsage == RESOURCEUSAGE_CONTAINER && NetResource->dwType == RESOURCETYPE_ANY)
{
if (NetResource->lpRemoteName)
{
CString strFullName = NetResource->lpRemoteName;
if (strFullName.Left(2).Compare("\\\\") == 0)
strFullName = strFullName.Right(strFullName.GetLength() - 2);
if(strFullName.IsEmpty())
continue;
// 1. add number to list contorl
CString pcNo;
pcNo.Format("%d", m_dwCountTotalPc + 1);
m_ListSearchPc.InsertItem(m_dwCountTotalPc, pcNo);
// 2. add pc aname to list control
strFullName.MakeLower();
m_ListSearchPc.SetItemText(m_dwCountTotalPc, 1, (LPCTSTR)strFullName);
m_dwCountTotalPc++;
}
}
}
delete lpBuffer;
WNetCloseEnum(hEnum);
}
WSACleanup();
CString total;
total.Format("%d", m_dwCountTotalPc);
CString PopupMessage;
PopupMessage = "Number of Total Pc :";
PopupMessage += total;
SetDlgItemText(IDC_TEXT_LOCALPC_EA, LPCTSTR (PopupMessage));
UpdateData(FALSE);
}
|
|
|
|
|
When you say "nothing in return value," does that mean that WNetOpenEnum() is returning NO_ERROR ?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Yes. WNetOpenEnum() is returning NO_ERROR.
|
|
|
|
|
I did not find anything exceptionally wrong. See if any of these minor changes make a difference:
void CNetworkDlg::SearchLocalPc(void)
{
WSADATA wsaData;
CString strText;
DWORD dwResult = 0,
dwCount = 0xffffffff,
dwBufferSize = 16384,
dwIndex = 0;
int nItem;
LPNETRESOURCE lpNetResource = NULL;
HANDLE hEnum;
LPVOID lpBuffer;
m_ListSearchPc.DeleteAllItems();
dwResult = WSAStartup(MAKEWORD(1, 1), &wsaData);
if (0 == dwResult)
{
dwResult = WNetOpenEnum(RESOURCE_CONTEXT, RESOURCETYPE_ANY, NULL, NULL, &hEnum);
if (NO_ERROR == dwResult && NULL != hEnum)
{
lpBuffer = new BYTE[dwBufferSize];
dwResult = WNetEnumResource(hEnum, &dwCount, lpBuffer, &dwBufferSize);
if (NO_ERROR == dwResult && dwCount > 0)
{
lpNetResource = (LPNETRESOURCE) lpBuffer;
while (dwIndex < dwCount && NULL != lpNetResource)
{
if (RESOURCEUSAGE_CONTAINER & lpNetResource->dwUsage && RESOURCETYPE_ANY == lpNetResource->dwType)
{
if (lpNetResource->lpRemoteName)
{
strText.Format(_T("%lu"), dwIndex);
nItem = m_ListSearchPc.InsertItem(dwIndex, strText);
strText = lpNetResource->lpRemoteName;
if (_T("\\\\") == strText.Left(2))
strText.Delete(0, 2);
strText.MakeLower();
m_ListSearchPc.SetItemText(nItem, 1, strText);
dwIndex++;
}
}
lpNetResource++;
}
strText.Format(_T("Number of Total PC: %lu"), dwIndex);
SetDlgItemText(IDC_TEXT_LOCALPC_EA, strText);
}
delete [] lpBuffer;
}
dwResult = WSACleanup();
}
if (dwResult != 0)
{
strText.Format(_T("Error: %lu"), dwResult);
m_ListSearchPc.InsertItem(0, strText);
}
}
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
hi all
i use the below to create a modeless dialog which works ok
CCPServerWait* m_pWaitDlg;
m_pWaitDlg = new CCPServerWait;
m_pWaitDlg->Create(IDD_DCPSERVER_WAIT);
m_pWaitDlg->m_wait_mes = "Connecting to CMIS Please
m_pWaitDlg->UpdateData(FALSE);
m_pWaitDlg->ShowWindow(SW_SHOW);
m_pWaitDlg->UpdateWindow();
m_pWaitDlg->DestroyWindow();
but before i use this code; i need to call the function
ok = SQLCreateDataSource(m_hWnd,"CP_CMIS_CON");
with this in, the code for the modeless dialog doesnt work
if i take it out then the code for the modeless dialog does work,
obviously i need it in, can ne1 help ???
si
|
|
|
|
|
si_69 wrote:
m_pWaitDlg->UpdateWindow();
There is no need to call UpdateWindow() here.
si_69 wrote:
the code for the modeless dialog doesnt work
Define "doesnt work." Have you single-stepped through each line of code?
The code you've shown does not appear to do anything other than create a dialog object and then destroy it. I can't imagine it being on the screen any longer than a quick flash, if that long. The last time I used one, there was some (lengthy) processing going on in between the calls to ShowWindow() and DestroyWindow() .
http://www.codeproject.com/script/comments/forums.asp?forumid=1647&select=857875&df=100&fr=101#xx857875xx
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Does anyone know how to detect a CDatabase disonnection?
I'm inserting rows into a database and when it disconnects it throws a CDBException with return code of type 'SQL_ERROR'. This is the same error code for all SQL errors e.g. primary key violation etc.
I want to detect a disconnection, then attempt a reconnect but can't figure out how to specifically detect a disconnection?
Can anyone help?
|
|
|
|
|
What really happen when I convert my VS 6.0 (C++) project to a VS .NET project. May I then take advantage of some .NET “stuff”?
Are there any reason for me to start using VS .NET except for a nicer editor?
All tips are welcomed!
_____________________________
...and justice for all
APe
|
|
|
|
|
What really happen when I convert my VS 6.0 (C++) project to a VS .NET project. May I then take advantage of some .NET “stuff”?
Only if your existing project uses it, or else .NET won't be called.
Are there any reason for me to start using VS .NET except for a nicer editor?
My personal opinion,
Pros: Better compiler and linker (claimed that the executables generated by VC7 run faster than VC6 in Dr Dobb's Journal), better STL conformance, upgraded debugger.
Cons: Slower interface compares to VC6, no more class wizard.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Anthony_Yio wrote:
no more class wizard
I've found that irritating too. Anyway, I guess I still can do all that class-wisard did in some other way?
_____________________________
...and justice for all
APe
|
|
|
|
|
Anyway, I guess I still can do all that class-wisard did in some other way?
Of course, there are. Just that the functions are not in the same place. A few ways to access the class wizard functions. In VS 2003, I am not sure of others. One, is via your properties window - control event button when you have selected your resources, this allow you to select the event handler you need.
and second, is by right click on your resources. You will notice, Add Varible or Add Event Handler menu enabled.
For more details, check out their dynamic help.
Sonork 100.41263:Anthony_Yio
|
|
|
|
|
Good to hear! Tahnks
_____________________________
...and justice for all
APe
|
|
|
|
|
Hi,
I would like to connect do a DSN (data source name) through my code in C++, but I don't want to write the UserName and Password in my code: how can I do??
Here it is my code:
static bool IsSubscribed(SQLCHAR Account[], bool& subscription, bool& warning)
{
SQLHENV henv = NULL;
SQLHDBC hdbc = NULL;
SQLHSTMT hstmt = NULL;
SQLRETURN sRet;
PTSTR szDataSource = _T("DSN_NAME");
PTSTR szUID = _T("UserName");
PTSTR szPWD = _T("Password");
// Initialize the ODBC environment.
if (SQLAllocHandle(SQL_HANDLE_ENV, NULL, &henv) == SQL_ERROR)
{
WriteIntoFile("ERRORE Initialize the ODBC environment");
return false;
}
SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*) SQL_OV_ODBC3,SQL_IS_INTEGER);
// Allocate a connection handle and connect to the data source.
if (SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc) == SQL_ERROR)
{
WriteIntoFile("ERRORE Allocate a connection handle");
return false;
}
if (SQLConnect(hdbc, (SQLTCHAR*) szDataSource, SQL_NTS,
(SQLTCHAR*) szUID, SQL_NTS, (SQLTCHAR*) szPWD, SQL_NTS) == SQL_ERROR)
{
WriteIntoFile("ERRORE Connect to the DataSource");
return false;
}
// Get a statement handle and execute a Transact-SQL SELECT statement
if (SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt) == SQL_ERROR)
{
WriteIntoFile("ERRORE Get a statement handle and execute a Trans-SQL");
return false;
}
SQLINTEGER cbAccount = SQL_NTS;
// ? marks the input parameter.
sRet = SQLPrepare(hstmt, (SQLCHAR*) "{call spIsSubscribed(?)}", SQL_NTS);
// Bind the input parameter.
sRet = SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR,
SQL_CHAR, 20, 0, Account, 0, &cbAccount);
if( (SQLExecute(hstmt)) == SQL_ERROR)
{
WriteIntoFile("ERRORE Execute");
return false;
}
bool sub;
SQLINTEGER cbSub;
bool warn;
SQLINTEGER cbWarning;
// Retrieve data from row set.
SQLBindCol(hstmt, 1, SQL_C_BIT, (SQLPOINTER) &sub, 0, &cbSub);
SQLBindCol(hstmt, 2, SQL_C_BIT, (SQLPOINTER) &warn, 0, &cbWarning);
sRet = SQLFetch(hstmt);
if(sRet != SQL_SUCCESS && sRet != SQL_SUCCESS_WITH_INFO)
{
WriteIntoFile("ERRORE Fetch");
return false;
}
subscription = sub;
warning = warn;
/* Clean up.*/
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
SQLDisconnect(hdbc);
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
SQLFreeHandle(SQL_HANDLE_ENV, henv);
return true;
}
|
|
|
|
|
Hi..
I don't have much time to see your code but
One thing u can do is supply coneection string...
that's very easy...
Use class CDatabase
CRecordset
or drive class from CRecordset & supply all information at creation time...
I'm in hurry...
so see..u later..
bye..
---Sumit Kapoor--- sumit_kapoor1980@hotmail.com
|
|
|
|
|
Why not wrap all of that ODBC nastiness into a class? I have been using the same ODBC classes for about 8 years now, and never had a problem. If you want the classes, shoot me an email.
onwards and upwards...
|
|
|
|
|
Hello,
I have class defined somethig like this :
class CAaa
{
...
CString m_str;
void Set();
}
CAaa::Set()
{
CString tmp;
m_str = tmp;
}
It's more complicated class, but this is the most important part.
Destructor of CAaa will crash the application in CString destructer,
which shows ASSERT in debug mode that it can't free the memory, because it's not valid memory block.
I found out that this won't happend when i use
m_str = (LPCSTR)tmp;
insead of
m_str = tmp;
Why the second thing is not working ? I know that there's only reference increment in second case, and copying of all data in first case,
but why doesn't the reference counting work correctly ?
Is this bad practice to assign member CString value of local CString in function ?
Thanks
rrrado
|
|
|
|
|
How is the CAaa object being created, and Set() being called.
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Thanks for reply !
I don't know whether this is important, but there's list oc Caa :
typedef CArray<CAaa,CAaa&> CAaaArray
class anotherClass
{
void SomeFunc();
CAaaArray m_array;
}
CAaa::SomeFunc()
{
CAaa *aaa;
for (int i=0; i<m_array->GetSize(); i++)
{
aaa = &m_array->GetAt(i);
....
aaa->Set();
}
}
Another weird thing is that for each item in this loop also destructor of CAaa is called, but it's probably because od GetAt returning temporary object created with default copy constructor, which is destroyed at the end of the loop ... I'll have to figure out whether creating of temporary CAaa object isn't problem ....
rrrado
|
|
|
|
|
Sorry
typedef CArray<CAaa,CAaa&> CAaaArray;
rrrado
|
|
|
|
|
I assume you typed these code snippets in rather than copying/pasting them directory from your project. I had to make some changes just to get them to compile. Here is what I have that produces no errors:
class CAaa
{
CString m_str;
public:
CAaa();
~CAaa();
void Set();
};
void CAaa::Set()
{
CString tmp;
m_str = tmp;
}
typedef CArray<CAaa *, CAaa *> CAaaArray;
class anotherClass
{
CAaaArray m_array;
public:
anotherClass();
~anotherClass()
{
CAaa *aaa;
for (int i = 0; i < m_array.GetSize(); i++)
{
aaa = m_array.GetAt(i);
delete aaa;
}
}
void SomeFunc();
void add();
};
void anotherClass::add()
{
CAaa *aaa = new CAaa;
m_array.Add(aaa);
}
void anotherClass::SomeFunc()
{
CAaa *aaa;
for (int i = 0; i < m_array.GetSize(); i++)
{
aaa = m_array.GetAt(i);
aaa->Set();
}
}
...
anotherClass ac;
ac.add();
ac.SomeFunc(); How does it compare to what you have?
"When I was born I was so surprised that I didn't talk for a year and a half." - Gracie Allen
|
|
|
|
|
Yes it would be too big to paste here original classes.
You've used array of pointers, I used array of objects.
So there is different constructing/destructing objkects in array,
it's maybe the biggest difference.
I've posted original array typedef in previous message
rrrado
|
|
|
|
|
ok I've created new project where this also happend
http://rrrado.szm.sk/aaa.zip
just compile and click twice at the button1
Thank you !
rrrado
|
|
|
|
|
This works
for (i=0; i<20; i++)
{
(m_array.GetAt(0)).Set();
}
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|
Did you mean (m_array.GetAt(i)).Set(); ?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
No Check the code
Papa
while (TRUE)
Papa.WillLove ( Bebe ) ;
|
|
|
|
|