declare function GdipBitmapUnlockBits lib "GDIPlus" (bitmap as Ptr, bitmapData as Ptr) as integer
dim sBitmap as BITMAP
dim sBitmapData as BitmapData
dim r as integer = GdipBitmapUnlockBits(sBitmap,sBitmapData)
but this compiles without error:
declare function GdipBitmapUnlockBits lib "GDIPlus" (byref bitmap as BITMAP, byref bitmapData as BitmapData) as integer
dim sBitmap as BITMAP
dim sBitmapData as BitmapData
dim r as integer = GdipBitmapUnlockBits(sBitmap,sBitmapData)
Have you done this before and verified that the correct pointers are being passed?
ByRef is correct. When an external function expects a pointer to a piece of data, you can declare the parameter as a generic Ptr, or you can declare it ByRef as the desired type. Either way, you are telling the compiler that the external function expects a pointer to some data. If the intent is that the function will modify the data before returning, ByRef is probably the right choice.
This is true for all types, structures or otherwise: you can either create a memoryblock with the right size, populate it, and pass the memoryblock’s pointer to the external function; or you can declare the external function using a ByRef parameter of the appropriate type and pass in the value directly. Either way, the compiler will generate code which gets a pointer to the bit of memory you’ve named and passes it along to the external function.