Home > Net >  Help bosses!!!!!! C #, C, UG/NX second development
Help bosses!!!!!! C #, C, UG/NX second development

Time:03-22

I am now practicing UG secondary development in c #, think through the c # call GRIP, so need to call this function UF_call_grip in c + +,
At the beginning of the first to use the following key code:
 
using NXOpen;
Using NXOpen. UF;
using System;
using System.Collections.Generic;//c # List<> The namespace
Using System. The Runtime. InteropServices;//DllImport namespace, define the structure also must add
Public class OpenAPI
{
[DllImport (" libufun. DLL, CallingConvention=CallingConvention Cdecl, CharSet=CharSet. Ansi, EntryPoint="UF_call_grip")]
Internal static extern int _CallGrip (string grip_executable, int argument_count, ref Args gruf_arg_list);
}


 
public static int Main (string [] args)
{
Int retValue=https://bbs.csdn.net/topics/0;
Try
{
TheProgram=new Program ();

//TODO: Add your application code here

NXOpen. Utilities. JAM. StartUFCall ();
String path="D: \ \ test. TXT".
IntPtr init=Marshal. StringToHGlobalAnsi (path);
Int grip_arg_count=1;
The Args [] grip_arg_list=new Args [1].
Grip_arg_list [0]. Address=init;
Grip_arg_list [0]. Length=0;
Grip_arg_list [0]. Type=UFConstants. UF_TYPE_CHAR;
OpenAPI. _CallGrip (" E: \ \ VSandUGDEMO \ \ xianshi GRS ", grip_arg_count, ref grip_arg_list ;
NXOpen. Session. UndoMarkId markId1;
NXOpen. Utilities. JAM. EndUFCall ();

TheProgram. The Dispose ();
}
The catch (NXOpen. NXException ex)
{
//- Enter your exception handling code here -- -- -- -- --

}
return retValue;
}
Hint: from "ref NXOpen. UF. The Args []" into "ref NXOpen. UF. The Args" this one problem, (the color)
Then I put the definition
 Args [] grip_arg_list=new Args [1]. 
Grip_arg_list [0]. Address=init;
Grip_arg_list [0]. Length=0;
Grip_arg_list [0]. Type=UFConstants. UF_TYPE_CHAR;

To:
 Args grip_arg_list; 
Grip_arg_list. Address=init;
Grip_arg_list. Length=0;
Grip_arg_list. Type=UFConstants. UF_TYPE_CHAR;

Generated. DLL file is run on UG, the below error message:

This is what problem,,, there are two still cannot solve the problem: (1) the type of the variable on the transition from c + + to c # is the problem? Similar Char * into c + + c # string, then how UF_args_p_t in c + + is converted into the corresponding type in c #? (2) thinking directly in c + + using UF_call_grip function, through the generated. DLL to the c # reference, but the reference is not, how to do this?
Kindly, help is going to go crazy child,,,,

Stick a UF_call_grip function
 extern UFUNEXPORT int UF_call_grip (
Char * grip_executable,/* & lt; I>
Name of GRIP program to execute (file Name
Or full path name).
*/
Int count,/* & lt; I>
The Count of the arguments to pass to GRIP the executable
*/
UF_args_p_t UFARGS/* & lt; I, len: count>
An array of structures where each element in the
The array is a structure that contains an
The arguments the type, size, and the address. Note that
If an argument is type UF_TYPE_CHAR, the array
Must be initialized prior to the UF_call_grip
Call.
*/
);

 struct UF_args_s 
{int type./* one of the types, UF_TYPE_DOUBLE,
UF_TYPE_DOUBLE_ARRAY UF_TYPE_TAG_T,
UF_TYPE_TAG_T_ARRAY, UF_TYPE_CHAR or
UF_TYPE_CHAR_ARRAY. */
Int length;/* the number of elements in an array, the for
Types UF_TYPE_DOUBLE_ARRAY,
UF_TYPE_TAG_T_ARRAY or UF_TYPE_CHAR_ARRAY. */
Void * address;/* A pointer to an array of the given
The type and length. Note that the for an array
Of UF_TYPE_CHAR, if the argument list
Is built by the Open the program, it must
Initialize this array been it is input or
The output. An output array can be initialized
By setting the first byte to '\ 0'. */
};

Typedef struct UF_args_s UF_args_t, * UF_args_p_t;
  •  Tags:  
  • C#