MapViewOfFile -> 'The specified procedure could not be found.'

G

Guest

I get the error: 'The specified procedure could not be found.' Anyone know why?

I get the error to the call of the function MapViewOfFile():

Private Const FILE_MAP_ALL_ACCESS As Integer = &H1 Or &H2 Or &H4 Or &H8
Or &H10 Or &HF0000

Private Declare Auto Function MapViewOfFile Lib "kernel32" ( _
ByVal hFileMappingObject As IntPtr, _
ByVal dwDesiredAccess As Integer, _
ByVal dwFileOffsetHigh As Integer, _
ByVal dwFileOffsetLow As Integer, _
ByVal dwNumberOfBytesToMap As Integer) As Integer

Function SendCommand(ByVal hwnd As IntPtr, ByVal command As String) As
Boolean
Dim hMapFile As IntPtr
Dim mData As String
Dim result As Boolean = False
Dim errorMessage As String

hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, 0,
PAGE_READWRITE, 0, 4096, "mIRC")

mData = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0, 0).ToString
errorMessage = New Win32Exception(Marshal.GetLastWin32Error()).Message

wsprintf(mData, command)

SendMessage(hwnd, WM_MCOMMAND, vbNull, vbNullString)

If mData = "1" Then
result = True
End If

UnmapViewOfFile(mData)
CloseHandle(hMapFile)

Return result
End Function
 
T

Tom Shelton

I get the error: 'The specified procedure could not be found.' Anyone know why?

I get the error to the call of the function MapViewOfFile():

Private Const FILE_MAP_ALL_ACCESS As Integer = &H1 Or &H2 Or &H4 Or &H8
Or &H10 Or &HF0000

Private Declare Auto Function MapViewOfFile Lib "kernel32" ( _
ByVal hFileMappingObject As IntPtr, _
ByVal dwDesiredAccess As Integer, _
ByVal dwFileOffsetHigh As Integer, _
ByVal dwFileOffsetLow As Integer, _
ByVal dwNumberOfBytesToMap As Integer) As Integer

Try removing the Auto from the declaration.
 
M

Mattias Sjögren

I get the error: 'The specified procedure could not be found.' Anyone know why?

Do you get an exception thrown with that error message, or is it just
the string you get in errorMessage after the call? As long as the
function succeeds (returns non-zero), you shouldn't bother calling
Marshal.GetLastWin32Error.

BTW, why do you check if the return value converted to a string is
"1"? MapViewOfFile returns a nonzero pointer value if it succeeds.



Mattias
 
G

Guest

Ok, that makes sense. I don't get thrown an exception, but the program mIRC
doesn't seem to be getting the message as SendMessage is returning 0. I can't
figure out why since all the other functions seem to be returning correct
values.

btw that return value was just code from somewhere else, which I removed.

Private Const WM_MCOMMAND As Integer = &H102 + 200

Declare Auto Function SendMessage Lib "user32" ( _
ByVal hWnd As IntPtr, _
ByVal Msg As Integer, _
ByVal wParam As Integer, _
ByVal lParam As Integer) As Integer

Function SendCommand(ByVal hwnd As IntPtr, ByVal command As String) As
Boolean
Dim hMapFile As IntPtr
Dim mData As Long

' hwnd = 459282
' command = "/msg XBN`grind test"

' Returns: 1684 (IntPtr)
hMapFile = CreateFileMapping(INVALID_HANDLE_VALUE, 0,
PAGE_READWRITE, 0, 4096, "mIRC")

' Returns: 8975933078252945408 (Long)
mData = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0,
NumberOfBytes)

' Returns: 2 (Integer)
wsprintf(mData, command)

' Returns: 0 (Integer)
SendMessage(hwnd, WM_MCOMMAND, 0, 0)

' Returns: False
UnmapViewOfFile(mData)

' Returns: False
CloseHandle(hMapFile)

Return True
End Function
 
M

Mattias Sjögren

' Returns: 8975933078252945408 (Long)
mData = MapViewOfFile(hMapFile, FILE_MAP_ALL_ACCESS, 0, 0,
NumberOfBytes)

Did you change the return type of MapViewOfFile to a Long? Integer was
more correct for Win32, but ideally you should use IntPtr to represent
pointers.



Mattias
 

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

Top