Código: Selecionar todos
////////////////////////////////////////////////////////////////////////////////
//Arquivo com as funções em C++
////////////////////////////////////////////////////////////////////////////////
#include "common.ch" // para poder redefinir a função type() para ischaracter() e outras
#include "winuser.ch"
/////////////////////////////////////////////////////////////////////////////
#pragma BEGINDUMP
#pragma comment( lib, "shell32.lib" )
#include <winsock.h>
#include <windows.h>
#include "winbase.h"
#include "winuser.h"
#include <stdio.h>
#include <stdlib.h>
#include <Iphlpapi.h>
#include <Assert.h>
#include "hbapi.h"
#include "hbapiitm.h"
#include "item.api"
#define HB_OS_WIN_32_USED
/////////////////////////////////////////////////////////////////////////////
HB_FUNC( _OPENHELPFILE )
{
HINSTANCE hInst;
LPCTSTR lpPath = (LPTSTR) hb_parc( 1 );
LPCTSTR lpHelpFile = (LPTSTR) hb_parc( 2 );
hInst = ShellExecute( 0, "Open", lpHelpFile, 0, lpPath, 1 );
hb_retnl( (LONG) hInst );
return;
}
//------------------------------------------------------------------
// standard 32 byte's M$ guid
// Link: http://forums.fivetechsupport.com/viewtopic.php?f=3&t=28026&p=156570&hilit=guid#p156570
// Link: http://forums.fivetechsupport.com/viewtopic.php?f=3&t=21719&start=30
//------------------------------------------------------------------
HB_FUNC( _NEWGUID32 )
{
GUID guid;
char obuff[38];
memset( obuff, 0x0, 38 );
if ( CoCreateGuid(&guid) == NULL )
{
OLECHAR tmpbuff[76];
StringFromGUID2(&guid, tmpbuff, 76);
WideCharToMultiByte(CP_OEMCP, 0, tmpbuff, -1, obuff, 38, NULL, NULL);
}
hb_retclen(obuff, 38);
}
/////////////////////////////////////////////////////////////////////////////
//Pressionar a tecla alt
//https://docs.microsoft.com/pt-br/windows/win32/inputdev/virtual-key-codes
HB_FUNC( _VKALT )
{
keybd_event (VK_MENU, 0, 0, 0 );
keybd_event (VK_MENU, 0, KEYEVENTF_KEYUP, 0);
}
/////////////////////////////////////////////////////////////////
//Pressionar qualquer tecla
HB_FUNC( _VKLETRA )
{
keybd_event (hb_parnl(1), 0, 0, 0 );
keybd_event (hb_parnl(1), 0, KEYEVENTF_KEYUP, 0);
}
/////////////////////////////////////////////////////////////////
//Pressionar seta direita
HB_FUNC( _VKSETADIR )
{
keybd_event (VK_RIGHT, 0, 0, 0 );
keybd_event (VK_RIGHT, 0, KEYEVENTF_KEYUP, 0);
}
/////////////////////////////////////////////////////////////////
//Pressionar seta baixo
HB_FUNC( _VKSETABAI )
{
int n; //= 1;
for(n = 1; n <= hb_parni(1); n++) {
keybd_event (VK_DOWN, 0, 0, 0 );
keybd_event (VK_DOWN, 0, KEYEVENTF_KEYUP, 0);
}
}
//////////////////////////////////////////////////////////////////////////////////////
//
HB_FUNC( _CLI ) //Retorna o nome do usuário do windows
{
//ponteiro char[] para o IP retornado no formato string
char *IP;
struct in_addr ipGeral;
//ponteiro para a estrutura que armazena o IP obtido pelo nome do pc
struct hostent * ipPeloNome;
char nomeDoPCLocal[255]; //armazena o nome do computador local
WSADATA infoSocket; //estrutura para obter as informações básica do socket no windows.
//inicializa o socket 2.0 no windows - sem essa inicialização, vc não tem
//permissão para utilizar as funções de rede no windows.
WSAStartup(MAKEWORD(2,0), &infoSocket);
gethostname(nomeDoPCLocal, 255); //função obtém o nome da sua máquina local
//função retorna o endereço para uma estrutura do tipo hostent, que dentre outras opções
//armazena o endereço de ip referente ao nome do PC passado como argumento para essa função.
ipPeloNome = gethostbyname(nomeDoPCLocal);
//copia o IP obtido para uma estrutura do tipo "in_addr"
memcpy(&ipGeral, ipPeloNome->h_addr_list[0], sizeof(struct in_addr));
//inet_ntoa() decodifica a estrutura do tipo "in_addr" e retorna o IP em uma string de
//caracteres legíveis.
IP = inet_ntoa(ipGeral);
hb_retc( IP);
WSACleanup();
}
///////////////////////////////////////////////////////////////////////////////////////////
// Pega o MAC da placa de Rede
HB_FUNC(_CLM)
{
IP_ADAPTER_INFO AdapterInfo[16]; // Allocate information for up to 16 NICs
DWORD dwBufLen = sizeof(AdapterInfo); // Save the memory size of buffer
unsigned char ret[ 20 ] ={0};
DWORD dwStatus = GetAdaptersInfo( // Call GetAdapterInfo
AdapterInfo, // [out] buffer to receive data
&dwBufLen); // [in] size of receive data buffer
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;// Contains pointer to current adapter info
//assert(dwStatus == ERROR_SUCCESS); // Verify return value is valid, no buffer overflow
sprintf(ret,"%02X-%02X-%02X-%02X-%02X-%02X",
pAdapterInfo->Address[0], pAdapterInfo->Address[1],
pAdapterInfo->Address[2], pAdapterInfo->Address[3],
pAdapterInfo->Address[4], pAdapterInfo->Address[5]);
hb_retc(ret);
}
/////////////////////////////////////////////////////////////////////////////
//
HB_FUNC( _CLSHIFT )
{
HINSTANCE mRetorno;
LPCTSTR mString1 = (LPTSTR) hb_parc( 1 );
LPCTSTR mString2 = (LPTSTR) hb_parc( 2 );
// temos que converter a string em um valor inteiro válido
int res1 = atoi(mString1);
int res2 = atoi(mString2);
hb_retnl( (LONG) (res1 ^ ( res2 >> 8 )) );
return;
}
#pragma ENDDUMP