WHLLAPI.DLL : Can't get a pointer to DLL


J

jeffrey.travassos

WHLLAPI.DLL - System Error when trying to Load DLL

I've got two machines, both running XP. I doubt they're identical HD imagesthough.

The center here runs an Emulator called Aviva for Desktops version 12. Theyuse it to connect to IBM mainframes.

I use a laptop to develop simple tools for the center and up until today, Ithought I was running the same version of the Aviva Emulator as the centerin the end I'm not. I'm running Aviva for Desktops 8.20

Now. I found some sample code here http://www.sdisw.com/tn3270/WHLLAPI3270VB.htm, which works great on my version of Aviva. I've got both WHLLAPI.DLL and WHLLAP16.DLL in the install directory of Aviva and all is well. I can get a pointer to the DLL and issue commands to the WinHll API successfully.

When I take this sample code and move it to one of the production machines,I am no longer able to load the same DLL. The install directory structure is a little different. I don't have WHLLAPI16.DLL but I do have WHLLAPI.DLL.. When I point the sample code to that file and try to get a pointer to it,It fails, and thus I cannot control the Emulator.

So I putsed around in the directory and found a utility called TstApi.exe that allows me to execute individual functions of WinHLLAPI and EHLLAPI, andI've learned that if I call WinHLLAPIStartup before anything else, my subsequent calls work. So I've determined this call as a prerequisite for all other calls on this machine.

When I examine some sample code I found, I see that a pointer to the WHLLAPI Dll is obtained before WinHLLAPIStartup is even called. I guess that's mymain issue. I'm not sure how to tell why I'm not obtaining a pointer...

Here's the code that loads the DLL

Private Declare Auto Function LoadLibrary Lib "kernel32" _
(ByVal DllToLoad As String) As IntPtr

Private Declare Function GetProcAddress Lib "kernel32" _
(ByVal ModuleHandle As IntPtr, ByVal ProcName As String) _
As IntPtr

Private Declare Function FreeLibrary Lib "kernel32" _
(ByVal ModuleHandle As IntPtr) As IntPtr

' Declare delegates for the Whllapi functions: WinHLLAPI, WinHLLAPIStatup and
' WHLLAPICleanup. (Requires .NET Framework version 2.0 or above)
'
' WinHLLAPI function call syntax as documented in the Windows HLLAPI
' Specification Version 1.1
'
' extern void FAR PASCAL WinHLLAPI(
' LPWORD lpwFunction, /* Function name */
' LPBYTE lpbyString, /* String pointer */
' LPWORD lpwLength, /* String (data) length */
' LPWORD lpwReturnCode); /* Return code */
'
' int WinHLLAPIStartup(WORD wVersionRequired, LPWHLLAPIDATA lpData)
'
' BOOL WinHLLAPICleanup(void)
'
<UnmanagedFunctionPointer(CallingConvention.Cdecl)> _
Public Delegate Sub WinHLLAPI(ByRef lpwFunction As UInt16, ByVal byDataAs Byte(), ByRef lpwLength As UInt16, ByRef lpwReturnCode As UInt16)
<UnmanagedFunctionPointer(CallingConvention.Cdecl)> _
Public Delegate Function WinHLLAPIStartup(ByVal nVersion As Short, ByVal byData As Byte()) As Integer
<UnmanagedFunctionPointer(CallingConvention.Cdecl)> _
Public Delegate Function WinHLLAPICleanup() As Integer

Public WinHLLAPIDelegate As WinHLLAPI
Public WinHLLAPIStartupDelegate As WinHLLAPIStartup
Public WinHLLAPICleanupDelegate As WinHLLAPICleanup

Public handleToWhllapiDll As IntPtr

Public Function LoadDll(ByVal whllapiDllFilename As String) As Boolean

' Map the WHLLAPI DLL into our address space.
handleToWhllapiDll = LoadLibrary(whllapiDllFilename)

If handleToWhllapiDll <> IntPtr.Zero Then

' Get the addresses of the WinHLLAPI, WinHLLAPIStartup and WinHLLAPICleanup
Dim ptrToWinHLLAPIFunction As IntPtr
Dim ptrToWinHLLAPIStartupFunction As IntPtr
Dim ptrToWinHLLAPICleanupFunction As IntPtr
ptrToWinHLLAPIFunction = GetProcAddress(handleToWhllapiDll, "WinHLLAPI")
ptrToWinHLLAPIStartupFunction = GetProcAddress(handleToWhllapiDll, "WinHLLAPIStartup")
ptrToWinHLLAPICleanupFunction = GetProcAddress(handleToWhllapiDll, "WinHLLAPICleanup")

If (ptrToWinHLLAPIFunction <> IntPtr.Zero) AndAlso _
(ptrToWinHLLAPIStartupFunction <> IntPtr.Zero) AndAlso _
(ptrToWinHLLAPICleanupFunction <> IntPtr.Zero) Then


WinHLLAPIDelegate = Marshal.GetDelegateForFunctionPointer(ptrToWinHLLAPIFunction, GetType(WinHLLAPI))
WinHLLAPIStartupDelegate = Marshal.GetDelegateForFunctionPointer(ptrToWinHLLAPIStartupFunction, GetType(WinHLLAPIStartup))
WinHLLAPICleanupDelegate = Marshal.GetDelegateForFunctionPointer(ptrToWinHLLAPICleanupFunction, GetType(WinHLLAPICleanup))

Return True

End If

End If
Return False
End Function

Thank you
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top