1. Array from C++ DLL to Euphoria

I have DLL (with sources), that provides some data in an array. Is it possible to display the array in a sequence? I mean, without a physical copy of data.

new topic     » topic index » view message » categorize

2. Re: Array from C++ DLL to Euphoria

TheresNoTime said...

I have DLL (with sources), that provides some data in an array. Is it possible to display the array in a sequence? I mean, without a physical copy of data.

Not that I know of. A physical copy of the data (typically via some form of peek() ) is required to get this into a sequence.

new topic     » goto parent     » topic index » view message » categorize

3. Re: Array from C++ DLL to Euphoria

Maybe, shared memory or something like that? Is it possible to see the array is physically located in the DLL? For example, if we get a pointer to it?

new topic     » goto parent     » topic index » view message » categorize

4. Re: Array from C++ DLL to Euphoria

TheresNoTime said...

Maybe, shared memory or something like that? Is it possible to see the array is physically located in the DLL? For example, if we get a pointer to it?

You can get a pointer to it by using define_c_var. In order to do anything with it, you'll need to use peeks and pokes. Eventually, when memstructs are figured out, there will be ways to work with it in a more natural fashion.

Could you tell us more about what you are trying to do? Based on what you've said, I think you'll want to probably not peek the whole thing, but just what you need when you need it, and poke values back as required. But that's just my speculation based on what you've said.

Matt

new topic     » goto parent     » topic index » view message » categorize

5. Re: Array from C++ DLL to Euphoria

TheresNoTime said...

Maybe, shared memory or something like that? Is it possible to see the array is physically located in the DLL? For example, if we get a pointer to it?

You'd still need to peek at that pointer and make a copy of it to see what's inside of it (though not necessarily a copy of the whole thing).

The only way to avoid a peek phase would be if the DLL itself understood Euphoria's datastructures and returned an Euphoria sequence. This would require modifying the DLL itself and it is a fairly advanced technique. The only library off the top of my head that does this is wxEuphoria.

Also, is the C++ DLL returning an arra of primitive datatypes (eg. int[] or char[] or bool[], etc) or an array of C++ objects? Dealing with the latter directly in Euphoria is another can of worms entirely.

new topic     » goto parent     » topic index » view message » categorize

6. Re: Array from C++ DLL to Euphoria

jimcbrown said...

Also, is the C++ DLL returning an arra of primitive datatypes (eg. int[] or char[] or bool[], etc) or an array of C++ objects?

unsigned long

new topic     » goto parent     » topic index » view message » categorize

7. Re: Array from C++ DLL to Euphoria

Could you tell us more about what you are trying to do? Based on what you've said, I think you'll want to probably not peek the whole thing, but just what you need when you need it, and poke values back as required. But that's just my speculation based on what you've said.

Matt

SAFEARRAY* DisplayBuffer = NULL;
 
int __stdcall takeScreen() { 
  if (DisplayBuffer) { 
    SafeArrayDestroy(DisplayBuffer); 
    DisplayBuffer=NULL; 
  } 
  HRESULT rc = VirtualDisplay->TakeScreenShotToArray(0, DisplayWidth, DisplayHeight, &DisplayBuffer); 
  return SUCCEEDED(rc) ? EU_TRUE : EU_FALSE; 
}

I want to get screenshot and export it, pixel-by-pixel, to my program, written in Euphoria. May be, "takeScreen" must return pointer to DisplayBuffer?

P.S. Why TABs not converted to two spaces inside eucode tag? It is inconvenience.

new topic     » goto parent     » topic index » view message » categorize

8. Re: Array from C++ DLL to Euphoria

TheresNoTime said...
mattlewis said...

Could you tell us more about what you are trying to do? Based on what you've said, I think you'll want to probably not peek the whole thing, but just what you need when you need it, and poke values back as required. But that's just my speculation based on what you've said.

SAFEARRAY* DisplayBuffer = NULL; 
 
int __stdcall takeScreen() { 
  if (DisplayBuffer) { 
    SafeArrayDestroy(DisplayBuffer); 
    DisplayBuffer=NULL; 
  } 
  HRESULT rc = VirtualDisplay->TakeScreenShotToArray(0, DisplayWidth, DisplayHeight, &DisplayBuffer); 
  return SUCCEEDED(rc) ? EU_TRUE : EU_FALSE; 
}

I want to get screenshot and export it, pixel-by-pixel, to my program, written in Euphoria. May be, "takeScreen" must return pointer to DisplayBuffer?

P.S. Why TABs not converted to two spaces inside eucode tag? It is inconvenience.

Egad! A SafeArray. I recommend that you download EuCOM. It has stuff for handling them. In particular, they are in variant.ew. To wrap, you should be able to:

include variant.ew 
constant DisplayBuffer = define_c_var( the_dll, "DisplayBuffer" ) 
 
? get_array( peek4u( DisplayBuffer ) ) 

Matt

new topic     » goto parent     » topic index » view message » categorize

9. Re: Array from C++ DLL to Euphoria

Thanks! But I do not understand how Euphoria find the internal structure of the array? I guess, Euphoria always sees it as a sequence of bytes?

new topic     » goto parent     » topic index » view message » categorize

10. Re: Array from C++ DLL to Euphoria

TheresNoTime said...

Thanks! But I do not understand how Euphoria find the internal structure of the array? I guess, Euphoria always sees it as a sequence of bytes?

For C++, an array is just a set of contiguous bytes, so all Euphoria needs to know is the RAM address of the first element, the size (in bytes) of each element, and how many elements in the array.

new topic     » goto parent     » topic index » view message » categorize

11. Re: Array from C++ DLL to Euphoria

TheresNoTime said...

Thanks! But I do not understand how Euphoria find the internal structure of the array? I guess, Euphoria always sees it as a sequence of bytes?

A SAFEARRAY is a special thing that Microsoft created for COM / ActiveX / OLE Automation. It's not just a native C++ array. There is a whole API for dealing with them.

Matt

new topic     » goto parent     » topic index » view message » categorize

12. Re: Array from C++ DLL to Euphoria

mattlewis said...
TheresNoTime said...

Thanks! But I do not understand how Euphoria find the internal structure of the array? I guess, Euphoria always sees it as a sequence of bytes?

A SAFEARRAY is a special thing that Microsoft created for COM / ActiveX / OLE Automation. It's not just a native C++ array. There is a whole API for dealing with them.

Matt

I have idea: transform SAFEARRAY with screenshot to more compact array. I needn't full information about pixels. It is possible to squeeze RGB to one byte. I can see two methods:

1. Eight bits composed by three bits from R, three from G and two from B. May be even this: four bits of R and four bits G. I know in advance that the blue color will rarely see in my screenshots.

2. (R+G+B)/3. So, we get brightness (from 0 to 255). Other formula: (R+G+B)>>2 (from 0 to 191).

Do you think this makes sense? Whether such transformation will be compensated by simplifying and/or accelerating export of an byte[] to Euphoria program?

new topic     » goto parent     » topic index » view message » categorize

13. Re: Array from C++ DLL to Euphoria

Why don't you simply save the window  to some video format like PCX. 
Then when you need to check some pixels display the window on a virtual 
window to do your processing. 
You don't have to calculate all that compression and you can use a video 
format that you can find source for from the web. 

new topic     » goto parent     » topic index » view message » categorize

14. Re: Array from C++ DLL to Euphoria

TheresNoTime said...
mattlewis said...
TheresNoTime said...

Thanks! But I do not understand how Euphoria find the internal structure of the array? I guess, Euphoria always sees it as a sequence of bytes?

A SAFEARRAY is a special thing that Microsoft created for COM / ActiveX / OLE Automation. It's not just a native C++ array. There is a whole API for dealing with them.

Matt

I have idea: transform SAFEARRAY with screenshot to more compact array. I needn't full information about pixels. It is possible to squeeze RGB to one byte. I can see two methods:

1. Eight bits composed by three bits from R, three from G and two from B. May be even this: four bits of R and four bits G. I know in advance that the blue color will rarely see in my screenshots.

2. (R+G+B)/3. So, we get brightness (from 0 to 255). Other formula: (R+G+B)>>2 (from 0 to 191).

Do you think this makes sense? Whether such transformation will be compensated by simplifying and/or accelerating export of an byte[] to Euphoria program?

It's not exactly clear to me what you're proposing to do. The current get_array() routine pulls the entire thing. If you only need part of it, and it's not very big, you should be able to modify the code fairly simply.

But a SAFEARRAY is not a native C++ array. It's a COM thing, so it can be used by C++, C or VB. I think that it's really more of a native VB array, as I don't think you need to use any special API when dealing with a SAFEARRAY in VB (I could be wrong on this). But for C/C++ you need to use the SafeArray API.

The individual elements are Variants, which are like the COM version of a euphoria object. It can hold anything. Take a look at the VT_* constants in variant.ew to get an idea of the stuff that a Variant can hold. Note that variant.ew also has stuff for reading and writing to Variants.

Matt

new topic     » goto parent     » topic index » view message » categorize

15. Re: Array from C++ DLL to Euphoria

Thanks for explanations. Now I am sure that EuCOM meets my needs exactly.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu