//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//Declaração dos ponteiros para função.
typedef short _stdcall (*PtrInp)(short EndPorta);
typedef void _stdcall (*PtrOut)(short EndPorta, short datum);
HINSTANCE hLib; //Instância para a DLL inpout32.dll.
PtrInp inportB; //Instância para a função Imp32().
PtrOut outportB; //Instância para a função Out32().
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
//Carrega a DLL na memória.
hLib = LoadLibrary("inpout32.dll");
if(hLib == NULL)
{
ShowMessage("Erro. O arquivo inpout32.DLL não foi encontrado.");
Application->Terminate();
}
//Obtém o endereço da função Inp32 contida na DLL.
inportB = (PtrInp) GetProcAddress(hLib, "Inp32");
if(inportB == NULL)
{
ShowMessage("Erro. Erro ao endereçar a função Inp32.");
Application->Terminate();
}
//Obtém o endereço da função Out32 contida na DLL.
outportB = (PtrOut) GetProcAddress(hLib, "Out32");
if(outportB == NULL)
{
ShowMessage("Erro. Erro ao endereçar a função Out32.");
Application->Terminate();
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCloseQuery(TObject *Sender, bool &CanClose)
{
FreeLibrary(hLib); //Libera memória alocada pela DLL
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if(StrToInt(Edit1->Text) <=255)
{
outportB(0x378,StrToInt(Edit1->Text));
}
}
//---------------------------------------------------------------------------
Kleber escreveu:É impressão ou o programa em Delphi parece ser mais "limpo"?
Kleber escreveu:É impressão ou o programa em Delphi parece ser mais "limpo"?
//Declaração dos ponteiros para função.
typedef short _stdcall (*PtrInp)(short EndPorta);
typedef void _stdcall (*PtrOut)(short EndPorta, short datum);
HINSTANCE hLib; //Instância para a DLL inpout32.dll.
PtrInp inportB; //Instância para a função Imp32().
PtrOut outportB; //Instância para a função Out32().
Function inportb(EndPorta: Integer) BYTE stdcall; external ‘inpout32.dll’ name ‘Inp32’
Procedure outportb(EndPorta:Integer; Valor:BYTE); stdcall; external ‘inpout32.dll’ name ‘Out32’;
Function inportb(EndPorta: Integer) BYTE stdcall; external ‘inpout32.dll’ name ‘Inp32’
Procedure outportb(EndPorta:Integer; Valor:BYTE); stdcall; external ‘inpout32.dll’ name ‘Out32’;
Function inportb(EndPorta: Integer) BYTE stdcall;
external ‘inpout32.dll’ name ‘Inp32’
Procedure outportb(EndPorta:Integer; Valor:BYTE);
stdcall;
external ‘inpout32.dll’ name ‘Out32’;
Jorge_Francisco escreveu:Alem da portabilidade do c++, escrever "Begin" e "end" não torna-se prático...
Wagner de Queiroz escreveu:um simples hellow word basicao chamou centenas de arquivos para compilar um executavel, e quase dois longos minutos para compilar.
Voltar para Visual C++/C/C++/C#
Usuários navegando neste fórum: Nenhum usuário registrado e 0 visitantes