Click here to Skip to main content
15,903,175 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: help me write a program Pin
Rick York27-Jan-17 5:05
mveRick York27-Jan-17 5:05 
GeneralRe: help me write a program Pin
Richard MacCutchan27-Jan-17 6:15
mveRichard MacCutchan27-Jan-17 6:15 
GeneralRe: help me write a program Pin
Rick York27-Jan-17 8:24
mveRick York27-Jan-17 8:24 
GeneralRe: help me write a program Pin
Richard MacCutchan27-Jan-17 8:41
mveRichard MacCutchan27-Jan-17 8:41 
GeneralRe: help me write a program Pin
Member 1296870329-Jan-17 5:08
Member 1296870329-Jan-17 5:08 
GeneralRe: help me write a program Pin
Richard MacCutchan29-Jan-17 5:51
mveRichard MacCutchan29-Jan-17 5:51 
SuggestionRe: help me write a program Pin
David Crow30-Jan-17 2:19
David Crow30-Jan-17 2:19 
AnswerRe: help me write a program Pin
Patrice T28-Jan-17 13:10
mvePatrice T28-Jan-17 13:10 
Questionhow do i write this program? Pin
Member 1296870326-Jan-17 0:03
Member 1296870326-Jan-17 0:03 
AnswerRe: how do i write this program? Pin
Jochen Arndt26-Jan-17 0:29
professionalJochen Arndt26-Jan-17 0:29 
GeneralRe: how do i write this program? Pin
Stefan_Lang26-Jan-17 19:58
Stefan_Lang26-Jan-17 19:58 
AnswerRe: how do i write this program? Pin
Patrice T28-Jan-17 13:15
mvePatrice T28-Jan-17 13:15 
QuestionPerformance issue when drawing on MFC Pin
Member 162132325-Jan-17 10:59
Member 162132325-Jan-17 10:59 
AnswerRe: Performance issue when drawing on MFC Pin
leon de boer25-Jan-17 18:25
leon de boer25-Jan-17 18:25 
GeneralRe: Performance issue when drawing on MFC Pin
Member 162132326-Jan-17 10:28
Member 162132326-Jan-17 10:28 
GeneralRe: Performance issue when drawing on MFC Pin
leon de boer26-Jan-17 17:50
leon de boer26-Jan-17 17:50 
Questionfree memory when constructor throw exception Pin
john563219-Jan-17 17:49
john563219-Jan-17 17:49 
AnswerRe: free memory when constructor throw exception Pin
rxantos19-Jan-17 19:05
rxantos19-Jan-17 19:05 
AnswerRe: free memory when constructor throw exception Pin
«_Superman_»19-Jan-17 19:32
professional«_Superman_»19-Jan-17 19:32 
AnswerRe: free memory when constructor throw exception Pin
Albert Holguin20-Jan-17 10:14
professionalAlbert Holguin20-Jan-17 10:14 
QuestionSend data to POS Printer by USB Pin
Member 1286002219-Jan-17 16:10
Member 1286002219-Jan-17 16:10 
I need to send a string or char to a "POS Receipt Printer" via USB.

My problem is how to establish a communication with the printer by USB port in C++ (I'm using MFC)

I tried this:

HANDLE dev = CreateFile(
"\\\\.\\USB001",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);

if(dev!=INVALID_HANDLE_VALUE)
{
DWORD dwWritten = 0;
LPCSTR lpszTest = "Hello world!";
::WriteFile(dev, lpszTest, strlen(lpszTest), &dwWritten, NULL);
::CloseHandle(dev);
}

but, it returns by GetLastError() a value = 2 (Can not find the specified file)


Also, I tried this:

HANDLE dev;

CString s("\\\\.\\USB001");
LPWSTR p=(LPWSTR)(LPCTSTR)s;
if(OpenPort(p,(PHANDLE)&dev))
{
CString str = "Hello world!";
LPBYTE pByte = new BYTE[str.GetLength()+1];
memcpy(pByte,(VOID*)LPCTSTR(str),str.GetLength());
LPDWORD r;
r=0;

WritePort(dev,pByte,6,r);

delete [] pByte;
}

But I got frustrated,
due that OpenPort and WritePort belongs to #include <winsplp.h> and <winspool.h> , so it generates a lot of dependencies (libs,dlls) that escapes my knowledge.


If anyone can help me, I will be really grateful.


Yany
AnswerRe: Send data to POS Printer by USB Pin
«_Superman_»19-Jan-17 19:48
professional«_Superman_»19-Jan-17 19:48 
SuggestionRe: Send data to POS Printer by USB Pin
David Crow20-Jan-17 3:15
David Crow20-Jan-17 3:15 
QuestionLight weight solution for distrubted memory map Pin
Member 380393118-Jan-17 16:12
Member 380393118-Jan-17 16:12 
QuestionGdiplus: DrawImage not working Pin
Member 162132314-Jan-17 3:28
Member 162132314-Jan-17 3:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.