473,326 Members | 2,337 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

How to get address of array parameter?

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
3 2624
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Douglas | last post by:
Hi, What is the need for the inaccessible pointer address beyond the end of an array? Eg. could for(ip = &array; ip < &array; ip++).... not be rewritten as
27
by: Adam Warner | last post by:
Hi all, In the code snippet below I successfully determine the address of val1:* struct o val1=l_SYM_2B(&a).o; print_aesthetic(&val1); The structure o is heavyweight. I understand...
33
by: baumann.Pan | last post by:
hi all, i want to get the address of buf, which defined as char buf = "abcde"; so can call strsep(address of buf, pointer to token);
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
3
by: dbru | last post by:
I need to pass an address of a Managed float array to a DLL. The following doesn't seem to work extern static float GetXXX( StringBuilder HWND, long nWhat, ref float lparam );
10
by: | last post by:
If I have an array of int: int array; I suppose the correct way to clear it using memset() would be: memset(array, 0, 8 * sizeof(int)); However, I've seen the following in a piece of code:...
8
by: Wayne Shu | last post by:
Why there has such a rule for the template non-type argument?? but address of an object of external linkage is acceptable!! e.g. template <int *p> class C; int i; int arr;
3
by: klaritydefect | last post by:
Hi, I am receving the following error when I run my application (build on C ++ code) Program received signal SIGSEGV, Segmentation fault si_code: 1 - SEGV_MAPERR - Address not mapped to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.