RasEnumEntries ????????

2 отговора 100 прегледа
#1

RasEnumEntries ????????

zdravite tozi kod raboti pod Win 2000 , i XP otlichno no pod 98
nishto ne se poluchava. RasEnumEntries bi tryabvalo da raboti i pod 98 - vsichko e spored help-a no ne ebava Tryabva da se napulni edin Combo Box sus konekciite (Dial Up konekciite). Nykakvi idei ? Predvaritelno mnogo vi blagodarya
eto go koda:
.................................................................................................................................
void CDialupListDlg::Refresh()
{
m_cbAccounts.ResetContent();

LPRASENTRYNAME lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, sizeof(RASENTRYNAME));
DWORD cb = 0;
DWORD cEntries = 0;
DWORD nRet;

lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
//zono: dobavih po-dolnoto (samo dolniya red) ako sraboti shte e chudo
cb = lpRasEntryName->dwSize;
if ((nRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries)) == ERROR_BUFFER_TOO_SMALL) {
GlobalFree((HGLOBAL)lpRasEntryName);
lpRasEntryName = (LPRASENTRYNAME)GlobalAlloc(GPTR, cb);
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
}

// Calling RasEnumEntries to enumerate the phone-book entries
nRet = RasEnumEntries(NULL, NULL, lpRasEntryName, &cb, &cEntries);
if (nRet != ERROR_SUCCESS) {
TRACE(_T("RasEnumEntries failed: Error %d\n"), nRet);
}else{
TRACE(_T("Phone-book entries in the default phone book:\n\n"));
for(DWORD i=0;i < cEntries;i++) {
//TRACE(_T("%s\n"),lpRasEntryName->szEntryName);
m_cbAccounts.AddString(lpRasEntryName->szEntryName);
lpRasEntryName++;
}
}
//GlobalFree(lpRasEntryName);

if(m_cbAccounts.GetCount() > 0)
m_cbAccounts.SetCurSel(0);

}
..................................................................................................................................

Отговор
в отговор на ZergSwarm #2

Ако смяташ...

..., че някой ще седне да ти изследва кода ред по ред, жестоко се лъжеш. За тази работа се плаща, нещо което ти не предлагаш. Ако на теб ти трябва кода, ти си го оправяй.

Не можеш да copy+paste 20 реда код, и да питаш - що не работи? Ми щото е калпаво. Да беше казал как точно не работи...

На всичко отгоре, не си го и направил във вид удобен за copy+paste+compile. Нищо чудно, че и никой не ти е отговорил. Погледни [линк], ще ти е от полза.

Все пак за да не излезе, че отговорът ми е само за заяждане ще ти напомня следното:

Windows XP & 2000 са NT съвместими. Прегледай МСДН пак, и обърни внимание на QuickInfo за всички ползвани функции. Защото за RasEntryDlg примерно, ще видиш следното:

Windows NT: Requires version 4.0 or later.
Windows: Unsupported.
Windows CE: Unsupported.
Header: Declared in rasdlg.h.
Import Library: Use rasdlg.lib.
Unicode: Implemented as Unicode and ANSI versions on Windows NT.

Мечтата е мисъл, мисълта е идея, всяка идея се реализира. Аз не мечтая, а реализирам идеите си.
Отговор
в отговор на ZergSwarm #3

Re: RasEnumEntries ????????

Ето какво MSDN казва по въпроса:

RasEnumEntries

The RasEnumEntries function lists all entry names in a remote access phone book.


DWORD RasEnumEntries(
LPCTSTR reserved,
LPTCSTR lpszPhonebook,
LPRASENTRYNAME lprasentryname,
LPDWORD lpcb,
LPDWORD lpcEntries
);

Parameters
reserved
[in] Reserved; must be NULL.
lpszPhonebook
[in]
Windows NT/2000/XP: Pointer to a null-terminated string that specifies the full path and file name of a phone-book (PBK) file. If this parameter is NULL, the function uses the current default phone-book file. The default phone-book file is the one selected by the user in the User Preferences property sheet of the Dial-Up Networking dialog box.

Windows 2000/XP: If this parameter is NULL, the entries are enumerated from all the remote access phone-book files in the AllUsers profile and the user's profile.

Windows 95/98/Me: This parameter should always be NULL. Dial-up networking stores phone-book entries in the registry rather than in a phone-book file.

lprasentryname
[in, out] Pointer to a buffer that, on output, receives an array of RASENTRYNAME structures, one for each phone-book entry.
On input, an application must set the dwSize member of the first RASENTRYNAME structure in the buffer to sizeof(RASENTRYNAME) in order to identify the version of the structure being passed.

lpcb
[in, out] Pointer to a variable that, on input, contains the size, in bytes, of the buffer specified by lprasentryname.
On output, the function sets this variable to the number of bytes required to successfully complete the call.

lpcEntries
[out] Pointer to a variable that receives to the number of phone-book entries written to the buffer specified by lprasentryname.
Return Values
If the function succeeds, the return value is zero.

If the function fails, the return value is a nonzero error value listed in the RasError.h header file or one of the following values.


Value Meaning
ERROR_BUFFER_TOO_SMALL The buffer pointed to by the lprasentryname parameter is not large enough to hold all the entries.
ERROR_INVALID_SIZE The value of dwSize in the RASENTRYNAME structure pointed to by lprasentryname, specifies a version of the structure that is not supported on the current platform. For example, on Windows 95, RasEnumEntries returns this error if dwSize indicates that RASENTRYNAME includes the dwFlags and szPhonebookPath members, since these members are not supported on Windows 95 (they are supported only on Windows 2000 and later).
ERROR_NOT_ENOUGH_MEMORY The function could not allocate sufficient memory to complete the operation.




Remarks
The following sample code enumerates the RAS phone-book entries on the current machine. The code initially calls RasEnumEntries to obtain the size of the buffer to pass in. The code then calls RasEnumEntries again, to enumerate the entries. Note that for both calls, the code sets the dwSize member of the first RASENTRY structure in the buffer to sizeof(RASENTRY) to specify the structure version.


DWORD dwCb = sizeof(RASENTRYNAME);
DWORD dwErr = ERROR_SUCCESS;
DWORD dwRetries = 5;
DWORD dwEntries = 0;
RASENTRYNAME* lpRasEntryName = NULL;

//
// Loop through in case the information from RAS changes between calls.
//
while (dwRetries--)
{
//
// If the memory is allocated, free it.
//
if (NULL != lpRasEntryName)
{
HeapFree(GetProcessHeap(), 0, lpRasEntryName);
lpRasEntryName = NULL;
}
//
// Allocate the size need for the RAS structure.
//
lpRasEntryName = HeapAlloc(GetProcessHeap(), 0, dwCb);
if (NULL == lpRasEntryName)
{
dwErr = ERROR_NOT_ENOUGH_MEMORY;
break;
}
//
// Set the structure size for version checking purposes.
//
lpRasEntryName->dwSize = sizeof(RASENTRYNAME);
//
// Call the RAS API, bail on the loop if we are successful or an unknown
// error occurs.
//
dwErr = RasEnumEntries(
NULL,
NULL,
lpRasEntryName,
&dwCb,
&dwEntries);
if (ERROR_BUFFER_TOO_SMALL != dwErr)
{
break;
}
}
//
// In the success case print the names of the entries.
//
if (ERROR_SUCCESS == dwErr)
{
DWORD i;

printf("Phone-book entries in the default phone book:\n\n");
for (i = 0; i < dwEntries; i++)
{
printf("%s\n", lpRasEntryName->szEntryName);
}
}
else
{
printf("RasEnumEntries failed: Error = %d\n", dwErr);
}
//
// Free the memory if necessary.
//
if (NULL != lpRasEntryName)
{
HeapFree(GetProcessHeap(), 0, lpRasEntryName);
lpRasEntryName = NULL;
}



Windows 95/98/Me: RasEnumEntriesW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.


Requirements
Client: Included in Windows XP, Windows 2000 Professional, Windows NT Workstation, Windows Me, Windows 98, Windows 95.
Server: Included in Windows .NET Server 2003, Windows 2000 Server, Windows NT Server.
Unicode: Implemented as Unicode and ANSI versions on Windows NT/2000/XP. Also supported by Microsoft Layer for Unicode.
Header: Declared in Ras.h.
Library: Use Rasapi32.lib.


See Also
Remote Access Service (RAS) Overview, Remote Access Service Functions, RASENTRYNAME, RasEnumConnections

Аре бегай да пикаш!


Отговор