By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,418 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,418 IT Pros & Developers. It's quick & easy.

How to get address of array parameter?

P: n/a
I'm trying to use a callback procedure from a COM library. The declaration
is Callback(ByRef pData as System.Array, ...).

pData contains the memory representation of a bitmap. I'm trying to create
a bitmap object by passing pData to the bitmap's constructor, which accepts
the data as IntPtr. How do I go about getting a pointer to pData?

I'm using VS 2005 Beta 2.

TIA,

Richard
Nov 21 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
You should allocate an hGlobal, copy the bitmap into that and then pass the
IntPtr to the COM object for the global. See the methods in the Interop
namespace for more information.
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
I'm trying to use a callback procedure from a COM library. The
declaration
is Callback(ByRef pData as System.Array, ...).

pData contains the memory representation of a bitmap. I'm trying to
create
a bitmap object by passing pData to the bitmap's constructor, which
accepts
the data as IntPtr. How do I go about getting a pointer to pData?

I'm using VS 2005 Beta 2.

TIA,

Richard

Nov 21 '05 #2

P: n/a
Thanks for replying, but offhand, that seems to be a rather inefficient
approach. Especially since it also means having to copy the bitmap image
back to the original variable.

Are you sure there isn't a better way?

Richard Rosenheim

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:dc*******************@news.demon.co.uk...
You should allocate an hGlobal, copy the bitmap into that and then pass the IntPtr to the COM object for the global. See the methods in the Interop
namespace for more information.
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
I'm trying to use a callback procedure from a COM library. The
declaration
is Callback(ByRef pData as System.Array, ...).

pData contains the memory representation of a bitmap. I'm trying to
create
a bitmap object by passing pData to the bitmap's constructor, which
accepts
the data as IntPtr. How do I go about getting a pointer to pData?

I'm using VS 2005 Beta 2.

TIA,

Richard


Nov 21 '05 #3

P: n/a
In doing some more research, I think the approach is to use
System.Runtime.Interopservices.GCHandle.Alloc. But, I haven't been able to
get it to work.

Here's what I have so far:

Private Sub Callback(ByRef pData as System.Array, ByVal lWidth As
Integer, ByVal lHeight As Integer, _
ByVal lBitCount As Integer, ByVal
lSize As Integer, ByVal bTopDown As Integer)

Dim gch As System.Runtime.InteropServicesGCHandle
Dim b As Bitmap

Try
gch = GCHandle.Alloc(pData(0))
b = New Bitmap(lWidth, lHeight, (lWidth * lBitCount) / 8, f,
GCHandle.op_Explicit(gch))
b.Save("c:\test.bmp", ImageFormat.Bmp)
gch.Free()
Catch ex As Exception
...

The b.Save is generating the exception "Run-time exception thrown :
System.Runtime.InteropServices.ExternalException - A generic error occurred
in GDI+.

I also tried calling gch.Free() before doing the save, and received the same
results. Anyone have any suggestions?

Richard Rosenheim
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:On*************@TK2MSFTNGP09.phx.gbl...
Thanks for replying, but offhand, that seems to be a rather inefficient
approach. Especially since it also means having to copy the bitmap image
back to the original variable.

Are you sure there isn't a better way?

Richard Rosenheim

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:dc*******************@news.demon.co.uk...
You should allocate an hGlobal, copy the bitmap into that and then pass

the
IntPtr to the COM object for the global. See the methods in the Interop
namespace for more information.
"Richard L Rosenheim" <ri*****@rlr.com> wrote in message
news:OY**************@TK2MSFTNGP09.phx.gbl...
I'm trying to use a callback procedure from a COM library. The
declaration
is Callback(ByRef pData as System.Array, ...).

pData contains the memory representation of a bitmap. I'm trying to
create
a bitmap object by passing pData to the bitmap's constructor, which
accepts
the data as IntPtr. How do I go about getting a pointer to pData?

I'm using VS 2005 Beta 2.

TIA,

Richard



Nov 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.