Re: How to cast a buffer pointer into a byte array



Cmtk Software wrote:
Hi all,

I'm developing a VC++.NET ATL in-process COM which dynamically
allocates a buffer in memory. After filling this buffer (with bitmap
image data) it is needed in the VB6 application which will reference
this COM I'm writing. The VB application needs this data as a byte
array ( Byte() ) because this is the type the OCX display control it
uses requires. Due to the frequent updates that will take place, I
cannot copy the data anywhere along the way.
I know that a possible solution is that the VB will define the byte
array and send it's VarPtr(byteArray(1)) to the C++ COM but that
doesn't sit right with the design of this COM because it might need
to serve several GUIs simultaneously.

So, the question is: Is there a way to send a pointer to the buffer
from the C++ COM to the VB (Possible ways: long value of the memory
address, VARIANT*, SAFEARRAY, etc.) and "wrap" this pointer with a VB
byte array type (cast this pointer to a byte() in VB)?
Any other creative solution will be most welcomed...

Thanks in advance!

Will the COMponent be serving other languages besides VB6?

If not, then the solution is to create and return an OLE SafeArray. VB can manage this (including disposing of it) as a normal Byte() array.

It's dead easy and quite fast using SafeArrayCreate (with VT_UI1). You just return the pointer to the descriptor as the result.

Ask if you need more info.

--

Jim Mack
MicroDexterity Inc
www.microdexterity.com
.



Relevant Pages

  • Re: some unanswered questions on C
    ... A pointer variable that's never been given a value. ... you don't know what memory you're modifying. ... >what i want to ask is that when i declare my buffer for fgets as ... "char *buffer" creates a pointer, ...
    (comp.unix.programmer)
  • Re: Library Design, f0dders nightmare.
    ... first demo mistake but I suggest to you that a sequence of blunders ... The stack is only used temporarily while creating the argv array. ... in the input buffer. ... so you are not wasting memory. ...
    (alt.lang.asm)
  • Re: HardBound and SoftBound (was "The State of Software")
    ... completely re-widen, to all of memory, and hence lose all protection. ... e.g. unless you know that malloc'ing is being done out of a common array ... I agree with Nick - SoftBound will fail to detect many common ... interpreted as a pointer across different architectures and memory models... ...
    (comp.arch)
  • Re: Problem with large arrays
    ... >am trying to using an array of signals that is just slightly larger) for the ... location of this very large memory. ... so that each pointer points to one row. ... row data structure and make the pointer point to it. ...
    (comp.lang.vhdl)
  • Re: gdb not catching out-of-bounds pointer
    ... that, for example, accesses one array from a pointer to another is ... provided the library writer knows what the compiler writer guarantees ... The portability of an allocator depends on the source of raw memory. ...
    (comp.unix.programmer)

Quantcast