|
I'm trying to open a pipe to traverse through a list of files retrieved using a "dir" command. I have everything set up the way I used to have it in one of my other applications; but, for some reason, it's not working.
Here's the code:
if( (fp = _popen( szCommand, "r" )) == NULL )
exit( 1 );
Where fp is defined as FILE* and szCommand is a a CString containing the Short Path to the directory I'm trying to look at. The function returns NULL and shuts the app down. I'm not sure what I'm doing wrong or if it's something caused by Windows 2000 or what. Does anyone have any ideas?
|
|
|
|
|
Is yours a Windows app? Seems like _popen works only for console apps.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
you must pass "dir" command to szCommand not a path
* POPEN.C: This program uses _popen and _pclose to receive a
* stream of text from a system process.
*/
#include <stdio.h>
#include <stdlib.h>
void main( void )
{
char psBuffer[128];
FILE *chkdsk;
if( (chkdsk = _popen( "dir *.c /on /p", "rt" )) == NULL )
exit( 1 );
while( !feof( chkdsk ) )
{
if( fgets( psBuffer, 128, chkdsk ) != NULL )
printf( psBuffer );
}
printf( "\nProcess returned %d\n", _pclose( chkdsk ) );
}
soptest
|
|
|
|
|
I've got a really strange keyboard hooking issue that is causing problems between the debug and release versions of the test code, namely the debug version is working globally while the release version seems to only work within the context of the test app window. Below is the source code for the test app. Any insight into this would be greatly apprecaited.
----------------------------------------------
#include "stdafx.h"
static HHOOK KeyboardHookHandle = NULL;
LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM);
LRESULT CALLBACK KeyboardHookProc(int code, WPARAM wParam, LPARAM lParam)
{
MessageBox(NULL, "Keystroke Detected", "Memorex", MB_OK);
return CallNextHookEx(KeyboardHookHandle, code, wParam, lParam);
}
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_WINLOGO);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = "KeyboardHookTest";
wndclass.hIconSm = LoadIcon (NULL, IDI_WINLOGO);
RegisterClassEx (&wndclass);
hwnd = CreateWindow ("KeyboardHookTest",
"KeyboardHookingTest",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow (hwnd, iCmdShow);
UpdateWindow (hwnd);
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg);
DispatchMessage (&msg);
}
return msg.wParam ;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case WM_CREATE:
KeyboardHookHandle = SetWindowsHookEx(WH_KEYBOARD, KeyboardHookProc, 0, 0);
break;
case WM_SIZE:
break;
case WM_PAINT:
break;
case WM_DESTROY:
if (KeyboardHookHandle)
UnhookWindowsHookEx(KeyboardHookHandle);
PostQuitMessage(0);
break;
}
return DefWindowProc (hwnd, iMsg, wParam, lParam);
}
----------------------------------------------
I can't seem to isolate what is causing such anomalous behavior and I also apologize for the 'messiness' of my code. Again, any help would be apprecaited.
Can you imagine Darth Maul on speed?
|
|
|
|
|
First of all, I'd say your code is clear as water
The docs are rather obscure in this point, but it could be that you have to pass hInstance as the hMod parameter of SetWindowsHookEx --giving it a try is cheap, anyway.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Paying closer attention to the docs, there's a line that says:
All global hook functions must be in libraries
So, you've got to move your code to a DLL. As for why it seemed to work on Debug mode, I guess it is because the executable is run in the context of the debugger process, acting like a sort of DLL on the eye of the system (To check this out, symply execute your debug .EXE by double clicking it outside the IDE. If my theory proves right, you'll get the same behavior as in release mode --no global hooking.)
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
In my owner draw combobox, MeasureItem doesn't get called (at least when I use AddString ). However DrawItem does get called. But without MeasureItem, the heights are screwed up.
What's wrong?
|
|
|
|
|
Are you using a fixed size combo box?
Build a man a fire, and he will be warm for a day Light a man on fire, and he will be warm for the rest of his life!
|
|
|
|
|
I'm not.
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~( CBS_OWNERDRAWFIXED | CBS_SORT );
cs.style |= ( CBS_OWNERDRAWVARIABLE | CBS_DROPDOWNLIST | CBS_HASSTRINGS );
Even if I am, MeasureItem should still be able to determine the height of each entry, just not separately.
|
|
|
|
|
How do you make it so any file with a certain extension is opened with your program?
-Raffi
|
|
|
|
|
I answered this question in other thread... here is
THE LINK
Mauricio Ritter - Brazil
Sonorking now: 100.13560 Trank
The alcohol is one of the greatest enemys of man, but a man who flee from his enemys is a coward.
|
|
|
|
|
Does anyone know the maximum value of an unsigned long and a signed long variable in Windows NT ?
Thanks,
Hoang
Hoang Le
|
|
|
|
|
4,294,967,295 (232-1) and 2,147,483,647 (231-1) respectively.
These are declared for your convenience as the macros ULONG_MAX and LONG_MAX in <limits.h> , so you'd better use those rather than the crude numbers.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
And 64-bit versions of NT will of course be 2^64-1 (18,446,744,073,709,551,615). That is why the macros are useful.
// Rock
|
|
|
|
|
The size of types depends on the compiler, not the OS.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Only as a manner of speaking do the size of the types depend on the compiler. It is stated somewhere in the standard that int , for instance, should be the most natural type of the target processor, meaning the size handled naturally by registers and for which the ALU ops are performed in the most efficient way. So, it is nonsense to have non 32-bit int s for 32-bit processors, and the same goes for 64-bit architectures.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
Joaquín M López Muñoz wrote:
So, it is nonsense to have non 32-bit ints for 32-bit processors, and the same goes for 64-bit architectures.
MS's 64-bit compilers use a 32-bit int to ease Win32-to-Win64 porting.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Oh well, that's a powerful enough reason to retain 32bit int s, I guess.
Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo
|
|
|
|
|
MS's 64-bit compilers use a 32-bit int to ease Win32-to-Win64 porting.
Who ever accused MS of following standards?
|
|
|
|
|
What standards are they going against? The C standard says nothing about int having to match the CPU register size.
--Mike--
Just released - RightClick-Encrypt - Adds fast & easy file encryption to Explorer
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Sonork - 100.10414 AcidHelm
|
|
|
|
|
Right. Now I don't remember the wording, but its meaning is clear: An int shall be the fastest (natural) integral representation for the given target CPU (architecture).
As 64 bits is the natural integer size for a 64-bit CPU, I'd expect that 64-bit integer operations would be the fastest.
|
|
|
|
|
I'm trying to create a bitmap file from a memory device context but the only thing I create is a complete white bitmap.
Here my code:
MyFunction()
{
CClientDC dc(this);
CRect rectBF(0,0,450,450);
CBitmap bmp, *poldbmp;
CDC memdc;
bmp.CreateCompatibleBitmap(&dc, 450, 450);
memdc.CreateCompatibleDC( &dc );
poldbmp = memdc.SelectObject( &bmp );
</A>
m_ctlGraphWnd.DrawGraphToDC(&memdc, rectBF);
memdc.SelectObject(poldbmp);
CPalette palette;
if( dc.GetDeviceCaps(RASTERCAPS) & RC_PALETTE )
{
UINT nSize = sizeof(LOGPALETTE) + (sizeof(PALETTEENTRY) * 256);
LOGPALETTE *pLP = (LOGPALETTE *) new BYTE[nSize];
pLP->palVersion = 0x300;
pLP->palNumEntries =
GetSystemPaletteEntries( dc, 0, 255, pLP->palPalEntry );
palette.CreatePalette( pLP );
delete[] pLP;
}
This code above works correctly. The graph was drawn in memdc.
HANDLE hDIB = DDBToDIB(bmp, BI_RGB, &palette);
if( hDIB == NULL )
return ;
WriteDIB(_T("graph.bmp"), hDIB);
GlobalFree( hDIB );
}
I don't know why but operations done on memdc aren't reflected in CBitmap bmp.
Thanks in advance!
|
|
|
|
|
Hi,
I have a Visual C++ 6.0 that uses a LictControl dialog, it works fine when I edit colums, rows on it! I also can print out its contents ... except:
a) I can not print the column titles
b) Somehow my fonts is very very small
PS: I do have a small zip project file ... I can not attach here. I can send to any one if I have the Email address!
- On the CNewDlg::OnInitDialog() ==> I insert colums titles and row text: OK!
- On the CNewDlg::OnBntPrint() ==> Please help in the // *********> actually do PRINTING here <******** (it locates at the end)
BOOL CNewDlg::OnInitDialog()
{
CDialog::OnInitDialog();
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);
}
}
SetIcon(m_hIcon, TRUE);
SetIcon(m_hIcon, FALSE);
CString temp, strSQL;
LVCOLUMN column;
LVITEM item;
int i;
char* guestListCol[9] = {"Room#", "Status", "FirstName", "LastName",
"CheckIn", "Until", "ExtraDays", "Adults", "Children"};
column.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
column.fmt = LVCFMT_LEFT;
temp = "CHECK-IN GUEST LIST REPORT FOR " + COleDateTime::GetCurrentTime().Format("%m/%d/%Y %H:%M:%S");
strSQL.Format ("SELECT * FROM CurrentGuestList WHERE GuestStatus = 'CheckIn'");
UpdateData (false);
for (i=0; i<9; i++)
{
column.cx = 75;
column.iSubItem = i;
column.pszText = guestListCol[i];
m_report.InsertColumn (i, &column);
}
m_report.DeleteAllItems();
item.mask = LVIF_TEXT;
item.iSubItem = 0;
i = 0;
item.iItem = i;
item.pszText = "dummy";
m_report.InsertItem (&item);
m_report.SetItemText (i, 0, "101");
m_report.SetItemText (i, 1, "Check-In");
m_report.SetItemText (i, 2, "John");
m_report.SetItemText (i, 3, "Senior");
m_report.SetItemText (i, 4, "May/20/2002");
m_report.SetItemText (i, 5, "May/22/2002");
m_report.SetItemText (i, 6, "1");
m_report.SetItemText (i, 7, "2");
m_report.SetItemText (i, 8, "4");
return TRUE;
}
void CNewDlg::OnBntPrint()
{
CPrintDialog dlg (FALSE);
if (dlg.DoModal() == IDOK)
{
HDC hdc = dlg.GetPrinterDC();
CDC dc;
DOCINFO docinfo;
memset(&docinfo, 0, sizeof(docinfo));
docinfo.cbSize = sizeof(docinfo);
docinfo.lpszDocName = _T("CDC::StartDoc() Code Fragment");
dc.Attach(hdc);
if (dc.StartDoc(&docinfo) < 0)
MessageBox(_T("Printer wouldn't initalize"));
else
{
if (dc.StartPage() < 0)
{
MessageBox(_T("Could not start page"));
dc.AbortDoc();
}
else
{
m_report.Print(&dc, PRF_NONCLIENT);
m_report.Print(&dc, PRF_CLIENT);
}
dc.EndPage();
dc.EndDoc();
}
}
}
I tried to do a lot of things but failed, can anyone help me?
Thanks
ATC
|
|
|
|
|
i am using this code to put every other letter in a Cstring into a CString variable.
CString mPWD;
CString szTemp;
BOOL bMakePass = TRUE;
CString m_cPwd;
m_cPwd = szPassword;
for (int i = 0; i < m_iPwdLength; i++)
{
if (bMakePass)
{
szTemp = mPWD;
mPWD.Format("%s", m_cPwd.GetAt(i));
szTemp += mPWD;
mPWD = szTemp;
bMakePass = FALSE;
}
else
bMakePass = TRUE;
}
return mPWD;
but it causes the app to crash.
==================================================
Homepage: www.onyeyiri.co.uk
Email: theeclypse@hotmail.com
"I'm not any old Eclypse, i'm TheEclypse..get it, got it, good!"
|
|
|
|
|
CString s = "Hello World from Nish";
CString t="";
for(int i=0;i<s.GetLength();i+=2)
t+=s[i];
Regards,
Nish
Native CPian.
Born and brought up on CP.
With the CP blood in him.
|
|
|
|
|