Click here to Skip to main content
16,012,223 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an external declaration for a function in a dll I wish to call in a C# application.

The declaration is in the form

extern int WINAPI PassBuffer(void *lpDib);


where *lpDib refers to a bitmap or Dib to be passed to the dll. This I found in a '.h' file for the dll.

I'm not certain whats actually happening but I assume, lpDib is a pointer to the bmp I want to pass.

I've declared the function in my C# application as:

private static extern int PassBuffer(IntPtr lpDib);


Firstly, is this correct? and secondly how do i get the pointer to my bmp.

Its declared:

Bitmap bmp = new Bitmap("c:\\My.JPG");


How do I get the pointer of the bmp to hand to
PassBuffer(whatgoeshere);


Thanks for any help, I know its going to be a dumb question with a simple answer but its got me stumped...
Posted

1 solution

Try using this:

C#
// Create a new bitmap.
Bitmap bmp = new Bitmap("c:\\my.jpg");

// Lock the bitmap's bits.
Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);
System.Drawing.Imaging.BitmapData bmpData =
    bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite,
    bmp.PixelFormat);

// Get the address of the first line.
IntPtr ptr = bmpData.Scan0;


Then use the ptr in PassBuffer.
 
Share this answer
 
Comments
Simon Bang Terkildsen 2-Sep-11 18:14pm    
OP wrote:
That actually works better than my earlier solutions which were quite final..

It reports an image format error which suggests its reading the data in but not happy with how its laid out..

Perhaps I'm misunderstanding what it wants as lpDib, does it need the actual Dib file to be passed.

I can see what your solution achieves and it makes sense that would be what its after..
PAJP 3-Sep-11 14:32pm    
I still have issues with this..

The call requires a pointer to the Dib

<pre>extern int WINAPI PassBuffer(void *lpDib);</pre>

not a pointer to an array of bytes which is essentially the same thing but apparently in the code its not..

I suspect its a Win16 dll Im calling though all the other functions work fine but what it is seeing has to be spot on or it rejects it so any ideas etc would be appreciated.

I believe what i need to achieve is the same as in C where you would get a pointer to a bitmap i.e. <pre> ptr = &bmp </pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900