Rasapi32.dll loading in vc++

Rasapi32.dll is not getting loaded in vc++

Page 1 of 1

1 Replies - 2348 Views - Last Post: 27 October 2009 - 12:38 PM Rate Topic: -----

#1 avixt5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 27-October 09

Rasapi32.dll loading in vc++

Posted 27 October 2009 - 12:03 PM

this is generating

error LNK2001: unresolved external symbol _RasGetErrorStringA@12
error LNK2001: unresolved external symbol _RasEnumEntriesA@20

I am not able to use this RAS functions

so please tell what's wrong in this code




#include <ras.h>
#include <raserror.h>


BOOL CMy2NetDialDlg::QueryConnections()
{

typedef DWORD (WINAPI* RGEPA)
(LPCTSTR lpszPhonebook,		// pointer to full path and filename of 
							// phone-book file
  LPCTSTR lpszEntry,		// pointer to an entry name
  LPRASENTRY lpRasEntry,	// buffer that receives entry information
  LPDWORD lpdwEntryInfoSize,	// size, in bytes, of the lpRasEntry 
								// buffer
  LPBYTE lpbDeviceInfo,			// buffer that receives device-specific 
								// configuration information
  LPDWORD lpdwDeviceInfoSize	// size, in bytes, of the 
								// lpbDeviceInfo buffer
);
// load library
	HINSTANCE hLib = LoadLibrary(_T("RASAPI32.DLL"));
//	HINSTANCE hLib = LoadLibrary("C:\\WINDOWS\\system32\\RASAPI32.DLL");

//	AfxMessageBox("LoadLibrary(_T(RASAPI32.DLL))");
	if (NULL == hLib) return FALSE;
	RGEPA rgepa = (RGEPA) GetProcAddress(hLib, "RasGetEntryPropertiesA");
	if (NULL == rgepa)
	{
		::FreeLibrary(hLib);
		return FALSE;
	}
	RASENTRY RasEntry;
	DWORD dw = sizeof(RASENTRY);
	ZeroMemory(&RasEntry, dw);
	RasEntry.dwSize = dw;
	DWORD ret = rgepa(NULL, NULL, &RasEntry, &dw, NULL, NULL);//sEntryName
//	::FreeLibrary(hLib);


	LPRASENTRYNAME first_ras_entry; // really a buffer of [num_entries]
	DWORD buf_size, entry_size;
	DWORD num_entries = 1;
	DWORD dwRet;//retval
	UINT  ndx;
	char  szMessage[256];
	CString sProvdrTmp;

	entry_size = sizeof(RASENTRYNAME);
	buf_size = entry_size * num_entries;
	first_ras_entry = (LPRASENTRYNAME) new char[buf_size];

   // check for a malloc() failure
	if (NULL == first_ras_entry) return FALSE;

   // clear the whole buffer, rather than a single entry
	ZeroMemory(first_ras_entry, buf_size); // AKA bzero() or memset(0)
	first_ras_entry->dwSize = entry_size; // initialize the dwSize member
	dwRet = RasEnumEntries(NULL, NULL, first_ras_entry, &buf_size, &num_entries);

   if( (ERROR_BUFFER_TOO_SMALL == dwRet)  // entry size OK, but too many entries
	   || (ERROR_INVALID_SIZE == dwRet) ) // entry size wrong
   {
	  entry_size = buf_size / num_entries; // recalculate the correct entry size
	  
	  // reallocate the buffer:
	  delete first_ras_entry;
	  first_ras_entry = NULL;
	  first_ras_entry = (LPRASENTRYNAME) new char[buf_size];
	  
	  if (NULL != first_ras_entry) // if buffer OK, try again
	  {
		 ZeroMemory(first_ras_entry, buf_size);
		 first_ras_entry->dwSize = entry_size;
		 dwRet = RasEnumEntries(NULL, NULL, first_ras_entry, &buf_size, &num_entries);
	  }
	  else
		 dwRet = ERROR_NOT_ENOUGH_MEMORY;
   }

   if (0 != dwRet) // other error
   {
	  long int tmp_dwRet;
	  tmp_dwRet = RasGetErrorString((UINT)dwRet, szMessage, 256);
	  if (0 == tmp_dwRet)
	  {
			AfxMessageBox( szMessage);
			CString sss; //sss.LoadString(IDS_RASCS_25);
			wsprintf((LPSTR)szMessage, sss);
	  }
	  else
	  {
		  AfxMessageBox("Couldn't get a verbose err. message. RasGetErrorString() = %ld", tmp_dwRet);
	  }

		UpdateData(FALSE);
   }

   if (0 == num_entries)
   {
	  delete first_ras_entry;
	  return FALSE;
   }

	BOOL bSet = FALSE;

   if (0 == dwRet)  // No errors
   {
	  for (ndx = 0; ndx < num_entries; ndx++)
	  {
		sProvdrTmp =(CString)first_ras_entry[ndx].szEntryName;
	
		 if (first_ras_entry[ndx].szEntryName == sCurrentProvider)
		 {
				bSet = TRUE;
		 }
	  }
		if (!bSet)
		{
			sCurrentProvider = sProvdrTmp;//first_ras_entry[ndx].szEntryName;
		}

   }
	::FreeLibrary(hLib);

   delete first_ras_entry;
   return TRUE;

}





Is This A Good Question/Topic? 0
  • +

Replies To: Rasapi32.dll loading in vc++

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Rasapi32.dll loading in vc++

Posted 27 October 2009 - 12:38 PM

From the documentation for RasEnumEntries:

Quote

Requirements
Minimum supported client Windows 2000 Professional
Minimum supported server Windows 2000 Server
Header Ras.h
Library Rasapi32.lib
DLL Rasapi32.dll
Unicode and ANSI names RasEnumEntriesW (Unicode) and RasEnumEntriesA (ANSI)


See the bolded lib file? That needs to be linked into your application. Check your compiler's documentation on how to do this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1