Re: calling a method in a dll that returns a pointer
Ravi Kiran <[email protected]> Thu, 4 Jan 2007 07:34:15 -0500
| Newsgroups | gmane.comp.windows.devel.jawin |
|---|---|
| Message-ID | <LISTSERV%[email protected]> |
On Wed, 3 Jan 2007 15:37:11 -0500, Mcnamara, Sean D. <[email protected]> wrote: >If your "unsigned char*" is pointing to a single character, this might >be possible. My intuition, based on the function name you specified, >suggests that this is an array of raw 1-byte little-endian data of an >image. There are documented ways to deal with VT_ARRAYs (SafeArrays in >COM) with Jawin, because SafeArrays have a dope vector which specifies >the length of the array. Looking at the native source of Jawin, it seems >like it is not well suited to returning native arrays at all, because >AFAIK a character pointer does not imply any kind of length of an array >in any language. COM gets away with returning arrays without a length >because SafeArrays specify the length in the binary format of the array, >very much like a Java array does (so much so that the native code >streams one type into another without changing the format of it.) > >I am rather surprised that your GetImageBuffer method doesn't have an >out parameter specifying the length of the returned buffer. I would be >really surprised if the method returned a single character, in which >case it's more sane to get the result, but otherwise it seems that the >compiler you're using should somehow include a dope vector with arrays. >When marshalling back the data, the first thing Jawin would need to know >(even if this were supported) is the length of the array to allocate. >You might need to manually specify this in the instruction string. > >What compiler and version is the DLL compiled with? (hint: use >Dependency Walker and look at the DLL's dependencies on e.g. >msvcrt*.dll, libc6.dll, etc. for a clue if you have a closed source >DLL.) > >Also: I'm not sure what your level of proficiency is with Jawin yet, so >if you haven't already, read *everything* on >http://jawinproject.sourceforge.net/jawinuserguide_dll.html and >http://jawinproject.sourceforge.net/instruction_docs.html > >The minimum you should be able to code is the generic invoke/bytestream >process, including everything but the instruction string (which I'm not >too sure of myself right now.) All of that is boilerplate code. > >You may want to try a very basic instruction string and examine the >byte[] contents of the invoke method. If you get a single 32-bit value >(the pointer to the array that the method returns) and nothing else, you >then obviously have to find out how to coerce Jawin to perform >"indirection" on this pointer to get to the first element of the array. >Of course, without knowing where the array ends, you could keep scanning >the rest of your process's virtual address space as part of the array >until you get a page fault. :) If this native method was written without >any way to get the length of the returned buffer, you wouldn't be able >to use it in either C or Java. > >-Sean > >-----Original Message----- >From: Discussion of Java/Win32/COM integration with Jawin >[mailto:[email protected]] On Behalf Of Ravi Kiran >Sent: Wednesday, January 03, 2007 3:42 AM >To: [email protected] >Subject: [JAWIN] calling a method in a dll that returns a pointer > >hi,this is ravikiran, > >i am using jawin to call thirdparty dlls. > >in my dll there is a method with the following signature > >unsigned char* SF_GetImageBuffer() > >i have no idea how to make a call to the above method, so that i can get >the content of the pointer that the method is returning. > >can any one help me how to do this in jawin. i am new to jawin and i >didnt find any examples that suite my requiements. > >please help me. > >thanks in advance. hi, i am using the following code to get the content of the pointer returned by the GetBufferImage() method-- FuncPtr fp3=new FuncPtr("SFR300","SF_GetImageBuffer"); byte[] result1=null; result1=fp3.invoke(":n384:",0,nb,null,ReturnFlags.CHECK_FALSE); the length of the data contained in the memory location pointed by the pointer returned by the method is predefined as 384 bytes. is this the correct form of instruction string i am using to get the bytes stored in the pointer returned by the method. plz help me, i am struggling with specifying the correct instruction string. thanx in advance.