How to pass structure as pointer in C dll from C#

前端 未结 1 1037
-上瘾入骨i
-上瘾入骨i 2020-12-20 04:05

I am working on simple telephony application where I am changing the class of service of panasonic pbx extension. For that I am using \"Tapi32.dll\" which has methods in c++

相关标签:
1条回答
  • 2020-12-20 04:32
    [DllImport("Tapi32.dll", SetLastError=true)]
    unsafe private static extern int lineDevSpecific(int* hLine, IntPtr lpParams);
    
    unsafe static void Main(string[] args) {
        int vline=int.Parse("Ext101");
        int* hline=&vline;
    
        var sizeUserRec=Marshal.SizeOf(typeof(UserRec));
        var userRec=Marshal.AllocHGlobal(sizeUserRec);
        lineDevSpecific(hline, userRec);
        var x=(UserRec)Marshal.PtrToStructure(userRec, typeof(UserRec));
        Marshal.FreeHGlobal(userRec);
    }
    

    Take a look of this answer of question

    • Physical disk size not correct (IoCtlDiskGetDriveGeometry)

    You can find some more to make marshalling easier and more reusable.

    0 讨论(0)
提交回复
热议问题