.net - Converting VB6 using RtlMoveMemory to C# -
I am trying to convert an existing VB6 application into C #. The application should use the API which was also written in VB6 and is an ActiveX DLL. I am using .NET Interop functionality to wrap this API so that I can use it in C #.
The problem is a bit of code that becomes a byte array, and then uses RtlMoveMemory () to move it with a C # code below in a composition, get. Collection Exception "Value does not fall into the expected category" Exception I have tried different variations of some marshaling along with this implementation, but I am slightly in depth in this field. Everything I tried in, it happened as an exception.
Using a RtlMoveMemory () will fix a solution, but using Marshalling will also be a solution better. Hopefully this is just a matter of adding dots.
VB6 code:
public declare sub below Lib Type "kernel 32.dll" nickname "RTLMovemary" in any form, as long as ByVal bytes) type IntEventStruct IntTventStruct call DWApi.ReadEvent (code, DBIndex, TTStr, interval, bytebuff, etc.) as a single end-type dim byteBuff (PACKETSIZE-1) as a long value in the form of double quality as TTag. ErrMsg) call MoveIt (dEvent, byte buff (0), lane (die)) C # code:
[DllImport ( "Kernel32.dll", EntryPoint = "RTLMowMomori")] Static Externx Zero Strike (object destination, object source, long length); Public infrastructure readEventStruct {public double timing; Public full quality; Public float value; } Byte [] bytebuff = new byte [BUFFER_SIZE]; ReadEventStruct dwRead = New ReadEventStruct (); This.dw.ReadEvent (pt.Plant, pt.Index, pt.Time, pt.Interval, Ref: bytebuff, ref error message); Move (dwRead, byte buff, martial. Dwreead); Related API documents for readEvent () (I do not have access to the source code):
This retrieves process data for a specified routine The point is at the same time. Calling Conference: Call DWPCAPI. Byte (Plant A string, _ iChannel as Long, _String as StartT, _value single, _buffer (), byte as _rrrmsg) buffer (): byte buffer that contains data returned You can use fixed memory with a pinned pointer (remember that C # uses managed memory, so the system is free to move your object around in memory). Personal Static Unprotected External Zero MoveMemory (Zero * Destination, Zero * SRC, DualImport ("Kernel32.dll", EntryPoint = "RtlMoveMemory")]: Intestinal size);
And in your method, something like this:
Fixed (byte * p = pointer) {// RtlMoveMemory call} Another way is martial.printstructure () .
Comments
Post a Comment