FYI .Net 4 Incompatibility
Posted: 15 May 2010 07:59 AM   [ Ignore ]
New Member
Rank
Total Posts:  6
Joined  2010-04-19

Hi

I have noticed that the SDK is incompatible with .Net 4 due to the new System.Guid.  Use earlier .Net assemblies to save you lots of pain.

Profile
 
 
Posted: 16 May 2010 03:48 PM   [ Ignore ]   [ # 1 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

The multicam dll in the SDK is the native dll. As such it uses Window native GUID type.
Exactly what file is not compatible with .net 4?

Profile
 
 
Posted: 16 May 2010 11:30 PM   [ Ignore ]   [ # 2 ]
New Member
Rank
Total Posts:  6
Joined  2010-04-19

.Net 4 appears to have a different system.guid to the other .net versions.  I haven’t looked into the difference I have just changed the assemblies I use.

The following routine:

  Public Declare Function CLEyeGetCameraUUID Lib “CLEyeMulticam.dll” (ByVal camId As Integer) As System.Guid

unbalances the stack when called under .Net4 but not under previous .Net versions.  I checked the usual suspects such as processor target etc.

So I would guess that the .Net4 System.Guid no longer mirrors the Windows native GUID.

Profile
 
 
Posted: 16 May 2010 11:33 PM   [ Ignore ]   [ # 3 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

I doubt anything changed from 3.5 to 4.0 regarding the System.Guid. Are you running this on x64 OS? How are you compiling your program? As “Any CPU” or “x86”?

Profile
 
 
Posted: 17 May 2010 12:10 AM   [ Ignore ]   [ # 4 ]
New Member
Rank
Total Posts:  6
Joined  2010-04-19

I am running on XP with processor target of ‘x86’

Steps To Reproduce:

Create a new WinForms application in VB2010

1. Replace the form1.vb code with:

Public Class Form1
  Public Declare Function CLEyeGetCameraCount Lib “CLEyeMulticam.dll” () As Integer
  Public Declare Function CLEyeGetCameraUUID Lib “CLEyeMulticam.dll” (ByVal camId As Integer) As System.Guid
  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    If CLEyeGetCameraCount() > 0 Then
      Debug.Print(“Camera(0).UUID=” & CLEyeGetCameraUUID(0).ToString)
    End If

  End Sub
End Class

2.  Save the project

3.  Run the project.  Will error with PInvokeStackImbalance.

4.  Change the framework to .Net3.5 (Right click project in solution explorer and select properties.  Select the compile tab.  Click Advanced Compile options)

5.  Once the project has been saved and re-opened, run the project again

6.  Program will function normally and display the first cameras GUID in the immediate window

Profile
 
 
Posted: 17 May 2010 06:55 PM   [ Ignore ]   [ # 5 ]
Administrator
Avatar
RankRankRankRank
Total Posts:  585
Joined  2009-09-17

I verified and there is no change in System.Guid between 3.5 and 4.0.
What has changed is the PInvokeStackImbalance MDA settings. In .net 4.0, this has been activated by default.

You can do two things to work around this issue:

Disable the warning:
  1. In VS2010, go to Debug -> Exceptions -> Managed Debug Assistants and uncheck PInvokeStackImbalance.

  2. Define CLEyeGetCameraUUID like this (it should be _cdecl anyways):

[DllImport("CLEyeMulticam.dll"CallingConvention CallingConvention.Cdecl)]
public static extern Guid CLEyeGetCameraUUID(int camId); 

AlexP

Profile
 
 
Posted: 17 May 2010 11:34 PM   [ Ignore ]   [ # 6 ]
New Member
Rank
Total Posts:  6
Joined  2010-04-19

Hi Alex

Thanks for the help, I have discovered the following:

1.  The MDA for PInvokeStackImbalance was on whether I was using .Net3 or .Net4.  Turning this off let the code work but left me with a feeling that I was disabling the error to mask the problem, even if the problem had been dealt with

2.  Changing my external function reference as you suggest from:
      Public Declare Auto Function CLEyeGetCameraUUID Lib “CLEyeMulticam.dll” (ByVal camId As Integer) As System.Guid
    To:

<DllImport("CLEyeMulticam.dll"CallingConvention:=CallingConvention.Cdecl)> Public Function CLEyeGetCameraUUID(ByVal cameraIndex As Integer) As System.Guid
        End 
Function 

Fixed the problem for me.  I had to move my declaration from a class to a module (make static) and import System.RunTime.Interopservices for this to work under VB

Changing the calling convention to StdCall, which is the default, created the error again.

So maybe earlier .Net versions just quitely cleaned up the stack after the call with StdCall while .Net4 correctly reports that it is imbalanced?  The correct data arrives either way.

Profile
 
 
 
 


RSS 2.0     Atom Feed