How a control passes a custom struct

Source: Internet
Author: User
Tags bool uuid

First, development tools

I was going to use the. OCX control, and finally found, for custom struct, it seems to be powerless (who knows. If OCX can please contact me). The final adoption is ATL in vc++6.0. The following shows how to invoke a component function Senddata,receivedata with a custom structure. The parameter passing in the assembly is exactly the same as the following code, which is not repeated here. (This component is used in the distribution automation, to realize the feeder automation FA function, I design and develop myself).

Second, the source code here describes how to pass your own structure to the control. The source code for the calling component function is as follows:

int result;
VARIANT Lineval;
VARIANT Dotval;
SAFEARRAY FAR * pLSA = NULL;
Safearraybound dimension[1];
Dimension[0].llbound = 0;
Dimension[0].celements = max*10;
pLSA = SafeArrayCreate (vt_bstr,1,dimension);
Line FAR *plinedata=null;
:: Safearrayaccessdata (pLSA, (void hugep* far*) &plinedata);
for (i=0;i<max;i++)
{
Plinedata[i]. Stapoint_x=linedata[i]. stapoint_x;
Plinedata[i]. Stapoint_y=linedata[i]. stapoint_y;
Plinedata[i]. Endpoint_x=linedata[i]. endpoint_x;
Plinedata[i]. Endpoint_y=linedata[i]. endpoint_y;
Plinedata[i]. Endtype=linedata[i]. Endtype;
Plinedata[i].id=linedata[i].id;
Plinedata[i]. Linename=linedata[i]. Linename;
Plinedata[i]. Longth=linedata[i]. Longth;
Plinedata[i]. Power=linedata[i]. Power;
Plinedata[i]. Shcirflag=linedata[i]. Shcirflag;
}
:: Safearrayunaccessdata (PLSA);
LINEVAL.VT = Vt_array;
Lineval.parray = pLSA;
SAFEARRAY FAR * PDSA = NULL;
Dot FAR *pdotdata=null;
PDSA = SafeArrayCreate (VT_BSTR, 1, dimension);
:: Safearrayaccessdata (PDSA, (void hugep* far*) &pdotdata);
for (i=0;i<max;i++)
{
Pdotdata[i]. Cutflag=dotdata[i]. Cutflag;
Pdotdata[i]. Dotname=dotdata[i]. Dotname;
Pdotdata[i]. Dottype=dotdata[i]. Dottype;
Pdotdata[i]. Stapoint_x=dotdata[i]. stapoint_x;
Pdotdata[i]. Stapoint_y=dotdata[i]. stapoint_y;
Pdotdata[i]. Endpoint_x=dotdata[i]. endpoint_x;
Pdotdata[i]. Endpoint_y=dotdata[i]. endpoint_y;
Pdotdata[i]. Highcurrent=dotdata[i]. Highcurrent;
Pdotdata[i].id=dotdata[i].id;
Pdotdata[i]. Power=dotdata[i]. Power;
}
:: Safearrayunaccessdata (PDSA);
DOTVAL.VT = Vt_array;
Dotval.parray = PDSA;
QFA is a control,
SendData, Receivedata is a function in the control,
Lineval and Dotval are the structures they declare.
Result=qfa. SendData (lineval,dotval,3);
Long Linecount,dotcount;
The following data is received
SAFEARRAY FAR * Prelsa = NULL;
SAFEARRAY FAR * Predsa = NULL;
Prelsa = SafeArrayCreate (VT_BSTR, 1, dimension);
PREDSA = SafeArrayCreate (VT_BSTR, 1, dimension);
Line *pldata=null;
Dot *pddata=null;
Qfa. Receivedata (&lineval,&linecount,&dotval,&dotcount);
Prelsa = Lineval.parray;
PREDSA = Dotval.parray;
:: Safearrayaccessdata (PREDSA, (void hugep* far*) &pdotdata);
:: Safearrayunaccessdata (PREDSA);
for (int j=0;j<max;j++)
{
DOTDATA[J]. Highcurrent=-1;
}
for (i=0;i<dotcount;i++)
{
for (j=0;j<max;j++)
{
if (pdotdata[i].id==dotdata[j].id)
{
DOTDATA[J]. Power=pdotdata[i]. Power;
}
}
}
Line and DOT statements are as follows
struct line
{
Long id;//id number
BOOL power;//with electrical signs
BSTR linename;//Line Name
Long stapoint_x;//start X
Long stapoint_y;//start y
Long endpoint_x;//endpoint X
Long endpoint_y;//Endpoint Y
Short ENDTYPE;//1 load 2 power supply 0 Other
Long longth;
BOOL shcirflag;//Short Circuit mark
};
struct DOT
{
Long ID;
BOOL power;//Opening and closing sign
BSTR dotname;//Line Name
Long stapoint_x;//start X
Long stapoint_y;//start y
Long endpoint_x;//endpoint X
Long endpoint_y;//Endpoint Y
Short dottype;//operable sign 0 circuit breaker not remote Control 1 circuit breaker can remote Control 2 cutter Gate 3 line node 4 transformer
Short highcurrent;//over-flow sign-1 No overcurrent data >=0 with overcurrent data
BOOL cutflag;//Trip Sign
};
You need to declare the following in an ATL IDL file:
typedef
[
UUID (D124B04A-C5F9-4A16-9671-1E67B75DB1A1),
helpstring ("Network Node Struct")
]
struct line
{
Long id;//id number
BOOL power;//with electrical signs
BSTR linename;//Line Name
Long stapoint_x;//start X
Long stapoint_y;//start y
Long endpoint_x;//endpoint X
Long endpoint_y;//Endpoint Y
Short ENDTYPE;//1 load 2 power supply 0 Other
Long longth;
BOOL shcirflag;//Short Circuit mark
}line;
typedef
[
UUID (D124B04A-C5F9-4A16-9671-1E67B75DB1A2),
helpstring ("Network Node Struct")
]
struct DOT
{
Long ID;
BOOL power;//Opening and closing sign
BSTR dotname;//Line Name
Long stapoint_x;//start X
Long stapoint_y;//start y
Long endpoint_x;//endpoint X
Long endpoint_y;//Endpoint Y
Short dottype;//operable sign 0 circuit breaker not remote Control 1 circuit breaker can remote Control 2 cutter Gate 3 line node 4 transformer
Short highcurrent;//over current flag
BOOL cutflag;//Trip Sign
}dot;

Then you can use both of these structures.

Third, concluding remarks

Need more code, please see the example source. But the component QFA2004 source code cannot provide, please forgive. At the same time hope that there are better ways for the masters to provide a better way to pass the custom struct. The source code uses the method: first should register the QFA2004 component. regsvr32 c:\qfa2004.dll (c:\ directory changes according to Qfa2004.dll directory), then open with vc++6.0, compile.

This article supporting source code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.