⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 example1.cpp

📁 新买的书
💻 CPP
字号:
//####################################################################
// S2L2.cpp - (Section 2, Lesson 2) RECEIVING AN INTEGER FROM THE
//                                  TARGET
//            This is the RTDX Host Client for Section 2, Lesson 2
//
// This example receives integer value 5 from the target
//####################################################################
 
#import "c:\ti\cc\bin\rtdxint.dll"
#include <iostream.h>
 
#define Success             0               // Method call is valid
#define Failure             0x80004005L     // Method call failed

// No data was available. However, more data may be available in the future.
#define ENoDataAvailable    0x8003001EL     

// No data was available. The end of the log file has been reached.
#define EEndOfLogFile       0x80030002L     

#define VALUE_TO_SEND       5

using namespace RTDXINTLib;
 
int main()
{
        IRtdxExpPtr rtdx;       // holds pointer to IRtdxExp interface
        long data;              // holds data received from target application
        long status;            // holds status of RTDX COM API calls
        HRESULT hr;             // holds status of generic COM API calls
 
        // initialize COM
        ::CoInitialize( NULL );
 
        // instantiate the RTDX COM Object
        hr = rtdx.CreateInstance( L"RTDX" );
 
        cout.setf( ios::showbase );
 
        if ( FAILED(hr) ) {
                cerr << hex << hr << " - Error: Instantiation failed! \n";
                return -1;
        }
 
        // open a channel (ochan) for reading data
        status = rtdx->Open( "ochan", "R" );
 
        if ( status != Success ) {
                cerr << hex << status \
                     << " -  Error: Opening of channel \"ochan\" failed! \n";
                return -1;
        }
 
        // loop until we have read all of our messages
        do {
                // read a message
                status = rtdx->ReadI4( &data );
 
                // test status returned from ReadI4
                switch ( status ) {
                        case Success:
                                // display data
                                cout << data << "\n";
                                break;
                        case Failure:
                                cerr << hex << status \
                                     << " - Error: ReadI4 returned failure! \n";
                                return -1;
                        case ENoDataAvailable:
                                cout << "\n\nNo Data is currently available!\n";
                                cout << "\n\nWould you like to continue reading [y or n]?\n";
                                char option;
                                cin >> option;
                                if ( (option == 'y') || (option == 'Y') )
                                        break;
                                else
									return -1;
                        case EEndOfLogFile:
                                cout << "\n\nData Processing Complete!\n";
                                break;
                        default:
                                cerr << hex << status \
                                     << " - Error: Unknown return code! \n";
                                return -1;
                }
        } while ( status != EEndOfLogFile );
 
        // close the channel
        status = rtdx->Close();
 
        // release the RTDX COM Object
        rtdx.Release();
 
        // unitialize COM
        ::CoUninitialize();
 
        return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -