System.NullReferenceException

mjb3030

Well-known member
Joined
Aug 14, 2003
Messages
76
I have the following function:

Code:
    Function AllocBuffer(ByVal WinFlags As Integer, ByVal buffersize As Long) As Long
        Dim hbuf As Long
        Dim ecode As Long
        ecode = olDmAllocBuffer(WinFlags, buffersize, hbuf)
        If ecode <> OLNOERROR Then
            OLMEMTrap("AllocBuffer", ecode)
        Else
            AllocBuffer = hbuf
        End If

    End Function

the olDmAllocBuffer function is defined as:

Code:
    Declare Function olDmAllocBuffer& Lib "OLMEM32.DLL" (ByVal usWinFlags%, ByVal ulBufferSize&, ByVal hBuffer&)

An error of System.NullReference Exception or "Object reference not set to an instance of an object" is being thrown at the line

Code:
        ecode = olDmAllocBuffer(WinFlags, buffersize, hbuf)

All of this code is contained in a module. I dont see any objects here other than longs and integers. This code works in VB6. What am I doing wrong?
 
Could you show a bit more code before the line
Code:
ecode = olDmAllocBuffer(WinFlags, buffersize, hbuf)

i.e. how are you initalizing WinFlags, buffersize and hbuf (which looks like it should point to some kind of buffer and may be the one that needs initializing)
 
Last edited by a moderator:
A value of 0 is being passed in for WinFlags, a value of 200 is being passed in for buffersize, and hbuf is the variable that will hold the result being returned from olDmAllocBuffer.
 
Back
Top