Hi.
I need help with my code.
I'm trying to run unmanaged code from my C# code.
C++ Code
Result_t oemGetImage(PBYTE pImageBuffer,
PDWORD pdwSize, WORD nTop,
WORD nLeft, WORD nRight,
WORD nBottom, WORD nSkip,
WORD nBits, FileFormat_t nFormat,
WORD nWhiteValue,
WORD nExposeAttempts, WORD nGap,
BOOL Invert, void (*fpProgress) (WORD));
I don't know what to do with pImageBuffer, pdwSize or void (*fpProgress) (WORD)).
In C++ I execute this function like this:
BYTE *pBufor;
pBufor = new BYTE[MAX_IMAGE_SIZE];
DWORD *pSize;
pSize = new DWORD;
oemGetImage (pBufor,pSize, 0, 0, 200, 200, 1, 8, FF_RAW_GRAY, 200, 100, 55, false, NULL);
FF_RAW_GRAY is an enum with value of 1.
How can I declare pBufor which is a pointer to byte array?
And what to do with void (*fpProgress) (WORD))??
Thank you, for all your help.
Loading
VulpesPosted Jun 20, 2012, 2:40 PM
VulpesPosted Jun 22, 2012, 4:33 AM
The attribute you mention would only have been needed if the C++ function was using the Cdecl calling convention rather than the default Winapi (or StdCall) calling convention which evidently it was not.
PeterPosted Jun 21, 2012, 5:36 AM
Your solution worked perfectly!
However
[UnmanagedFunctionPointer(CallingConvenction.Cdecl)]
can't be resolved in my solution. Luckily everything worked fine without this line.
My definition for this function looks like this:
private extern static int oemGetImage([In, Out]byte[] pImageBuffer,
ref uint pdwSize, uint nTop,
uint nLeft, uint nRight,
uint nBottom, uint nSkip,
uint nBits, uint nFormat,
uint nWhiteValue,
uint nExposeAttempts, uint nGap,
bool Invert, [MarshalAs(UnmanagedType.FunctionPtr)]Progress fpProgress);
public delegate void Progress(ushort us);
and execution
byte[] pBufor = new byte[width * height];
uint pSize = 0;
oemGetImage(pBufor, ref pSize, 0, 0, _width, _height, 1, 8, 1, 220, 50, 35, false, null);
Thank you so much!