Pointer Problem for MVP

  • Thread starter Thread starter Qindong Zhang
  • Start date Start date
Q

Qindong Zhang

I get my memory address (Pointer) from an API call, and then pass this
address to DrawDibDraw function, it works fine on Windows 2000, but
not works on Windows XP (get green screen).

Here something interesting;

I copy the content of the pointer to byte array (Use Marshal.Copy &
intPtr), then create a new pointer from byte array (Use
Marshal.UnsafeAddrOfPinnedArrayElement) it works in Windows XP.


Why? Thanks.


' m_ImagePtr come from an API call.

' This does not work in Windows XP, but works in Windows 2000.
DrawDibDraw(xx, hc, .., m_ImagePtr, 0, 0, 0)

////////////////////////////////////////////
' This works in Windows XP

Dim m_data As Byte()
Dim tmpLength As Integer = 12345
ReDim m_data(tmpLength - 1)
Dim newPtr As New IntPtr(m_ImagePtr)
Marshal.Copy(newPtr, m_data, 0, m_data.Length)
Dim ImagePtr As Integer
ImagePtr = Marshal.UnsafeAddrOfPinnedArrayElement(m_data, 0).ToInt32

DrawDibDraw(xx, hc, .., ImagePtr, 0, 0, 0)
 
Qindong,

Sounds like it could be an alignment issue, perhaps the function
requires the data to be aligned on a DWORD boundary? Where do you get
the pointer from?

Is (m_ImagePtr Mod 4) = 0?



Mattias
 
* (e-mail address removed) (Qindong Zhang) scripsit:
[...]

Have a look at Mattias' reply. Please do not address posts to MVPs
"only", instead address them to everybody contributing to the group.
 
Hi Herfried,
. Please do not address posts to MVPs
"only", instead address them to everybody contributing to the group.
A good answer, I think better is if no MVP did answer this, or in the way as
did above.

Just a thought,

Cor
 
But his questions is too important for mere users. Only an MVP would know
the answer to such an important question.

(-;

Matt
 
* "md said:
But his questions is too important for mere users. Only an MVP would know
the answer to such an important question.

(-;

No. MVPs are humans too and do not know everything. Maybe a non-MVP
won't reply to your question even if he/she knows an answer.
 
In u5%[email protected],
md said:
But his questions is too important for mere users. Only an MVP would
know the answer to such an important question.

Everyone's questions are "important."

Furthermore, there are many very knowledgable people who for whatever reason
have not been awarded MVP status (i.e. they don't meet all the criteria, or
perhaps refused the award).
 
Mattias Sjögren said:
Qindong,

Sounds like it could be an alignment issue, perhaps the function
requires the data to be aligned on a DWORD boundary? Where do you get
the pointer from?

Is (m_ImagePtr Mod 4) = 0?



Mattias

Mattias,

The address come from an API call.

<DllImport("VideoInsight.dll",
EntryPoint:="_HICAP200_dw_LockWait4GetImageAddrEx@20")> Private Shared
Function HICAP200_dw_LockWait4GetImageAddrEx(ByVal IN_dwChannel As
Integer, ByRef IN_dwImageAddr As Integer, ByVal IN_dw4CC As Integer,
ByVal IN_dwBLOCKFlag As Integer, ByVal IN_dwWaitmSec As Integer) As
Integer
End Function

IN_dwImageAddr is the address of pointer.
 
Mattias Sjögren said:
Qindong,

Sounds like it could be an alignment issue, perhaps the function
requires the data to be aligned on a DWORD boundary? Where do you get
the pointer from?

Is (m_ImagePtr Mod 4) = 0?



Mattias

I tested the value of m_ImagePtr, it is an ODD number. e.g. 154533891.
 
Back
Top