Technical documentation Heredes

01. API. Library initialization

function options
InitIONLibrary Syntax:
void InitIONLibrary (void);
This function has no parameters. The main purpose of this function is to initialize the use of heredes.dll in your application.
This function must be called once by your application before using the Heredes API.

02. API. Get a handle to a new connection

function options
CreateIONHandle Syntax:
HANDLE CreateIONHandle (void);
This function has no parameters. Creates an environment for a new outgoing (client) connection. Returns a handle to the connection.
Example:
HANDLE hDcon = CreateIONHandle();

03. API. Close connection handle

function options
void CloseIONHandle Syntax:
CloseIONHandle(HANDLE hConn); as a parameter takes the connection descriptor obtained by the function CreateIONHandle. The function closes the descriptors created by the function CreateIONHandle and frees up the memory region occupied by the connection environment.
Example:
CloseIONHandle(hDcon);

04. API. New User Registration

function options
void RegIONId Syntax:
void RegIONId(LPDWORD LocValid, LPDWORD LocId);
LocValid - a pointer to a variable that will receive a confirmation code for the owner of the identifier. The value of the variable is ignored if the LocId value is equal to zero. LocId - a pointer to a variable that will receive a personal identifier. The variable must be equal to zero if a new identifier is required to be registered. This function works synchronously. Do not call this function unnecessarily every time you start the program, but instead save the user ID and verification code for future use. The function does not return values, but if successful, the LocValid and LocId variables contain nonzero values.

About user IDs

The connection between users is established by means of personal unique identifiers.

User ID is a number from 0x1 to 0xFFFFFFF0 (32 bits).

When a user asks the STUN server for the parameters of an outgoing connection, or notifies the STUN server that it is ready to accept an incoming connection, it sends a personal identifier and a key confirming registration.

The ID confirmation key is also a number from 0x1 to 0xFFFFFFF0 (32 bits).

The STUN server checks whether the personal identifier matches the confirmation key.

Thus, two levels of security are carried out: the STUN check by the user's server for validity (not considered secure) and the use by users of secret encryption keys that may not be transmitted over the network, depending on the implementation by your software. In addition, when transferring personal data, you can use your own encryption system, the algorithm of which can only be known to you.

To register a new user and obtain a personal ID and verification code, use the RegIONId function.

About connection states

To determine the current state of the connection, you can use the Callback function, which receives status notifications - status status

status description
0 connection to STUN server is not established
1 connection to STUN server is active
2 data for direct connection received
3 trying to establish a direct connection and verify the private key
4 secret encryption key error
5 secret key negotiated
6 connection established successfully, direct data exchange possible

05. API. Get connection status

function options
int IONGetStatus Syntax:
int IONGetStatus(HANDLE hConn); hConn - connection handle obtained by the CreateIONHandle or IONWaitConnection function Returns the connection status number. Learn more about connection states.

06. API. Establish an outgoing connection

function options
BOOL IONConnectToId Syntax:
void IONConnectToId(HANDLE hConn,
LPDWORD pId,
LPDWORD LocValid,
LPDWORD LocId,
LPVOID SecStr,
CBSELID CBSelUser,
CBSTATUS CBStatus,
CBUDATA CBUserData);

hConn - connection handle obtained by the CreateIONHandle function

pId - Reserved for future use.

LocValid - a pointer to the confirmation code of the owner of the identifier. The variable must be zero.

LocId - a pointer to a variable containing a personal identifier. The variable must be zero.

pSecStr - address of an 8-byte array containing the encryption key

CBSelUser - pointer to the interface event handler function. Can be NULL if access to the local list of identifiers is not required.

CBStatus - a pointer to a function that handles the connection progress (notifications about the current status).

CBUserData - a pointer to a handler function for incoming user data sent by the IONSendUserData function. May be NULL if no user input is expected.

The function returns TRUE on success or FALSE if the connection failed.

07. API. User data processor

function options
CBUserData Syntax:

CBUDATA CBUserData(HANDLE hConn,
LPDWORD pData,
int datSize);

hConn - connection handle obtained by the CreateIONHandle function

pData - pointer to an array of incoming data

datSize - length of user data in bytes

the function returns TRUE on success or FALSE if the connection failed

08. API. Reset outgoing connection

function options
void IONDisconnect Syntax: void IONDisconnect(HANDLE hConn);

hConn - connection handle obtained by CreateIONHandle or WaitIONConnection

Terminates the currently active connection or stops trying to establish a connection.

09. API. Waiting for an incoming connection

function options
IONWaitConnection Syntax: HANDLE IONWaitConnection(LPDWORD LocValid,
LPDWORD LocId, CBUDATA CBUserData);

LocValid - a pointer to a variable that will receive a confirmation code for the owner of the identifier. Variable value is ignored if LocId is equal to zero

LocId - a pointer to a variable that will receive a personal identifier. The variable must be equal to zero if you want to register a new identifier

CBUDATA - pointer to the CBUserData handler procedure for incoming user data sent using SendUserData The

function starts a thread waiting for incoming connections and returns the connection ID. To free memory and terminate the wait thread, use IONTerminate

10. API. Stop waiting for incoming connections

function options
void IONTerminate Syntax: void IONTerminate(HANDLE hConn);

hConn - connection descriptor obtained by the IONWaitConnection function

Terminates the currently active connection and ends the thread waiting for incoming connections. You should not use this function with the parameter obtained by CreateIONHandle.

The difference from IONDisconnect is that if IONTerminate is called, the waiting thread is terminated, so reconnecting to the thread becomes impossible.

11. API. Passing user data of undefined type

function options
SendUserData Syntax: int SendUserData(HANDLE hConn,
PVOID UserDataAddr
DWORD LongData);

hConn - connection handle obtained by CreateIONHandle or IONWaitConnection

hUserDataAddr - pointer to a string with arbitrary user data

LongData - user data length

The function returns the number of bytes queued for sending and does not guarantee their delivery. Your application should arrange for confirmation of receipt of data, if necessary.

It should be borne in mind that the server application will send user data in blocks from 30 to 1006 bytes and your application must independently split the sent data into parts and mark in what order. They should be collected. Also, your application must ensure the integrity of the received data by requesting re-sending of the lost block if guaranteed delivery is required.

Your application can use additional arbitrary encryption algorithms before calling SendUserData to enhance security.

Please note that SendUserData can only be used to transfer data with an active connection (status 6). Also, sending is done in blocks of 992 bytes. In case of sending a larger block, only the first 992 bytes will be sent. The function returns the number of bytes actually transferred.

12. API. File transfer

function options
IONSendFileToId Syntax: int IONSendFileToId(LPDWORD pValid, LPDWORD pId, CBSELID CBSelUser, LPDWORD pHightDword);

pValid - a pointer to a DWORD variable containing the confirmation code of the owner of the identifier.

pId - a pointer to a DWORD variable containing an identifier.

CBSelUse - pointer to CALLBACK procedure for processing WM_COMMAND. You can use this feature to provide the user with a choice of ID, create interfaces, and more. Can be NULL if the user enters the recipient Id only manually.

pHightDword - pointer to the upper 4 bytes of the size of the transferred bytes.

the function returns the least significant 4 bytes of the size of the transferred bytes.

if the most significant bit in the value at the pHightDword address is set to 1 (the value is more than 0x80000000), then an error occurred during transmission data and the file is not fully transferred. It is up to your application to decide how to handle such errors.

Thus, the theoretical upper limit on the size of the transferred file is respectively 8 388 608 TB, however, it should be borne in mind that the transfer runs on top of UDP and is susceptible to interference, so unpredictable transmission disruptions are possible, not all of which is able to handle this function.

13. API. Initializing audio

function options
IONSetAudioParam Syntax: void IONSetAudioParam(HANDLE hConn, bool FPlay, LPCTSTR pFileOut, LPCTSTR pFileIn, CBAIN CBInAud);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function.

FPlay - playback flag. Set to TRUE if you don't want to play the incoming audio stream. Concurrently specifying FALSE in the FPlay parameters and NULL in pFileSpeak will result in a refusal to accept the incoming audio stream.

pFileMic - full path and file name for parallel recording of outgoing audio. For correct playback of the recorded file by other applications such as Windows Media Player or others, the file extension * .wav should be specified. This parameter must be NULL if the parallel file write mode is not required.

pFileSpeak - full path and file name for parallel recording of incoming audio. For correct playback of the recorded file by other applications such as Windows Media Player or others, the file extension * .wav should be specified. This parameter must be NULL if the parallel file write mode is not required.

CBInAud - the address of the callback function to react to the incoming audio stream. may be NULL.

This function creates an environment and sets the processing parameters for the incoming and outgoing audio stream. You can call it once and use the standard settings for audio connections with any Id or set individually for each incoming or outgoing connection

You are not required to call this function if your application uses SendUserData to send an audio stream, but this is required before using the Heredes API audio functions.

14. API. Start streaming audio

function options
IONStartAudioStream Syntax: bool IONStartAudioStream(Handle hConn, int nSamplesPerSec);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

nSamplesPerSec - Sample rate (Hertz). Allowed values ​​are 8000, 11025, 22050, 44100. If this value is NULL, the default frequency is 11025 Hz.

This function should be called after the connection is established (connection status 6). The function returns a value immediately after creating an audio channel or in case of an error.

a notification is sent to the receiving party about the need to open access to the device's speakers for playback, file to save audio stream or parallel playback and write data to a file.

If successful, the caller opens access to the microphone in mono mode (using one audio channel). In case of impossibility access audio playback devices on the receiving end, access to the microphone also does not open and the function returns zero.

the result of this function is nonzero on success. The transfer of the audio stream begins immediately after the parties agree on the transfer.

The audio stream is transmitted in PCM mono format with the frequency specified in the nSamplesPerSec parameter and, with appropriate parameters, is saved in the wave format

Your application must call IONSetAudioParam to set parameters before using this function.

Your application must call IONStopAudioStream to correctly complete the audio stream.

15. API. Interrupt audio stream transmission

function options
IONStopAudioStream Syntax: void IONStopAudioStream(Handle hConn);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function.

The function notifies the remote ID of the completion of the audio stream transfer, which causes the corresponding audio devices to be released and all open ones closed. descriptors to process.

Only the transmitting party must call this function. At the same time, the call of this function does not affect the incoming audio stream and its processing.

16. API. Setting video stream parameters

function options
SetINVISTParam Syntax: void SetINVISTParam (Handle hConn,
HDC hDC,
int widthX,
int heightY,
int rightX,
int rightY, CBSTATUS INVStat );

hConn - the handle received by the CreateIONHandle or IONWaitConnection function.

hDC - virtual or physical hDC of the image source on the service side or DC for rendering on the client side.

rightX - X coordinate of the upper left corner of the source rectangle (relative to the window).

topY - Y coordinate of the upper left corner of the source rectangle (relative to the window).

widthX - width of the source rectangle (relative to the window).

heightY - the height of the source rectangle (relative to the window).

INVStat - reserved.

The function sets the initial parameters of the video stream. This function should be called on the server side before a request for video streaming comes. on the client side, calling this function is optional.

17. API. Creating an interactive real-time player

function options
CreateINPRT Syntax: void CreateINPRT(Handle hConn, int posX, int POSY, int widthX, int heightY, DWORD styleWin, HWND hParent, LPDWORD lpWin, int LCount, CBSTATUS WMClose);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function.

posX - The initial horizontal position of the window. For an overlapped or pop-up window, the x parameter is the initial x-coordinate of the window's upper-left corner, in screen coordinates. For a child window, x is the x-coordinate of the upper-left corner of the window relative to the upper-left corner of the parent window's client area. If x is set to CW_USEDEFAULT, the system selects the default position for the window's upper-left corner and ignores the y parameter. CW_USEDEFAULT is valid only for overlapped windows; if it is specified for a pop-up or child window, the x and y parameters are set to zero.

posY - The initial vertical position of the window. For an overlapped or pop-up window, the y parameter is the initial y-coordinate of the window's upper-left corner, in screen coordinates. For a child window, y is the initial y-coordinate of the upper-left corner of the child window relative to the upper-left corner of the parent window's client area. For a list box y is the initial y-coordinate of the upper-left corner of the list box's client area relative to the upper-left corner of the parent window's client area. If an overlapped window is created with the WS_VISIBLE style bit set and the x parameter is set to CW_USEDEFAULT, then the y parameter determines how the window is shown. If the y parameter is CW_USEDEFAULT, then the window manager calls ShowWindow with the SW_SHOW flag after the window has been created. If the y parameter is some other value, then the window manager calls ShowWindow with that value as the nCmdShow parameter.

widthX - The width, in device units, of the window. For overlapped windows, nWidth is the window's width, in screen coordinates, or CW_USEDEFAULT. If nWidth is CW_USEDEFAULT, the system selects a default width and height for the window; the default width extends from the initial x-coordinates to the right edge of the screen; the default height extends from the initial y-coordinate to the top of the icon area. CW_USEDEFAULT is valid only for overlapped windows; if CW_USEDEFAULT is specified for a pop-up or child window, the nWidth and nHeight parameter are set to zero.

heightY - The height, in device units, of the window. For overlapped windows, nHeight is the window's height, in screen coordinates. If the nWidth parameter is set to CW_USEDEFAULT, the system ignores nHeight.

styleWin - window style. learn more about styles

hParent - A handle to the parent or owner window of the window being created. To create a child window or an owned window, supply a valid window handle. This parameter is optional for pop-up windows. To create a message-only window, supply HWND_MESSAGE or a handle to an existing message-only window.

lpWin - the address of the variable that will receive the Handle value of the player window.

LCount - conditional division into horizontal blocks. can take values ​​from 1 to 15.

WMClose -pointer to a function that will receive a duplicate WM_CLOSE message for the player window.

The function must be called on the client side. Coordinates the parameters of the video stream transmission with the server with which the connection must be previously established. creates an interactive player window and displays the live video stream.

18. API. Initializing the environment for a frame-by-frame video stream

function options
StartRemoteINVIST Syntax: void StartRemoteINVIST (Handle hConn,
HDC hDC,
int widthX,
int heightY,
int LCount);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function.

hDC - virtual or physical DC for client-side rendering.

rightX - X coordinate of the upper left corner of the source rectangle (relative to the window).

topY - Y coordinate of the upper left corner of the source rectangle (relative to the window).

widthX - width of the source rectangle (relative to the window).

heightY - the height of the source rectangle (relative to the window).

LCount - conditional division into horizontal blocks. can take values ​​from 1 to 15.

The function prepares the server-side and client-side environment for broadcasting a frame-by-frame stream from the server to the client. The function is called by the client.

19. API. Obtaining the address of a copy of video memory

function options
GetBMPAddr Syntax: LPDWORD GetBMPAddr (Handle hConn);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

returns a pointer to an array of bitmap data.

20. API. Frame rendering

function options
GetRemoteINVISTService Syntax: void GetRemoteINVISTService (Handle hConn);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function.

The function receives the next frame from the server and renders it to the DC specified when calling StartRemoteINVIST.

21. API. Freeing memory occupied by a video stream

function options
StopRemoteINVIST Syntax: void StopRemoteINVIST(Handle hConn);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

stops the video stream and frees the memory used for the video stream on the server and client sides

22. API. Vertical mouse scrolling

function options
IONMouseVScroll Syntax: void IONMouseVScroll(Handle hConn, DWORD UpDown);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

UpDown if -1 scrolls up, otherwise - down

simulate vertical scrolling with the mouse wheel

23. API. Press the left mouse button

function options
IONLMouseDown Syntax: void IONLMouseDown(Handle hConn, DWORD ScrX, DWORD ScrY );

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

ScrX - absolute relative coordinate of the remote screen X

ScrX - absolute relative coordinate of the remote screen Y

Simulate left mouse button press.

24. API. Press the right mouse button

function options
IONRMouseDown Syntax: void IONRMouseDown(Handle hConn, DWORD ScrX, DWORD ScrY );

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

ScrX - absolute relative coordinate of the remote screen X

ScrX - absolute relative coordinate of the remote screen Y

Simulate right mouse button press.

25. API. Releasing the left mouse button

function options
IONLMouseUp Syntax: void IONLMouseUp(Handle hConn, DWORD ScrX, DWORD ScrY );

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

ScrX - absolute relative coordinate of the remote screen X

ScrX - absolute relative coordinate of the remote screen Y

simulate left mouse button click

26. API. Releasing the right mouse button

function options
IONRMouseUp Syntax: void IONRMouseUp(Handle hConn, DWORD ScrX, DWORD ScrY );

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

ScrX - absolute relative coordinate of the remote screen X

ScrX - absolute relative coordinate of the remote screen Y

simulate right mouse button click

27. API. Move the mouse pointer

function options
IONMouseMove Syntax: void IONMouseMove(Handle hConn, DWORD ScrX, DWORD ScrY , int StepMove);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

ScrX - absolute relative coordinate of the remote screen X

ScrX - absolute relative coordinate of the remote screen Y

StepMove - Reserved

simulate moving the mouse pointer to a given position

28. API. Pressing a keyboard button

function options
IONKeyDown Syntax: void IONKeyDown(Handle hConn, DWORD VKey);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

VKey virtual key-code the button pressed

simulate a keyboard button press

29. API. Releasing the keyboard button

function options
IONKeyUp Syntax: void IONKeyUp(Handle hConn, DWORD VKey);

hConn - the handle received by the CreateIONHandle or IONWaitConnection function

VKey virtual key-code the button pressed

simulate keyboard button release

30. API. Launching a console application with redirected I / O

function options
StartHiddenConsoleProcess Syntax:

void StartHiddenConsoleProcess(LPVOID pCMDLine, PHANDLE pOutPipe, PHANDLE pInPipe, PHANDLE pCOutPipe, PHANDLE pCInPipe);

pCMDLine - pointer to ASCIIZ (null-terminated) string with the name of the console application being launched

pOutPipe pointer to a variable that will receive a pipe handle for output

pInPipe pointer to a variable that will receive a pipe handle for input

pСOutPipe a pointer to a variable that will receive a pipe handle for output on the console side

pСInPipe a pointer to a variable that will receive a pipe handle for input on the console side

31. API. Sending a command to the console

function options
SendCommandLine Syntax:

void SendCommandLine(HANDLE hOutpipe, LPVOID pCOMCline);

hOutpipe - a pipe handle for output returned by the StartHiddenConsoleProcess function

pCOMCline Pointer to a command line ending in three characters 0x0D, 0x0A, 0x00

32. API. Save a copy of the remote DC to BMP

function options
SaveINVISTtoBPM Syntax:

int SaveINVISTtoBPM(HANDLE hConn, LPVOID pFName);

hConn - the handle received by the CreateIONHandle function

pFName ASCIIZ string containing bmp file name

Example 1. File exchange over NAT

// almost unlimited file exchange between clients over NAT
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\WORK\\P2P\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\WORK\P2P\HEREDES\heredes.h>

int main(void)
{
	InitIONLibrary();	// initialization of HEREDES libraries and interfaces
	DWORD Valid = 0;
	DWORD Id = 0;
	DWORD HightDword = 0;

	RegIONId(&Valid, &Id);	// register a new user
	// start an asynchronous server to listen for incoming connections
	HANDLE hConn = IONWaitConnection(&Valid, &Id, NULL);

	// launch synchronous interface for file transfer
	DWORD lowDword = IONSendFileToId(&Valid, &Id, NULL, &HightDword);

	IONTerminate(hConn);   // interrupt waiting for incoming connections
	CloseIONHandle(hConn);
	return 0;
}
Download the compiled example 1

Example 2. Simple UDP server and UDP client over NAT


      //UDP server that listens to the network for a minute and waits for incoming connections
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>

int main(void)
{
	InitIONLibrary();	//initialization of HEREDES libraries and interfaces
	DWORD Valid = 0;
	DWORD Id = 0;
	DWORD HightDword = 0;

	RegIONId(&Valid, &Id);	//New User Registration

	//starting an asynchronous server to listen for incoming connections
	HANDLE hConn = IONWaitConnection(&Valid, &Id, NULL);
	HANDLE hEv=CreateEventA(NULL,1,NULL,NULL);
	
	WaitForSingleObject(hEv,60000);
	CloseHandle(hEv);

	IONTerminate(hConn); //interrupt waiting for incoming connections
	CloseIONHandlw(hConn); //interrupt waiting for incoming connections
	
	return 0;
}

//the simplest UDP client that does nothing
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>

int main(void)
{
	InitIONLibrary();		//initialization of HEREDES libraries and interfaces
	CHAR SecKey[8];		//8-byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	HANDLE hConn;
	RegIONId(&Valid, &Id);	//New User Registration
	
	
	hConn=CreateIONHandle();
		if (IONConnectToId(hConn, NULL, &Valid, &Id, &SecKey, NULL, NULL, NULL)==TRUE){
				MessageBoxA(NULL,"connect installed","connection state", 48);
				HANDLE hEv=CreateEventA(NULL,1,NULL,NULL);
				WaitForSingleObject(hEv,60000);
				CloseHandle(hEv);

		}else{
				MessageBoxA(NULL,"connection error","connection status", 48);
		};

	IONDisconnect(hConn); //interrupt waiting for incoming connections
	CloseIONHandle(hConn); //interrupt waiting for incoming connections
	return 0;
}

Example 3. Multifunctional device or client and server rolled into one

//client-server over NAT
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>


int main(void)
{
	InitIONLibrary();			//initialization of HEREDES libraries and interfaces

	CHAR SecKey[8];			//8 byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	RegIONId(&Valid, &Id);		//New User Registration


	HANDLE hCON_IN=IONWaitConnection(&Valid, &Id, NULL);
	HANDLE hCON_OUT=CreateIONHandle();


	if (IONConnectToId(hCON_OUT, NULL, &Valid, &Id, &SecKey, NULL, NULL, NULL==TRUE)){

		



		}else{
		MessageBoxA(NULL,"connection error","connection status", 48);
		};

		IONTerminate(hCON_IN);
		IONDisconnect(hCON_OUT);
		CloseIONHandle(hCON_IN);
		CloseIONHandle(hCON_OUT);
	FreeConsole();
	return 0;
}
      

Example 4. Simple console messenger over NAT

//write over NAT
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>

HANDLE hOutput;
CBUDATA __stdcall UserDataProc(HANDLE hConn, LPVOID pAddrUserData, int datSize)
{
	DWORD inSize;
	WriteConsoleA(hOutput,pAddrUserData, datSize, &inSize, NULL);
	return 0;
}

int main(void)
{
	InitIONLibrary();				//initialization of HEREDES libraries and interfaces

	CHAR buffer[0x3E0];			//maximum user data block size 0x3E0
	DWORD bSize=0;

	CHAR SecKey[8];			//8 byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	RegIONId(&Valid, &Id);		//New User Registration

	AllocConsole();
	HANDLE hInput=GetStdHandle(-10);
	hOutput=GetStdHandle(-11);


	HANDLE hCON_IN=IONWaitConnection(&Valid, &Id, (CBUDATA) &UserDataProc);
	HANDLE hCON_OUT=CreateIONHandle();


	if (IONConnectToId(hCON_OUT, NULL, &Valid, &Id, &SecKey, \
			NULL, NULL, (CBUDATA) &UserDataProc)==TRUE){


			while (bSize!=-1){
				ReadConsoleA(hInput,&buffer,0x3E0,&bSize,NULL);
				if (IONGetStatus(hCON_OUT)==6) {SendUserData(hCON_OUT,&buffer,bSize);};
				if (IONGetStatus(hCON_IN)==6) {SendUserData(hCON_IN,&buffer,bSize);};
						}
				
		}else{
				MessageBoxA(NULL,"connection error","connection status", 48);
		};

		IONTerminate(hCON_IN);
		IONDisconnect(hCON_OUT);
		CloseIONHandle(hCON_IN);
		CloseIONHandle(hCON_OUT);
	FreeConsole();
	return 0;
}
      
Download the compiled example 4

Example 5. Simple call over NAT
//call over NAT
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>


int main(void)
{
	InitIONLibrary();			//initialization of HEREDES libraries and interfaces

	CHAR SecKey[8];			//8 byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	RegIONId(&Valid, &Id);		//New User Registration


	HANDLE hCON_IN=IONWaitConnection(&Valid, &Id, NULL);
	HANDLE hCON_OUT=CreateIONHandle();

	
	IONSetAudioParam(hCON_OUT,3,"aud_in.wav","aud_sp.wav",NULL);
	IONSetAudioParam(hCON_IN,3,"aud_in.wav","aud_sp.wav",NULL);


		if (IONConnectToId(hCON_OUT, NULL, &Valid, &Id, &SecKey, NULL, NULL, NULL)==TRUE){

			IONStartAudioStream(hCON_OUT,11025);
			HANDLE hEv=CreateEventA(NULL,1,NULL,NULL);
			WaitForSingleObject(hEv,60000);
			CloseHandle(hEv);

			
		}else{
				MessageBoxA(NULL,"connection error","connection status", 48);
		};
		IONStopAudioStream(hCON_IN);
		IONStopAudioStream(hCON_OUT);
		IONTerminate(hCON_IN);
		IONDisconnect(hCON_OUT);
		CloseIONHandle(hCON_IN);
		CloseIONHandle(hCON_OUT);
	return 0;
}
      
Download the compiled example 5

Example 6. From conversations to administration or CMD over NAT

//CMD over NAT
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>

CHAR buffer[0x3E0];			//maximum user data block size 0x3E0
HANDLE hOutput;
HANDLE outpipe;
HANDLE inpipe;
HANDLE hEv;
HANDLE hCON_IN;
HANDLE hCON_OUT;

CBUDATA __stdcall UserDataProc(HANDLE hConn, LPVOID pAddrUserData, int datSize)
{
	
	DWORD cRcv=1;
	if (IONGetStatus(hCON_IN)==6){
		SendCommandLine(outpipe,pAddrUserData);
		WaitForSingleObject(hEv,2000);
		
			while(cRcv!=0){
				PeekNamedPipe(inpipe,NULL,NULL,NULL,&cRcv,NULL);
				if (cRcv!=0){
					ReadFile(inpipe,&buffer,cRcv,&cRcv,NULL);
					}
				SendUserData(hCON_IN,&buffer,cRcv);
				}
	};

	if (IONGetStatus(hCON_OUT)==6){
				WriteConsoleA(hOutput,pAddrUserData,datSize,&cRcv,NULL);
			
	};



	DWORD inSize;
	WriteConsoleA(hOutput,pAddrUserData, datSize, &inSize, NULL);
	return 0;
}

int main(void)
{
	HANDLE hInCons;
	HANDLE hOutCons;
	
	hEv=CreateEventA(NULL,1,NULL,NULL);
	StartHiddenConsoleProcess("cmd.exe",&outpipe, &inpipe, &hOutCons, &hInCons);

	InitIONLibrary();			//initialization of HEREDES libraries and interfaces

	DWORD bSize=0;

	CHAR SecKey[8];			//8 byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	RegIONId(&Valid, &Id);		//New User Registration



	hCON_IN=IONWaitConnection(&Valid, &Id, (CBUDATA) &UserDataProc);
	hCON_OUT=CreateIONHandle();


	if (IONConnectToId(hCON_OUT, NULL, &Valid, &Id, &SecKey, \
			NULL, NULL, (CBUDATA) &UserDataProc)==TRUE){

			
			AllocConsole();
			HANDLE hInput=GetStdHandle(-10);
			hOutput=GetStdHandle(-11);
			WriteConsoleA(hOutput,"REMOTE CMD >",12,&bSize,NULL);


			while (bSize!=-1){
				ReadConsoleA(hInput,&buffer,0x3E0,&bSize,NULL);
				SendUserData(hCON_OUT,&buffer,bSize);
						}
				
			FreeConsole();

		}else{
				MessageBoxA(NULL,"connection error","connection status", 48);
		};

		IONTerminate(hCON_IN);
		IONDisconnect(hCON_OUT);
		CloseIONHandle(hCON_IN);
		CloseIONHandle(hCON_OUT);
	return 0;
}
      
Download the compiled example 6

Example 7. Let's take a photo. Taking a photo of a part of the remote desktop screen

//headless screen
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>


int main(void)
{
	InitIONLibrary();			//initialization of HEREDES libraries and interfaces

	CHAR SecKey[8];			//8 byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	RegIONId(&Valid, &Id);		//New User Registration

	HDC hCDC;
	HDC hDC=GetDC(NULL);
	HANDLE hCON_IN=IONWaitConnection(&Valid, &Id, NULL);
	HANDLE hCON_OUT=CreateIONHandle();
	SetINVISTParam(hCON_IN,hDC,64, 64, 256, 256,NULL);//set the parameters of the rectangle
                                                     // allowed to send over the network


	if (IONConnectToId(hCON_OUT, NULL, &Valid, &Id, &SecKey, NULL, NULL, NULL)==TRUE)
		{
			hCDC=CreateCompatibleDC(hDC);
			StartRemoteINVIST(hCON_OUT,hCDC,512, 512, 1);	// image dimensions
                                                           // I decided to increase
                                                          // but it was possible to keep the original or, on the contrary, reduce
			
	for (int i=0; i<3; i++){GetRemoteINVISTService(hCON_OUT);};	//I get a video from 3 frames
										//due to the specifics of the codec
			int sB=SaveINVISTtoBPM(hCON_OUT,"screen.bmp");


		}else{
		MessageBoxA(NULL,"connection error","connection status", 48);
		};
		DeleteDC(hCDC);
		IONTerminate(hCON_IN);
		IONDisconnect(hCON_OUT);
		CloseIONHandle(hCON_IN);
		CloseIONHandle(hCON_OUT);

	return 0;
}
      
Download the compiled example 7

Example 8. Own little TeamViewer

//own little TeamViewer
#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
#pragma comment(lib, "C:\\HEREDES\\heredes.lib")
#include <windows.h>
#include <C:\HEREDES\heredes.h>

HANDLE hEv;
WNDPROC __stdcall ProcClose(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam){

	SetEvent(hEv);

	return 0;
}

int main(void)
{
	hEv=CreateEventA(NULL,1,NULL,NULL);
	InitIONLibrary();			//initialization of HEREDES libraries and interfaces

	CHAR SecKey[8];			//8 byte array with encryption key
	DWORD Valid = 0;
	DWORD Id = 0;
	RegIONId(&Valid, &Id);		//New User Registration

	HDC hCDC;
	HDC hDC=GetDC(NULL);
	HANDLE hCON_IN=IONWaitConnection(&Valid, &Id, NULL);
	HANDLE hCON_OUT=CreateIONHandle();
	SetINVISTParam(hCON_IN,hDC,64, 64, GetSystemMetrics(0), GetSystemMetrics(1),NULL);					//set the parameters of the rectangle
	
	if (IONConnectToId(hCON_OUT, NULL, &Valid, &Id, &SecKey, NULL, NULL, NULL)==TRUE)
		{
	hCDC=CreateCompatibleDC(hDC);
	StartRemoteINVIST(hCON_OUT,hCDC,512, 512, 1);	//I decided to increase the size of the image,
                                                   // but it was possible to keep the original or, on the contrary, reduce
			HWND hWin;
			CreateINPRT(hCON_OUT, 64, 32, 512, 300, 0x00CF0000, NULL, &hWin, 1, (WNDPROC) ProcClose);

			WaitForSingleObject(hEv,-1);

		}else{
		MessageBoxA(NULL,"connection error","connection status", 48);
		};
		
		CloseHandle(hEv);
		IONTerminate(hCON_IN);
		IONDisconnect(hCON_OUT);
		CloseIONHandle(hCON_IN);
		CloseIONHandle(hCON_OUT);

	return 0;
}
      
Download the compiled example 8