POS 시스템 용 극 디스플레이 제품이 있으므로 화면에 일부 데이터를 표시하려고합니다. 은 내가 C-코드가 그 작업을 잘 C-코드해야 할 :델파이 - NULL 종료 문자
// demo.cpp : Defines the entry point for the console application.
//
#include <stdio.h>
#include <time.h>
#include <iostream>
using namespace std;
#include "windows.h"
int __cdecl main(int argc, char* argv[])
{
char in;
HMODULE hm;
long (*ou)();
long (*cu)();
long (*wp)(char*,long);
long (*ps)();
time_t tm;
char ss[64];
SetLastError(0);
hm = LoadLibrary("usbpd.dll");
printf(" hm = %p, %lu \n",hm,GetLastError());
if (hm==NULL) return 1;
SetLastError(0);
ou = (long(*)()) GetProcAddress(hm,"OpenUSBpd");
printf(" ou = %p, %lu \n",ou,GetLastError());
SetLastError(0);
cu = (long(*)()) GetProcAddress(hm,"CloseUSBpd");
printf(" cu = %p, %lu \n",cu,GetLastError());
SetLastError(0);
wp = (long(*)(char*,long)) GetProcAddress(hm,"WritePD");
printf(" wp = %p, %lu \n",wp,GetLastError());
SetLastError(0);
ps = (long(*)()) GetProcAddress(hm,"PdState");
printf(" ps = %p, %lu \n",ps,GetLastError());
printf(" OpenUSB = %ld \n", ou());
wp("Price: 5.00 ", 20);
wp("Total: 33.00 ", 20);
//for (long i=0;i<3;++i)
// {
// printf(" ps(1) = %ld \n", ps());
// time(&tm);
// sprintf(ss,"\x1b\x40%s",ctime(&tm));
// wp(ss, strlen(ss));
// if (argc>1) for (int j=30;j<255;++j) { ss[0] = j; ss[1] = 0; wp(ss,1);}
// printf(" ps(2) = %ld \n", ps());
// }
printf(" CloseUSB = %ld \n", cu());
cin.get();
FreeLibrary(hm);
return 0;
}
을 나는 C-코드, 로 동일한 기능을 수행 할 볼랜드 델파이로 작성된 코드를 가지고 있지만, 후 것은 내 데이터를 표시 그것은 쓰레기 문자를 보여줍니다.
델파이 코드 :
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDLLFunc = function(): Integer;
ptr = ^TChar;
TChar = array[1..20] of PChar;
TDLLWriteFunc = function(ps_Text: ptr; pi_Length: Integer): Integer;
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Edit1: TEdit;
Button3: TButton;
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
h: THandle;
OpenUSBpd : TDLLFunc;
CloseUSBpd: TDLLFunc;
WritePD : TDLLWriteFunc;
PdState : TDLLFunc;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button3Click(Sender: TObject);
var xx: TChar;
pxx: ptr;
i: Integer;
begin
h:= LoadLibrary('D:\GlassTech\Taboon\Devices\PD23_26U\USBPD.DLL');
if(h <> 0)then
begin
@OpenUSBpd := GetProcAddress(h, 'OpenUSBpd');
@CloseUSBpd:= GetProcAddress(h, 'CloseUSBpd');
@WritePD := GetProcAddress(h, 'WritePD');
@PdState := GetProcAddress(h, 'PdState');
OpenUSBpd;
end;
xx[1] := 'A';
xx[2] := 'B';
xx[3] := 'C';
xx[4] := 'D';
xx[5] := 'E';
xx[6] := 'F';
xx[7] := 'G';
xx[8] := 'H';
xx[9] := 'I';
xx[10]:= 'J';
xx[11]:= 'K';
xx[12]:= 'L';
xx[13]:= 'M';
xx[14]:= 'N';
xx[15]:= 'O';
xx[16]:= 'P';
xx[17]:= 'Q';
xx[18]:= 'R';
xx[19]:= 'S';
xx[20]:= 'T';
pxx:= @xx;
WritePD(pxx, 0);
CloseUSBpd;
end;
end.
제발 도와주세요, 감사합니다 모든
내가 결정할 수없는 코드가 더 나쁘다. C 나 델파이. 계속 진행하기 전에 프로그래밍의 첫 번째 원칙을 훨씬 더 견고하게 파악해야한다고 생각합니다. –
스택 오버플로에 오신 것을 환영합니다. 샘플 코드를 게시하여 Upvoted. 비록 우리 중 대부분이 당신의 코드가 좋지 않다고 생각 하긴하지만, 귀하의 코드가 없으면 귀하의 질문에 답변 할 수 없기 때문에 귀하가 게시 한 것을 기쁘게 생각합니다! –
David 씨, 답장을 보내 주셔서 감사합니다 우선 C 코드는 제작자가 작성한 데모이며 괜찮습니다. 델파이 코드에 대한 답변은 입니다. Andreas Rejbrand와 Mr. .Rudy Velthuis –