|
Could someone lead me to a source for writing to and reading from COM1 in pure binary mode as simple as possible. Looking to send and receive single bytes in range of 0x00-0xff. The final code needs to work on WinXP platform. Thanks.
|
|
|
|
|
|
these are my codes for image processing...im not sure why im getting this " INTERNAL COMPILER ERROR". pls help me...and pls do tell me whether if i continue with this codes, will i be able to perform thinning and edge detection..i have problems in developing the codes..pls do help me and i sincerely appreciate all the helps..thank you...
#include "stdafx.h"
#include "fvas.h"
#include "fvasDlg.h"
#include <math.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFvasDlg dialog
CFvasDlg::CFvasDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFvasDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFvasDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CFvasDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFvasDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFvasDlg, CDialog)
//{{AFX_MSG_MAP(CFvasDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_BUTTON1_DISPLAY, OnDisplay)
ON_BN_CLICKED(IDC_STATIC_BITMAP, OnStaticBitmap)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFvasDlg message handlers
BOOL CFvasDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CFvasDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void CFvasDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFvasDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CFvasDlg::OnDisplay()
{
// TODO: Add your control notification handler code here
static char BASED_CODE szFilter[] = "Bitmap Files (*.bmp) |*.bmp||";
CString m_sBitmap;
CFileDialog m_ldFile(TRUE, ".bmp", m_sBitmap, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter);
if (m_ldFile.DoModal() == IDOK)
{
m_sBitmap = m_ldFile.GetPathName();
HBITMAP hBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP, 100,140, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
HBITMAP hGrayBitmap = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP, 100,140, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
HBITMAP hGrayBitmap1 = (HBITMAP) ::LoadImage(AfxGetInstanceHandle(), m_sBitmap, IMAGE_BITMAP, 100,140, LR_LOADFROMFILE | LR_CREATEDIBSECTION);
BITMAP bm;
BITMAP bm1;
GetObject(hGrayBitmap, sizeof(BITMAP), (LPSTR)&bm);
typedef struct tagBITMAP
{
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
}
BITMAP, *PBITMAP;
if (hGrayBitmap)
{
CStatic *pImgPicture = (CStatic*)GetDlgItem(IDC_STATIC_BITMAP);
BYTE * pImgByte = (BYTE *) bm.bmBits;
if(pImgPicture==NULL)
{
AfxMessageBox("Fail to get Picture Control");
}
else
{
INT iWidthBytes = bm.bmWidth * 3;
for ( int y = 0; y < bm.bmHeight; y++)
{
for ( int x = 0; x < bm.bmWidth*3; x++)
{
unsigned char R = pImgByte[y*iWidthBytes+x+2];
unsigned char G = pImgByte[y*iWidthBytes+x+1];
unsigned char B = pImgByte[y*iWidthBytes+x];;
INT gray = ceil(0.3*R + 0.59*G + 0.11*B);
pImgByte[y*iWidthBytes+x+2] = gray;
pImgByte[y*iWidthBytes+x+1] = gray;
pImgByte[y*iWidthBytes+x] = gray;
}
}
void threshold (struct Image *bm, struct Image *bm1, int THRES)
{
int X, Y, GO, GB;
GO= 225;
GB= 0;
for (Y=0; Y<=bm.bmHeight; Y++)
{
for (X=0; X<=bm.bmWidth*3; X++)
{
if (*(bm.bmBitsPixel + X + (long) Y * bm.bmWidth*3) > THRES)
*(bm1.bmBitsPixel + X + (long) Y * bm.bmWidth*3) = GO;
else
*(bm1.bmBitsPixel + X + (long) Y * bm.bmWidth*3) = GB;
}
}
}
pImgPicture->SetBitmap(hGrayBitmap);
}
}
}
}
|
|
|
|
|
It would help, and you'd get a lot more responses, if you'd trim your code down to just the pieces necessary to reproduce the problem.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
/agree
I didn't feel like figuring it all out, but a suggestion would be to block comment out every method in the file except one. Then compile. If you get no errors, uncomment another function and recompile. Continue until you can at least figure out which particular function is causing the problem. Then try repeating the process with individual lines within the offending function.
Bob Ciora
|
|
|
|
|
This is definitely puzzling:
BITMAP bm;
BITMAP bm1;
GetObject(hGrayBitmap, sizeof(BITMAP), (LPSTR)&bm);
typedef struct tagBITMAP
{
LONG bmType;
LONG bmWidth;
LONG bmHeight;
LONG bmWidthBytes;
WORD bmPlanes;
WORD bmBitsPixel;
LPVOID bmBits;
}
BITMAP, *PBITMAP;
Defining variables of your type BITMAP before you've actually defined the structure?
Bob Ciora
|
|
|
|
|
bm and bm1 are instances of BITMAP that is defined in wingdi.h .
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Point taken But I'm still curious why this declaration is here.
Bob Ciora
|
|
|
|
|
Bob Ciora wrote:
But I'm still curious why this declaration is here.
Agreed. It serves no logical purpose.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Somebody correct me if I'm wrong, but AFAIK, you can't define a structure within a method. Take out the BITMAP structure definition and it should get rid of the compilation error.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I need to check if a folder exists. I have a specific path and will perform a certain action only if that path exists. How can I check to see if a specific folder (ie. "c:\Program Files\Debug") exists.
I have already tried using the WIN32 API call GetFileAttributes. I was checking to see if there was an error or not to see if the folder exists. The call returns an error regardless. The path is a BSTR, casted to char*, casted to LPCTSTR, if this is a problem.
|
|
|
|
|
ChemmieBro wrote:
I need to check if a folder exists.
See here and here.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Thanks for the links.
But actually, I tried pretty much everything there. Thing is, the _access ends up calling the GetFileAttributes API call and the GetFileAttributes call was what I was having problems with.
I actually found out what the problem was that I was having with GetFileAttributes. I guess the GetFileAttributes has it's own parser to parse the string you feed into it. I was feeding in a path that I had read straight from the registry. It was "C:\Program Files\Program". In order to turn off the parser (it tells me this in the help section), you need to append "\\?\" to the front of the path.
Since I had my path in a variable, I needed to do this in order to get the correct path for stuffing into the GetFileAttributes function...
Path = "\\\\?\\" + Path;
It works now.
|
|
|
|
|
ChemmieBro wrote:
Thing is, the _access ends up calling the GetFileAttributes API...
Where is this documented at?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I don't believe it is documented. But if you step into the _access() call while debugging, it's right there.
|
|
|
|
|
Thanks for the tip.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
I think you might be surprised if you take a 'generic' C app and build it in windows and then trace through the 'standard C function' calls. You will find many of them devolving into regular WIN32 API calls. People were trying to convince me one time that the File* functions (fopen, close, fprintf, etc.) were faster than CreateFile WriteFile, ReadFile, etc. I traced into the C runtime and find that after a lot of variable hashing and flags manipulation, they end up calling the Win32 API anyway, so I just started calling the Win32 API directly, as there is no effort at being 'port ready' to other platforms for our products.
I am not surprised that _access calls GetFileAttributes.
|
|
|
|
|
ChemmieBro wrote:
The path is a BSTR, casted to char*, casted to LPCTSTR, if this is a problem.
It is. A BSTR is a unicode string; you can't cast it to a char*. You'll have to call the unicode version of the function (GetFileAttributesW() ), or use the W2T() ATL conversion macro to convert from unicode to LPCTSTR.
Ryan "Punctuality is only a virtue for those who aren't smart enough to think of good excuses for being late" John Nichol "Point Of Impact"
|
|
|
|
|
I implemented a function for something I worked on that checks to see if a file exists, but the documentation indicates that it works for directories as well as files. So take a look at this. It's worked well for me and seems very reliable. It seems different than the other responses, so if you are still looking for an alternative; here you go.
I simply created a CString as input. The CString may contain wildcard characters such as * or ?. FindFirstFile is a global method and can be found in the MSDN library so go ahead and look it up and feel free to cut and paste this function and play with it to see how it works. It's pretty simple.
BOOL CDXControlDlg::IsNewFile(CString& sPath)
{
// Check if files exists already
WIN32_FIND_DATA fileInfo;
HANDLE hFile = ::FindFirstFile(sPath, &fileInfo);
if (hFile == INVALID_HANDLE_VALUE) {
// File not found
return TRUE;
} else {
// File exists.
::FindClose(hFile);
return FALSE;
}
}
Best Regards,
Shawn
|
|
|
|
|
Hallo,Before all i want to say sorry to my poor english.
I'm little new in this kind of develop like C++, and i'm trying to do a client server in visual c++ where i have to do a connection with the login of one user that previous is registered (but it's not my problem).When i have the user login, with this user i have to send the information to the server and the server will say me what access i have, like if i have access to different devices like USB, cd-Rom,..( it's my real problem, how can i restrict the different kind of devices?) or what files have i access to download to my client and i think that here i have to implement Encrypt of files.
Somebody can say me how can i do this or which libraries can i use or a idea of like implement this problem.
Thank you very much and i hope that you can help me.
|
|
|
|
|
As for the client/server part of the question, I'd suggest that you look into writing network applications, there are plenty of good books on this. There is one by MS press that is great. As for the restricting access to devices part of the question, I'd suggest that you outsource this work to someone who knows about the internals of windows, someone who can develop device drivers. This isn't the sort of thing I'd suggest doing yourself if you don't have the understanding of these concepts already. You won't find any libraries to do this for you.
-- Rocky Dean Pulley
|
|
|
|
|
Ok, thanks, so you recommended me that i read something about Network applications, ok. But i have one question more, to who can i ask about develop device drivers?.
Thanks.
/Jorge
|
|
|
|
|
Hello all,
I am running into a somewhat odd problem with printing from an MFC program. I am getting printouts just fine, but there seems to be a difference between the preview page and the printed page. The preview, in this case, prints 40 lines to a page, while the printed version prints 41. Since the overall printout is about 64-65 pages long, this is causing the last few pages to be very different between the two.
I put in some TRACE statements to print the height of a line with each font type I am using, and this is what I got (the fonts are all Times New Roman, various point sizes):
For the Preview version:
Preparing Page 2
Page 2
Report Hdr: 00155
Page Hdr: 00095
Table Caption: 00115
Column Hdr: 00115
Table Body: 00095
Table Total: 00095
Page Footer: 00075
Report Footer: 00075
Printing Page 2
Line Start 1110
Line Start 1225
Line Start 1340
Line Start 1455
Line Start 1570
Line Start 1685
Line Start 1800
...
Line Start 5020
Line Start 5135
Line Start 5250
Line Start 5365
Line Start 5480
Line Start 5595
For the Print version:
Preparing Page 2
Page 2
Report Hdr: 00151
Page Hdr: 00094
Table Caption: 00114
Column Hdr: 00114
Table Body: 00094
Table Total: 00093
Page Footer: 00075
Report Footer: 00075
Printing Page 2
Line Start 1108
Line Start 1222
Line Start 1336
Line Start 1450
Line Start 1564
Line Start 1678
Line Start 1792
...
Line Start 4984
Line Start 5098
Line Start 5212
Line Start 5326
Line Start 5440
Line Start 5554
Line Start 5668
As you can see, the font heights are a little different. This is causing an extra line per page. I did not think this was possible, since I am using the default printer definition in both cases. Is there any way to compensate for this?
Thanks for any hint anyone can provide.
Santanu
|
|
|
|
|
Hi
I have trouble using CDoc variable in MainFrm. I have included Cdoc.h in MainFrm but the error of undeclared variable still existed.
CDoc& pDoc = GetDocument();
ASSERT_VALID(pDoc);
This is how I normally getting CDoc variable from CView but it doesnt work in MainFrm. Please advise. THanks.
|
|
|
|
|
I think there is a GetActiveDocument(). If not that, then use GetActiveFrame(), from there you get the view of the frame and from that the document of the view.
Its a bit long winded.
If you vote me down, my score will only get lower
|
|
|
|
|