help passing a parameter when using PInvoke

  • Thread starter Thread starter rocio
  • Start date Start date
R

rocio

I have a DLL function with this signature:

CamOpen (HANDLE* phcam)

I wrote its declaration in VB.NET the following way:

Declare Function CamOpen Lib "veocamampi.dll" (ByVal phCam as
IntPtr)

And I'm calling it with this statement:

Dim hCam as IntPtr

Try
CamOpen (hCam)
catch ex as Exception
.......
end try

The exception I get is: "Bad arguments or incorrect declaration in CamOpen"

Now, notice that the original DLL declaration declares phcam as a pointer to
HANDLE........am I missing something here?
What type of marshaling do I need to do here?

tx in advance!
 
You should think more about what the function is trying to *do* than just
how to make everything compile. It's trying to return to you a handle,
right? Well, let's say that a 'handle'='IntPtr' and do something like this:

Declare Function CamOpen Lib "veocamampi.dll" (ByRef phCam as IntPtr)

Dim hCam as IntPtr

CamOpen( hCam )

Paul T.
 
Thanks Paul, I tried this before, but I still get the same error:

Bad Arguments or incorrect declaration in CamOpen.

Just wondering if anyone has tried before to use the SDK for the VEO camera.

-rocio
 
Use the dependency viewer to check the exported function names from the DLL.
Verify that the function CamOpen ***does not*** have any parameter
information in its exported name. Maybe it's not declared extern "C"...

You *did* set the phCam parameter to *ByRef*, right?

Paul T.
 
OK. The actual definition of the function I need to call is:

VEOCAMAPI_API HRESULT CamOpen(HANDLE* phCam);
I wrote its declaration in VB.NET the following way:

Declare Function CamOpen Lib "veocamampi.dll" (ByRef phCam as
IntPtr)

And I'm calling it with this statement:

Dim hCam as IntPtr

Try
CamOpen (hCam)
catch ex as Exception
.......
end try

The exception I get is: "Bad arguments or incorrect declaration in CamOpen"
I'm guessign it is an incorrect declaration of CamOpen, any ideas on this?
 
This is what I see in the veocamapi.h file:

#ifdef _cplusplus
extern "C" {
#endif

VEOCAMAPI_API HRESULT CamOpen(HANDLE *pHCam);
VEOCAMAPI_API HRESULT CamClose(HANDLE pHCam);
VEOCAMAPI_API HRESULT CamStartPreview(HANDLE pHCam, HWND previewhwnd);
: : :

#ifdef _cplusplus
}
#endif

what is the dependency viewer? How do I use this?

-rocio
 
Maybe the return type is missing? Something like:

Declare Function CamOpen Lib "veocamampi.dll" ( ByRef phCam as IntPtr ) as
Int32

Paul T.
 
If I tried this I get a MissingMEthodException ..... CamOpen is not defined
that way.

-rocio
 
It's "depends.exe". It, when you open a DLL with it, will show you the list
of imports that the DLL uses from other DLLs, and the list of exported
functions. If those are the declarations, though, it seems likely that the
..NET CF code is wrong, not the DLL code.

Paul T.
 
It's something obvious, then. You *have* to define the return value. Find
the veocamampi.dll file (is that *spelled* right?), and use depends.exe on
it, as I mentioned.

Paul T.
 
The left pane shows the dependency graph for the DLL. This DLL depends only
on coredll.dll.

The right/top pane shows the functions imported from the DLL selected, if
any, in the left pane. If you click on coredll.dll, you'll see a
significant list of things that the camera DLL is using.

The right/bottom pane shows the functions exported from the DLL. Since you
can see that no return type or parameters are indicated for the DLL in
question, it was properly compiled as a C, rather than C++, DLL and the
function names are not decorated.

Your declaration is wrong because you spelled the name of the DLL
incorrectly.

Paul T.
 
Back
Top