|
Thanks for the reply Joaquin, I was wondering how to use the try catch exceptions without MFC (I have used CException but obviously can't if I'm not using MFC) and you have given it to me on a plate, so many thanks for that . I also thank you for reaffirming the loading method, you know sometimes when you get that feeling when something doesn't quite feel right (thats what I got)? I think your example looks a lot sweeter, mind, with the try catch stuff in it, its exactly what I was looking for. Again, many thanks Joaquin, may the code be with you.
Alan.
"When I left you I was but the learner, now I am the master" - Darth Vader
|
|
|
|
|
I have a problem converting a CComBSTR to LPCTSTR with CW2CT. Eveything works fine until my CComBSTR gets around 64 caracters... then the result of the convertion is a long "corrupted" string: "îþîþîþîþîþîþîþîþîþîþîþîþîþîþîþ...."
Please help me !
-----
See comments between /* */ for more info
-----
LRESULT CListBoxDlg::OnBnClickedBtngetselitems(WORD , WORD , HWND , BOOL& )
{
LPCTSTR sTitle;
int arrSelList[12];
TCHAR pszBuf[128] = "";
int iMaxNum = 12;
LRESULT iSelCount = 0;
LPCTSTR sMsg = 0;
CComBSTR bsMessage;
iSelCount = this->SendDlgItemMessage(IDC_AVSCODES, LB_GETSELITEMS, WPARAM(iMaxNum), LPARAM(arrSelList));
if (iSelCount != LB_ERR) {
bsMessage.Append("You have selected the fields: ");
_stprintf(pszBuf, "%li", arrSelList[0]);
bsMessage.Append(pszBuf);
for (int i = 1; i < iSelCount; i++) {
bsMessage.Append(", ");
_stprintf(pszBuf, "%li", arrSelList[i]);
bsMessage.Append(pszBuf);
}
bsMessage.Append(".");
sMsg = CW2CT(bsMessage.m_str);
sTitle = _T("Selected Items List");
::MessageBox(this->m_hWnd, sMsg, sTitle, MB_OK);
}
return 0;
} ompared to ATL 3.0
*/
sMsg = CW2CT(bsMessage.m_str);
/*
// The following two lines makes it work fine but USES_CONVERSION is not supposed
// to be needed with ATL 7.0
USES_CONVERSION;
sMsg = W2CT(bsMessage.m_str);*/
sTitle = _T("Selected Items List");
::MessageBox(this->m_hWnd, sMsg, sTitle, MB_OK);
}
return 0;
}
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
J.-C. Gauthier - http://www.grandmenhir.com/
|
|
|
|
|
This is the problem:
TCHAR pszBuf[128] = "";
buffer size is for 64 wide char's
soptest
|
|
|
|
|
even with 1024 it doesn't work
TCHAR pszBuf[1024] = "";
maybe there is something else I need to do.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
J.-C. Gauthier - http://www.grandmenhir.com/
|
|
|
|
|
Use thi9s code:
inline char* ConvertBSTRToString(BSTR pSrc)
{
if(!pSrc) return NULL;
DWORD cb,cwch = ::SysStringLen(pSrc);
char *szOut = NULL;
if(cb = ::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch + 1, NULL, 0, 0, 0))
{
szOut = new char[cb];
if(szOut)
{
szOut[cb - 1] = '\0';
if(!::WideCharToMultiByte(CP_ACP, 0, pSrc, cwch + 1, szOut, cb, 0, 0))
{
delete []szOut;
szOut = NULL;
}
}
}
return szOut;
};
soptest
|
|
|
|
|
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
|
|
|
|
|