P/Invoke parameter marshalling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello,

I am using a video encoder from an existing DLL (MSFCEnc.dll, from Microsoft
Portrait). I manage to call the DLL functions, but one of them, the
setParams(), always returns false... I would like to check with you that I
used the correct correspondance between C++ parameters and C# ones.

C++:

//Set parameters before start compressing
MSFCENC_API HRESULT MSFCEnc_SetParams(
DWORD dwBandwidth, // [in] bps
int nFrameRate, // [in] default 15 fps
int nKeyFrameInterval, // [in] default 5 second
int nVersion, // [in] must be 2
int nOutputBitCount, // [in] 16 or 24, represent RGB565 and RGB24 format
respectively
BOOL bQualityImprove);

C#:

[DllImport("MSFCEnc.dll", EntryPoint="?MSFCEnc_SetParams@@YAJKHHHHH@Z")]
public static extern UInt32 SetParams(
UInt32 dwBandwidth,
Int32 nFrameRate,
Int32 nKeyFrameInterval,
Int32 nVersion,
Int32 nOutputBitCount,
Boolean bQualityImprove );

Call to the method:

UInt32 bandwidth = 56000;
Int32 frameRate = 15;
Int32 keyFrameInterval = 5;
Int32 version = 2;
Int32 outputBitCount = 24;
Boolean autoQualityImprove = true;

UInt32 paramOk = Encoder.SetParams(
bandwidth,
frameRate,
keyFrameInterval,
version,
outputBitCount,
autoQualityImprove);

paramOk always equals S_FALSE (1). I don't know if it is because of wrong
marshalling or because of badly chosen parameters values...

Thanks for the help,

Lionel Reyero
 
The declaration looks fine. Add SetLastError=true to it and check
GetLastWin32Error

-Chris
 
Also trying to call it with the same parameters from a C++ test harness
would be an easy way to answer the question of PInvoke definition validity

--
Alex Feinman
---
Visit http://www.opennetcf.org
The declaration looks fine. Add SetLastError=true to it and check
GetLastWin32Error

-Chris


Lionel Reyero said:
Hello,

I am using a video encoder from an existing DLL (MSFCEnc.dll, from
Microsoft
Portrait). I manage to call the DLL functions, but one of them, the
setParams(), always returns false... I would like to check with you that
I
used the correct correspondance between C++ parameters and C# ones.

C++:

//Set parameters before start compressing
MSFCENC_API HRESULT MSFCEnc_SetParams(
DWORD dwBandwidth, // [in] bps
int nFrameRate, // [in] default 15 fps
int nKeyFrameInterval, // [in] default 5 second
int nVersion, // [in] must be 2
int nOutputBitCount, // [in] 16 or 24, represent RGB565 and RGB24 format
respectively
BOOL bQualityImprove);

C#:

[DllImport("MSFCEnc.dll", EntryPoint="?MSFCEnc_SetParams@@YAJKHHHHH@Z")]
public static extern UInt32 SetParams(
UInt32 dwBandwidth,
Int32 nFrameRate,
Int32 nKeyFrameInterval,
Int32 nVersion,
Int32 nOutputBitCount,
Boolean bQualityImprove );

Call to the method:

UInt32 bandwidth = 56000;
Int32 frameRate = 15;
Int32 keyFrameInterval = 5;
Int32 version = 2;
Int32 outputBitCount = 24;
Boolean autoQualityImprove = true;

UInt32 paramOk = Encoder.SetParams(
bandwidth,
frameRate,
keyFrameInterval,
version,
outputBitCount,
autoQualityImprove);

paramOk always equals S_FALSE (1). I don't know if it is because of wrong
marshalling or because of badly chosen parameters values...

Thanks for the help,

Lionel Reyero
 
It's fine, the problem came from an error in the DLLImport entry point.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top