G
Guest
Hi group,
I have to pinvoke a RAS dll, but i have a native exception and
a dont know what are i doing incorret.
Unmanaged Code:
------------------------
DWORD WINAPI EnumEntries(LPWSTR lpstr, DWORD &count)
{
LPRASENTRYNAME lpRasEntry = NULL;
DWORD dwRes, dwSize, dwEntries, dw;
WCHAR szTmp[255];
wcscpy(szTmp,_T(""));
lpRasEntry = new RASENTRYNAME[20];
if(lpRasEntry == NULL)
{
return 1;
}
lpRasEntry[0].dwSize = sizeof(RASENTRYNAME);
dwSize = sizeof(RASENTRYNAME) * 20;
dwRes = RasEnumEntries(NULL, NULL, lpRasEntry, &dwSize, &dwEntries);
if (dwRes == 0)
{
count = dwEntries;
for(dw = 0; dw < dwEntries; dw++)
{
wcscat(szTmp,lpRasEntry[dw].szEntryName);
if (dw != dwEntries)
wcscat(szTmp,_T(","));
}
//wcsncpy(lpstr, szTmp, 255);
wcscpy(lpstr,szTmp);
}
delete [] lpRasEntry;
return dwRes;
}
Managed Code (VB):
------------------------
<DllImport("DllPrueba.dll")> _
Private Function EnumEntries(ByVal lpszValue As StringBuilder, ByRef
dwCount as Long) As Long
End Function
...........
Dim szValue As New StringBuilder(255)
Dim dwCount As Long
Dim ret As Long
Try
ret = EnumEntries(szValue, dwCount)
MessageBox.Show("Resultado: " & szValue.toString())
Catch ex As Exception
MessageBox.Show("Error EnumEntriesRAS: " & ex.Message.ToString())
End Try
I'm using StringBuilder with LPWSTR and ByRef with DWORD&.
Where they are the error(s)?
Thanks.
I have to pinvoke a RAS dll, but i have a native exception and
a dont know what are i doing incorret.
Unmanaged Code:
------------------------
DWORD WINAPI EnumEntries(LPWSTR lpstr, DWORD &count)
{
LPRASENTRYNAME lpRasEntry = NULL;
DWORD dwRes, dwSize, dwEntries, dw;
WCHAR szTmp[255];
wcscpy(szTmp,_T(""));
lpRasEntry = new RASENTRYNAME[20];
if(lpRasEntry == NULL)
{
return 1;
}
lpRasEntry[0].dwSize = sizeof(RASENTRYNAME);
dwSize = sizeof(RASENTRYNAME) * 20;
dwRes = RasEnumEntries(NULL, NULL, lpRasEntry, &dwSize, &dwEntries);
if (dwRes == 0)
{
count = dwEntries;
for(dw = 0; dw < dwEntries; dw++)
{
wcscat(szTmp,lpRasEntry[dw].szEntryName);
if (dw != dwEntries)
wcscat(szTmp,_T(","));
}
//wcsncpy(lpstr, szTmp, 255);
wcscpy(lpstr,szTmp);
}
delete [] lpRasEntry;
return dwRes;
}
Managed Code (VB):
------------------------
<DllImport("DllPrueba.dll")> _
Private Function EnumEntries(ByVal lpszValue As StringBuilder, ByRef
dwCount as Long) As Long
End Function
...........
Dim szValue As New StringBuilder(255)
Dim dwCount As Long
Dim ret As Long
Try
ret = EnumEntries(szValue, dwCount)
MessageBox.Show("Resultado: " & szValue.toString())
Catch ex As Exception
MessageBox.Show("Error EnumEntriesRAS: " & ex.Message.ToString())
End Try
I'm using StringBuilder with LPWSTR and ByRef with DWORD&.
Where they are the error(s)?
Thanks.