C#调用C/C++dll的方法(近期研究的课题)
维生素C的作用与摄取方法 #生活百科# #百科知识#
转载自https://www.cnblogs.com/bizca/p/4962559.html bizca大神的博客
NX Open,怎样取到面的环LOOP
在封装的ufun .NET库里面,对UF_MODL_ask_face_loops这个函数并没有封装,导致我们很多不便,那我们在.NET下怎样才能使用这个函数呢??当然是手动处理一下
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
public class AskFaceLoop
{
public LoopList[] AskFaceLoops(NXOpen.Tag faceTag)
{
System.IntPtr loopT;
NXOpen.Utilities.JAM.StartUFCall();
int errorCode = UF_MODL_ask_face_loops(faceTag,out loopT);
NXOpen.Utilities.JAM.EndUFCall();
if (errorCode != 0)
{
throw NXOpen.NXException.Create(errorCode);
}
System.IntPtr ptr = loopT;
List<LoopList> loopList = new List<LoopList>();
while (ptr != IntPtr.Zero)
{
_loop_list loopListT = (_loop_list)Marshal.PtrToStructure(ptr, typeof(_loop_list));
int count;
errorCode = UF_MODL_ask_list_count(loopListT.edge_list,out count);
NXOpen.Tag[] edgeArray = new NXOpen.Tag[count];
for (int i = 0; i < count; i++)
{
UF_MODL_ask_list_item(loopListT.edge_list, i,out edgeArray[i]);
}
//UF_MODL_delete_list(out loopListT.edge_list);
loopList.Add(new LoopList{Type = loopListT.type,EdgeList = edgeArray});
ptr = loopListT.next;
}
UF_MODL_delete_loop_list(out loopT);
return loopList.ToArray();
}
[DllImport("libufun.dll", EntryPoint = "UF_MODL_ask_face_loops", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_ask_face_loops(NXOpen.Tag face, out IntPtr loopList);
[DllImport("libufun.dll", EntryPoint = "UF_MODL_ask_list_count", CallingConvention = CallingConvention.Cdecl,
CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_ask_list_count(IntPtr list, out int count);
[DllImport("libufun.dll", EntryPoint = "UF_MODL_ask_list_item", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_ask_list_item(IntPtr list, int index, out NXOpen.Tag @object);
[DllImport("libufun.dll", EntryPoint = "UF_MODL_delete_list", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_delete_list(out IntPtr list);
[DllImport("libufun.dll", EntryPoint = "UF_MODL_delete_loop_list", CallingConvention = CallingConvention.Cdecl,CharSet = CharSet.Ansi)]
internal static extern int UF_MODL_delete_loop_list(out IntPtr list);
internal struct _loop_list
{
public int type;
public IntPtr edge_list;
public IntPtr next;
}
public struct LoopList
{
/// <summary>
/// Peripheral=1, Hole=2, Other=3
/// </summary>
public int Type;
public NXOpen.Tag[] EdgeList;
}
}
虽然Nxopen已经封装好了面选择器
NXOpen.Face face = (NXOpen.Face)face_select0.SelectedObjects.First();
NXOpen.Edge[] edges = face.GetEdges();
但是学习怎么用C#调用C++/C的dll也是非常重要的,所以接下的学习的课题就是这个了。
近期七七八八的事情太多了,也没办法静下心来写个功能,只能学学一些新的技术(对我而言),每天多了结一点进步一点才能厚积薄发,关键是一天如果从早到晚都没有看过代码的话心里总发慌,有一种莫名的害怕。
网址:C#调用C/C++dll的方法(近期研究的课题) https://www.yuejiaxmz.com/news/view/554525
相关内容
用c语言实现旅行商问题的c史上最管用的C盘深度清理秘籍
C语言在生活中的应用 …
释放C盘空间的27招优化技巧
C#最全资料
前列腺高c方法要多久
27招优化C盘技巧
HDL一C测定的参考方法是
【python】使用C
用公式法化简F=(A+B)*(A+B+C)*(A’+C)*(B+C+D)为:AC