Jump to content
RTollison

Copy bitmap from one app to another app bitmap

Recommended Posts

 I have a running app that has a bitmap object on it and i have a dll that creates a bitmap. without saving to disk or clipboard, i need to copy from dll bitmap to the app bitmap. i have the handle of the app in the dll and have the workings of trying to find the bitmap object in the app. but i need to figure out how would i go about copying the bitmap over. 

Share this post


Link to post

From the title it sounds as if you need to pass a bitmap between two applications, but your description makes it sound as if you need to pass a bitmap from a DLL to an application using that DLL.

Between applications: Save the bitmap to a memory stream and use WM_COPYDATA to copy the data. From DLL to application: Just pass a pointer or a bitmap handle.

 

Maybe work a bit more on the problem description?

Share this post


Link to post
6 hours ago, Anders Melander said:

From DLL to application: Just pass a pointer

Warning: object such as TBitMap in the DLL will not be recognized as a TBitmap in the EXE, unless they both use run-time packages.

Share this post


Link to post
5 minutes ago, FPiette said:

Warning: object such as TBitMap in the DLL will not be recognized as a TBitmap in the EXE, unless they both use run-time packages.

I think Anders meant pointer to WinAPI bitmap handle

Share this post


Link to post

Ok here is overall process/issue. i have a microfocus cobol program that uses a runtime (exe) to open an cobol compiled object file. in that program it has logic for printing bitmaps. However, it requires that the bitmap be a saved file. I had created the dll to load base64 encoded data and converted to bitmap and saved to disk. Then the cobol program would read the file and print then delete the bitmap file. But the bitmap is for a customers signature that quality control says 'No you will not save it to disk and delete due to security reasons.' So now i need to change the process so that the dll can copy the bitmap to the cobol programs bitmap handle. i figure that i will have to change the cobol to open a blank/empty bitmap and then send that handle to the dll to get the signature bitmap loaded into the cobol program. Cobol side is limited in what it can do, so the dll was needed to read/convert/save the bitmap.

 

Since this is not a full delphi process i just posted a general question and then would work out the details on my own.

Share this post


Link to post

If you have no control over cobol app and it only reads from file, there's little you can do except hooking CreateFile & FileWrite WinAPI's. Or even use filesystem driver to represent a piece of RAM as a drive but that unlikely is an option.

 

In theory, if you're lucky and the app uses only CreateFile without additional file-specific checks, you can feed it with path to a pipe which you will create and control.

Edited by Fr0sT.Brutal

Share this post


Link to post
1 hour ago, RTollison said:

Ok here is overall process/issue. i have a microfocus cobol program that uses a runtime (exe) to open an cobol compiled object file. in that program it has logic for printing bitmaps. However, it requires that the bitmap be a saved file. I had created the dll to load base64 encoded data and converted to bitmap and saved to disk. Then the cobol program would read the file and print then delete the bitmap file. But the bitmap is for a customers signature that quality control says 'No you will not save it to disk and delete due to security reasons.' So now i need to change the process so that the dll can copy the bitmap to the cobol programs bitmap handle. i figure that i will have to change the cobol to open a blank/empty bitmap and then send that handle to the dll to get the signature bitmap loaded into the cobol program. Cobol side is limited in what it can do, so the dll was needed to read/convert/save the bitmap.

 

Since this is not a full delphi process i just posted a general question and then would work out the details on my own.

If the Cobol programm passes a HBITMAP to the DLL procedure the following may work:

 

In the DLL procedure,

  1. create a TBItmap object
  2. assign the passed HBITMAP to that objects Handle property
  3. adjust with and height of the bitmap object to the signature bitmap's dimensions, if necessary
  4. draw the signature bitmap on the bitmap object's canvas (using Assign instead may recreate the bitmap Handle)
  5. set the bitmap Handle to 0 to disconnect the passed HBITMAP from the TBitmap object
  6. destroy the temporary TBitmap object.

If the Cobol program can get you a HDC from its bitmap you can pass that to the DLL instead of a HBITMAP and use BitBlt directly to copy the signature to it. That requires the Cobol program to properly size the bitmap first, though.

Share this post


Link to post

since you can't use the disk for security reasons, you could create a type (defined by the programmer) and store it in the memory (on the clipboard as MS Windows does) that stores the bitmap data (cloaked or not, compressed or no, etc) then that the other application could query and review for its use?  ... a kind of new type of data registered in the system for specific use in your application, got it?

Share this post


Link to post

that is why i was asking about copying a bitmap from dll to another bitmap in a separate app. in the cobol side the loadbitmapfromfile is what creates the bitmap and assigns it a handle. I was figuring on loading up a bitmap that is just empty/blank. then try to copy the dll bitmap into that hanlde. at this point i do not know if it will work but that is what i have to work with.

Share this post


Link to post

i am hoping that since the signature comes from the CreditCard machine that they are always the same size. that is what i am hoping for then the copying of the bitmap wouldnt have to worry about the size.

 

Share this post


Link to post

and to confirm the cobol side creates handle for the bitmap. it is defind in the cobol program as 

01  A-BITMAP              HANDLE.

so it is not like a bitmap object in delphi. that again is an obstacle that requires me to copy via handle and not bit-by-bit (only guessing again).

i guess i could create a bitmap in the dll and assign it the handle from cobol if that is possible, as long as i dont save the bitmap to disk.

Edited by RTollison

Share this post


Link to post

If that handle is WinAPI handle then yes, you can replace that loadbitmapfromfile with call to your DLL returning the handle

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×