CodefoundryDE / LegacyWrapper

LegacyWrapper uses a x86 wrapper to call legacy dlls from a 64 bit process (or vice versa).
MIT License
79 stars 20 forks source link

Problem with Out #2

Closed ante75 closed 6 years ago

ante75 commented 7 years ago

Hello everyone I chiamao Alex, I'm trying to use WrapperClient but I have a problem I get an error by doing this:

private delegate Int32 H264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, out H264_DVR_DEVICEINFO lpDeviceInfo, out int error, SocketStyle socketstyle);

static public Int32 WrapperH264_DVR_Login(string sDVRIP, ushort wDVRPort, string sUserName, string sPassword, out H264_DVR_DEVICEINFO lpDeviceInfo2, out int error, SocketStyle socketstyle)
 {
    using (var client = new WrapperClient("NetSdk.dll"))
     {
       error = 0;
       H264_DVR_DEVICEINFO lpDeviceInfo = new H264_DVR_DEVICEINFO();
       Int32 x = (Int32)client.Invoke<H264_DVR_Login>("H264_DVR_Login", new object[] { sDVRIP, 
                       wDVRPort, sUserName, sPassword, lpDeviceInfo, error, socketstyle });
       lpDeviceInfo2 = lpDeviceInfo;
       return x;
      }
}

ERROR: System.Runtime.Serialization.SerializationException: 'Il tipo 'TestVideo.H264_DVR_DEVICEINFO' nell'assembly 'TestVideo, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' non è contrassegnato come serializzabile.'

THE PROBLEM IS IN Out H264_DVR_DEVICEINFO lpDeviceInfo ???

who can help me? thank you all

zalintyre commented 7 years ago

From the error message I guess your class H264_DVR_DEVICEINFO needs a [Serializable] attribute on top. The error message is not related to out parameters.

Kind Regards, Franz

ante75 commented 7 years ago

Thanks for the help, I added [Serializable]
Now the mistake became this System.Runtime.Serialization.SerializationException: 'End of stream reached before the analysis is complete.'

zalintyre commented 7 years ago

Hi, can you paste some details of the Exception (stacktrace, message, etc)?

ante75 commented 7 years ago

I copied the exception details, can you understand something?

Si è verificata l'eccezione System.Runtime.Serialization.SerializationException
  HResult=0x8013150C
  Messaggio=Fine del flusso raggiunta prima del termine dell'analisi.
  Origine=mscorlib
  Analisi dello stack:
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser.Run()
   at System.Runtime.Serialization.Formatters.Binary.ObjectReader.Deserialize(HeaderHandler handler, __BinaryParser serParser, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream)
   at LegacyWrapperClient.Client.WrapperClient.Invoke[T](String function, Object[] args) in D:\Programmierung\CSharp\LegacyWrapper\LegacyWrapperClient\Client\WrapperClient.cs:line 75
   at TestVideo.XMSDK.WrapperH264_DVR_Login(String sDVRIP, UInt16 wDVRPort, String sUserName, String sPassword, H264_DVR_DEVICEINFO& lpDeviceInfo, Int32& error, SocketStyle socketstyle) in C:\Users\Operatore\Desktop\ZDIR\TEST VIDEO\TestVideo\TestVideo\XMSDK.cs:line 595
   at TestVideo.MainWindow.Window_Loaded(Object sender, RoutedEventArgs e) in C:\Users\Operatore\Desktop\ZDIR\TEST VIDEO\TestVideo\TestVideo\MainWindow.xaml.cs:line 131
   at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised)
   at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args)
   at System.Windows.BroadcastEventHelper.BroadcastEvent(DependencyObject root, RoutedEvent routedEvent)
   at System.Windows.BroadcastEventHelper.BroadcastLoadedEvent(Object root)
   at MS.Internal.LoadedOrUnloadedOperation.DoWork()
   at System.Windows.Media.MediaContext.FireLoadedPendingCallbacks()
   at System.Windows.Media.MediaContext.FireInvokeOnRenderCallbacks()
   at System.Windows.Media.MediaContext.RenderMessageHandlerCore(Object resizedCompositionTarget)
   at System.Windows.Media.MediaContext.RenderMessageHandler(Object resizedCompositionTarget)
   at System.Windows.Interop.HwndTarget.OnResize()
   at System.Windows.Interop.HwndTarget.HandleMessage(WindowMessage msg, IntPtr wparam, IntPtr lparam)
   at System.Windows.Interop.HwndSource.HwndTargetFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled)
   at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o)
   at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
   at System.Windows.Threading.ExceptionWrapper.TryCatchWhen(Object source, Delegate callback, Object args, Int32 numArgs, Delegate catchHandler)
   at System.Windows.Threading.Dispatcher.LegacyInvokeImpl(DispatcherPriority priority, TimeSpan timeout, Delegate method, Object args, Int32 numArgs)
   at MS.Win32.HwndSubclass.SubclassWndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam)
zalintyre commented 7 years ago

Looking for the HResult code with this link tells me that A mismatch has occurred between the runtime type of the array and the sub type recorded in the metadata.

So can you check all your type definitions for your delegate match the function in your dll?

ante75 commented 7 years ago

this is the original call:

H264_DVR_DEVICEINFO dvrdevInfo = new H264_DVR_DEVICEINFO(); int nError; int nLoginID = XMSDK.H264_DVR_Login(ip, port, User, Password, out dvrdevInfo, out nError, SocketStyle.TCPSOCKET);

I can not understand what it refers to the error COR_E_SERIALIZATION 0x8013150c A mismatch has occurred between the runtime type of the array and the sub type recorded in the metadata.

zalintyre commented 7 years ago

Have you got a proper API description of your desired function and its parameters at hand?

ante75 commented 7 years ago

I try to find some information

For the moment thank you