-
WRAPI in VB?
I'm trying to use WRAPI in VB, but I can't manage to get it working.
I downloaded the dll and lib from http://sysnet.ucsd.edu/pawn/wrapi/download.html
The source files contain a header file, which defines the function:
Code:
typedef struct WRAPI_NDIS_DEVICE
{
WCHAR *pDeviceName;
WCHAR *pDeviceDescription;
} WRAPI_NDIS_DEVICE;
WRAPI HRESULT WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);
In VB, I declare the functions like this:
Code:
Private Type WRAPI_NDIS_DEVICE
pDeviceName As String
pDeviceDescription As String
End Type
Private Declare Function WRAPIEnumerateDevices Lib "wrapi.dll" (ppDeviceList As WRAPI_NDIS_DEVICE, plItems As Long) As Long
When I call the function, I get an error saying: "File not found: wrapi.dll", and the IDE breaks on the Declare Function statement.
The dll and the lib are both in the same folder as the project, and I also tried moving them to the System32 folder, but to no avail.
Does anyone know what I'm doing wrong? i'm not even sure if it's possible to use these functions from VB, but I would expect a slightly different error message than file-not-found. Any help is more than welcome :)
-
Re: WRAPI in VB?
Not 100% sure bu tI think you havr to give the full path to the library...
Code:
Private Declare Function WRAPIEnumerateDevices Lib "C:\Windows\System32\wrapi.dll" (ppDeviceList As WRAPI_NDIS_DEVICE, plItems As Long) As Long
-
Re: WRAPI in VB?
Tried that, same result.
It would be rather strange if it did, since that way I would have to make sure the dll had to be in that exact location if installed on another machine.
-
Re: WRAPI in VB?
A few times I've seen odd characters get mixed in with code, like when copying/pasting from someplace. The characters in this case have no visual representation, so you don't see them, but vb just can't make heads or tails out of it, and acts in all manner of strange ways. I've found that pasting the code into the immediate window, then back into the code window seems to fix this type of thing, or you can edit the source file in notepad, but it can be tricky to find the culprit. I'd also check the filename for unintended characters, such as spaces or whatever. Other than that, I agree that vb should not be saying "file not found". Have you tried using Dir() to see if it can be located that way?
-
1 Attachment(s)
Re: WRAPI in VB?
Dir() returns wrapi.dll
As for the special characters when copy/pasting, since I only had the c++ header file to go on, I had to type the declaration myself, so that rules out any invalid characters.
Doing some further research, I pulled the dll into a utility DLL Export viewer, which shows all exported functions in a dll. The results showed up quite odd, so I suspect the dll from beeing corrupt. See attached screenshot (left is user32.dll, right is wrapi.dll).
Unfortunately, I don't have the needed skills to recompile from source, and I haven't been able to find another version of the dll.
I've just mailed the author of wrapi to see if he can come up with a solution, and check the dll for correctness, but since it doesn't appear to be a really active project, I can only hope to get a response.
-
Re: WRAPI in VB?
That is certainly strange. I would have thought you'd get an error like "Can't find entry point..."
-
Re: WRAPI in VB?
IMHO, you will be not able to use this DLL in VB because the all entries have the cdecl calling convention not supported by VB.
I could load this DLL and get "Can't find DLL entry point WRAPIEnumerateDevices in D:\Forums\CodeGuru\WRAPI\wrapi.dll" expected.
***EDITED***
After adding the correct alias to this function, I have "Bad DLL calling convention" expected.
Code:
Private Declare Function WRAPIEnumerateDevices Lib "D:\Forums\CodeGuru\WRAPI\wrapi.dll" _
Alias "?WRAPIEnumerateDevices@@YAJPAPAUWRAPI_NDIS_DEVICE@@PAJ@Z" _
(ppDeviceList As WRAPI_NDIS_DEVICE, plItems As Long) As Long
-
Re: WRAPI in VB?
Ok, that clears up a lot.
I found an example on PSC to call cdecl dll's from VB, but it keeps complaining about a wrong parameter type i'm passing (the WRAPI_NDIS_DEVICE).
I'll play with it some more to see if can get any further with that.
Do you know if it's hard to convert the dll to use _stdcall instead of cdecl? (maybe I should ask this in the VC++ forum instead). Would it require a complete rewrite, or only some subtile changes?
Thanks
-
Re: WRAPI in VB?
Q: Do you know if it's hard to convert the dll to use _stdcall instead of cdecl? (maybe I should ask this in the VC++ forum instead). Would it require a complete rewrite, or only some subtile changes?
1. You can rebuild ALL functions in project to be __stdcall convention.
Project Menu -> Settings... Alt+F7 Submenu -> select root node WRAPI -> C/C++ Tab -> Category: "Code Generation" Combo -> Calling convention: "__stdcall"
2. You can rename the HRESULT into STDAPI or STDMETHODIMP in each WRAPIXXXX declarations, for example:
WRAPI HRESULT WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);
to
WRAPI STDAPI WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);
or
WRAPI STDMETHODIMP WRAPIEnumerateDevices(WRAPI_NDIS_DEVICE **ppDeviceList, long *plItems);