Click here to Skip to main content
15,904,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is My structure:
C#
public struct _LineMove_TypeDef
{
    public  int _mIpn;
    public  int _ObjAcc;
    public  int _ObjDec;
    public  int _ObjSpeed;
     
    public  int[] _AxisDist;
    public  int[] _axisPos;
}


Here is my DllImport:
C#
[DllImport(DriveLibrary.dll, CallingConvention = CallingConvention.Cdecl, EntryPoint = _GoToPosInLine)]
public static extern bool _GoToPosInLine(ref LineMoveStruct._LineMove_TypeDef _lm, bool dr = true, bool p = false, bool sync = false, bool IntPol = false);


public bool GoToPosInLine(ref LineMoveStruct._LineMove_TypeDef _lm, bool dr = true, bool p = false, bool sync = false, bool IntPol = false)
{
    return _GoToPosInLine(ref _lm, dr, p, sync, IntPol);
}


What I have tried:

C#
public LineMoveStruct._LineMove_TypeDef _lmp;
int pos = 200;
_lmp = new LineMoveStruct._LineMove_TypeDef();

_lmp._axisPos = new int[8];
_lmp._AxisDist = new int[8];
_lmp._axisPos[0] = pos*2;
_lmp._axisPos[1] = _lmp._axisPos[0];
_lmp._axisPos[2] = _lmp._axisPos[1];
_lmp._AxisDist[0] = 30;
_lmp._AxisDist[1] = 30;
_lmp._AxisDist[2] = 30;
_lmp._mIpn = 1;
_lmp._ObjAcc = 10;
_lmp._ObjDec = 20;
_lmp._ObjSpeed =2000;

IntPtr pnt = Marshal.AllocHGlobal(Marshal.SizeOf(_lmp));

Marshal.StructureToPtr(_lmp, pnt, false);

LineMoveStruct._LineMove_TypeDef _lmp1;

_lmp1 = (LineMoveStruct._LineMove_TypeDef)Marshal.PtrToStructure(pnt, typeof(LineMoveStruct._LineMove_TypeDef));

Marshal.FreeHGlobal(pnt);

            
Motor._Mo.GoToPosInLine(ref _lmp);
Posted
Updated 16-May-16 1:06am
v2
Comments
Richard MacCutchan 16-May-16 6:50am    
What is the question?
Member 10958630 16-May-16 6:56am    
i want to pass Address of structure to function

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900