Home > Net >  Using c # call c DLL, there is a reading the value and the function of the outgoing, I think many ti
Using c # call c DLL, there is a reading the value and the function of the outgoing, I think many ti

Time:09-25

C + +

The static double a, [1056].
Extern "C" __declspec (dllexport) int con1 (double * buffer, int maxItem) {
Char acBuffer 30 + [1].
//Read the connection information from the INI file in current directory
DWORD dwRet=GetPrivateProfileString ((LPCWSTR) "Connection", (LPCWSTR) "Type", "TCP" LPCWSTR, LPWSTR acBuffer, 30, (LPCWSTR) "./ROD4plusViewer. Ini ");
The Connection * pConnection=NULL;
If (STRCMP (" SERIAL ", acBuffer)==0)
{
//Read serial port parameters and initialize a port instance for serial port 1
PCon SerialCom *=new SerialCom ();
GetPrivateProfileString ((LPCWSTR) "Serial", "ComPort" (LPCWSTR), (LPCWSTR) "COM1", (LPWSTR) acBuffer, 30, (LPCWSTR) "./ROD4plusViewer. Ini ");
PCon - & gt; SetComPort (acBuffer);
EBaudrate EBaudrate=(EBaudrate) GetPrivateProfileInt ((LPCWSTR) "Serial", (LPCWSTR) "Baudrate", 57600, (LPCWSTR) "./ROD4plusViewer. Ini ");
PCon - & gt; SetBaudrate (eBaudrate);
PConnection=pCon;

}
The else
{
//Read the TCP/IP parameters and initialize a port instance for stream socket usage.
TcpSocket * pCon=new TcpSocket ();
GetPrivateProfileString ((LPCWSTR) "TCP", "IP" (LPCWSTR), (LPCWSTR) "192.168.60.3 LPWSTR acBuffer, 30, (LPCWSTR)"./ROD4plusViewer. Ini ");
PCon - & gt; SetHostIp (acBuffer);
PCon - & gt; SetHostPort (GetPrivateProfileInt ((LPCWSTR) "TCP", (LPCWSTR) "Port", 9008, (LPCWSTR) "./ROD4plusViewer. Ini "));
PConnection=pCon;
}
//connect to sensor
PConnection - & gt; The connect ().
if(! PConnection - & gt; IsConnected ())
{
//the connection failed
The delete pConnection;
PConnection=NULL;
return -1;
}

//read values
HANDLE hRecvThread=NULL;
GetPrivateProfileString ((LPCWSTR) "Connection", (LPCWSTR) "Protocol", "BINARY" LPCWSTR, LPWSTR acBuffer, 30, (LPCWSTR) "./ROD4plusViewer. Ini ");
If (STRCMP (" ASCII_POLAR acBuffer)==0)
{
The return of 100;
S_eCoordSystem=COORD_POLAR;
S_pAsciiProtocol=new AsciiRemoteProtocol ();
S_pAsciiProtocol - & gt; SetConnection (pConnection);
//hRecvThread=CreateThread (NULL, 0, recvAsciiThreadProc, NULL, 0, NULL);
RecvAsciiThreadProc ();
The return of 100;
}
Else if (STRCMP (" ASCII_CARTESIAN acBuffer)==0)
{
S_eCoordSystem=COORD_CARTESIAN;
S_pAsciiProtocol=new AsciiRemoteProtocol ();
S_pAsciiProtocol - & gt; SetConnection (pConnection);
//hRecvThread=CreateThread (NULL, 0, recvAsciiThreadProc, NULL, 0, NULL);
RecvAsciiThreadProc ();
The return of 101;
}
The else
{

S_pBinaryProtocol=new ROD4BinaryProtocol ();
S_pBinaryProtocol - & gt; SetConnection (pConnection);
//hRecvThread=CreateThread (NULL, 0, recvBinaryThreadProc, NULL, 0, NULL);
RecvBinaryThreadProcTS ();
If (maxItem & lt; 1056)
return -1;
for(int i=0; i<1056; I++)
Buffer=[I] a [I];//a [I] in recvBinaryThreadProcTS was assignment ()
}
//the last close connection
PConnection - & gt; close();
The delete pConnection;
PConnection=NULL;
return 5;
}


C #
[DllImport (" testdll. DLL EntryPoint="con1," CallingConvention=CallingConvention. Cdecl)]
Public static extern int con1 (double [] buffer, int maxItem);
for (int j=0; J & lt; 10; J++)
{
Var buffer=new double [1056];
Var ret=test. Con1 (buffer, buffer Length);
Console. WriteLine (buffer. Length);
for (int i=0; i <1056; I++)
{
Console. WriteLine (buffer [I] + "" + I);

}

}
I am simple call this con1 function in c #, but each time the values are the same, should excuse me everybody how to modify

CodePudding user response:

You should put it into a c # DLLS are available, and then to call

CodePudding user response:

reference 1st floor tangyanzhi1111 response:
you should put it into a c # DLLS are available, and then call


The DLL has can use, I just make a list including the realization of the function, there is no question of a single read value, multiple calls to read value is always the same number

CodePudding user response:

Is any update of the parameter value, the problem has been solved!!!!!!

CodePudding user response:

The inside of the DLL value you can't update, equivalent to every time is to call, c # local try the value to exist
  •  Tags:  
  • C #
  • Related