Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
J

Joe Moldovan

@Joe Moldovan
About
Posts
44
Topics
12
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • access to path
    J Joe Moldovan

    I use the Shell Lightweight Utility APIs for this kind of stuff. You need to include "Shlwapi.h" and build with "Shlwapi.lib". The API is very easy to use. For your question, BOOL PathFileExists( LPCTSTR pszPath ); You can find this in MSDN->Platform SDK->User Interface Services->Windows Shell-> Shell Reference->Shell Lightweight Utility APIs Hope this helps!

    C / C++ / MFC question help

  • FindFirstfile parameter...
    J Joe Moldovan

    Do you mean that you want to find "*.abc" OR "*.xyz" in a folder? If so, I think you need two FindFirstFile() calls. HANDLE h1 = FindFirstFile( "*.abc", &filedata1 ); HANDLE h1 = FindFirstFile( "*.xyz", &filedata2 ); You have a match when, if (( h1 != INVALID_HANDLE_VALUE ) || ( h2 != INVALID_HANDLE_VALUE )) { .....Process h1 .....Process h2 } Joe M

    C / C++ / MFC question

  • Guarding delete
    J Joe Moldovan

    Thanks for your thoughts. I didn't design or write this stuff. I'm only trying to wrap an audio interface I got pre-cooked. I watch my own new's and delete's like a hawk and always have the leakage detector on. The bit about nulling the pointer is very good (simple and obvious) and will be standard in my code from now on. I do however find it strange that delete doesn't throw a catchable exception. There must be a good reason for it. I will try it on Linux and see if it tells me why.

    C / C++ / MFC question debugging help tutorial announcement

  • Guarding delete
    J Joe Moldovan

    Does anyone know of a way to guard a delete operator from trying to release a non-allocated block, as in the following trivial example. short x[ 100 ]; try { delete []x; } catch( ... ) { return MDERROR; } This does not work as the exception is caught somewhere in the bowels of the system and I get either an assert or a user breakpoint box. I have looked at RTTI but it doesn't help me. How can I prevent a crash if I'm passed a pointer to a global or static block? Thanks all!

    C / C++ / MFC question debugging help tutorial announcement

  • Enumerating devices
    J Joe Moldovan

    I have solved my original problem. I will post a solution as a new thread because it has some very interesting implications for direct access to devices. As I suspected, the solution is grotesque but works very well.

    C / C++ / MFC question

  • Enumerating devices
    J Joe Moldovan

    For someone who says he doesn't know much you sure know a lot more about this stuff than me! Thank you for your very helpful tips. The whole device/driver architecture/interface from MS is absolutely shocking. I have spent THREE whole days trying to do something which is trivial (send a "keep alive" null message every 5 minutes to a USB POS printer, an insignificant task for LPT1: or PRN: ) and I'm still scratching my head. But I did manage to answer the original question about SetupDiEnumDeviceInterfaces() parameters. To help others struggling with this stuff, the "Pointer to a GUID that specifies the device interface class for the requested interface" mentioned in the ISDN, can be found in HKLM\SYSTEM\CurrentControlSet\Control\DeviceClasses. MS does not want us to access these directly but I have found no other way. NOTE that there are a set of GUIDS which are the SETUP classes and are given in devguid.h. They won't work with this call but can be used in SetupDiGetClassDevs etc. as selectors for restricting the device data. I am going to use IOCTL as per your suggestion. Who knows! In another ten years or so I might even understand all this.

    C / C++ / MFC question

  • Enumerating devices
    J Joe Moldovan

    Thanks for that. But I need the bit with "Device Instance Handle, such as the Config Manager set of API functions, can use the DevInst value in the structure SP_DEVINFO_DATA returned by the SetupDiEnumDeviceInfo function" to work. And no, this call is not documented in the DDK any better than in the MSDN! Hope you have fun persevering with the book.

    C / C++ / MFC question

  • Enumerating devices
    J Joe Moldovan

    Has anyone ever used SetupDiEnumDeviceInterfaces? If so what the &%$#@ is the "CONST LPGUID InterfaceClassGuid" parameter refering to? I have tried values from the "devguid.h" but I get nothing. SetupDiGetClassDevs works with GUID_DEVCLASS_PRINTER and others like it. Has anyone ever found a generic way of enumerating devices and/or drivers on Win NT/2000. I'm just about to tear my hair out trying to find the device name for a USB printer. Why does it have to be so hard??? X| X| X|

    C / C++ / MFC question

  • throw and catch
    J Joe Moldovan

    I think you are correct and a thread can't be interrupted. I don't see any great technical difficulty in doing it (that's really what the scheduler does after all) but the system is designed not to do it, so that's that. I looked at APCs but they only work when the thread is sleeping or waiting so that's no good to me either. I need to have functions (node/action functions for a state machine written by others) running by themselves and being timed out in the state engine which I wrote. What do you mean "return an error value from the thread"? Do you mean the value in the terminating "return int" or some other mechanism I don't know about. I know you can get the terminating value when a thread exits is this what you mean? Thanks for your thoughts anyway. Joe M.

    C / C++ / MFC data-structures tutorial question

  • throw and catch
    J Joe Moldovan

    Does anyone know how to throw an exception across threads? Is this possible at all given the stack unwinding issues? Is there perhaps some other mechanism for interrupting the logic of one thread from another without Waits or SleepEx or other sync functions. Callbacks - from timers etc. - are in the calling thread so they are no good to me. I need to protect a block of code as follows, Start timer ------------- Code Block normal exit ------------- Timeout timeout exit The try/catch block is ideal but the timers run in their own threads so I don't catch nothing. Thanks to all!

    C / C++ / MFC data-structures tutorial question

  • CreateWaitableTimer is not creating
    J Joe Moldovan

    Thanks Michael!!! Saved me again as usual. I also found the answer in MSDN Q184796 together with an example.

    C / C++ / MFC c++ question visual-studio json help

  • CreateWaitableTimer is not creating
    J Joe Moldovan

    Forgot to mention: The MSDN example fails to compile also.

    C / C++ / MFC c++ question visual-studio json help

  • CreateWaitableTimer is not creating
    J Joe Moldovan

    I run VS6(SP5) on Win2000(SR2). I have a one line program which will not compile. #include windows.h int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ) { CreateWaitableTimer( NULL, TRUE, "JOE" ); return 0; } c:\develop\test\test.cpp(8) : error C2065: 'CreateWaitableTimer' : undeclared identifier To clarify the situation, I have no precompiled headers. The call definition is seen by VS because a mouse hover over the source shows the call prototype correctly. If I change windows.h to afxwin.h I get a good compile. QUESTION: Why can't I compile with windows.h? What has a Win32 API call got to do with MFC - or rather what does afxwin.h do that I don't? Thanks for any advice :rose: !

    C / C++ / MFC c++ question visual-studio json help

  • Archiving on CD
    J Joe Moldovan

    This is one of the best resources on the Net. Do you have any plans to archive the discussion threads on a CD or whatever. I am particularly interested in the C++ group. I am quite willing to pay for such a service and I imagine many others would too. Have Fun! Joe M.

    Site Bugs / Suggestions c++ discussion

  • Calculate a Checksum
    J Joe Moldovan

    Perhaps, BYTE checksum = 0; for ( int i = 0; i < 10; i++ ) { checksum += (BYTE)( data[ i ] ); } if ( checksum == 0 ) { good checksum } else { bad checksum } This means that one of your array values is a checksum value which makes the whole array add up to zero. PS: No one's English is perfect!

    C / C++ / MFC

  • Saving for the future
    J Joe Moldovan

    Because of the pace of work I get very little chance to look at this discussion group but it's one of the single most useful resorces on the Net and has never let me down. Does anyone know if there is any CD archive of the past threads or are there any plans to capture one. I would be willing to pay for such a service and I'm sure many others would be as well. I don't mean any fancy searchable database or anything like that - just a copy of the whole discussion group. It would be one of the most valuable resources for me. Have Fun!

    C / C++ / MFC database discussion

  • Single application instance
    J Joe Moldovan

    Great ideas but just as much work as my original. Pity that hInstance is not atomic across multi-cpu systems but that's asking a lot. Here is my solution for anyone who is interested. I don't think its very elegant but it works. At the beginning of xxxApp::InitInstance()look for an event. BOOL CTestApp::InitInstance() { // See if an instance of myself is already running if (( eDoIExist = OpenEvent( EVENT_ALL_ACCESS, NULL, "YesIExist" )) != NULL ) { // Yes. There is someone out there. Wake it up. SetEvent( eDoIExist ); // And get out return FALSE; } // No. I am the first so set up an event. eDoIExist = CreateEvent( NULL, TRUE, FALSE, "YesIExist" ); ..... Later in the init code when the main window (in my case a dialog) is ..... set up CTestDlg dlg; m_pMainWnd = &dlg; // Create a background thread to look for any other instance and send it // the main window ::CreateThread( NULL, 0, LookForMyself, m_pMainWnd , 0, NULL ); ..... At the end of the same source DWORD WINAPI LookForMyself( LPVOID lpParameter ) { // Forever do { WaitForSingleObject( eDoIExist, INFINITE ); // This is just a little flashy way of re-activating the running // instance ((CDialog *)lpParameter)->ShowWindow( SW_SHOWMINIMIZED ); ((CDialog *)lpParameter)->ShowWindow( SW_RESTORE ); // Reset and wait for more intruders ResetEvent( eDoIExist ); } while ( TRUE ); return 0; } Thank you all for your responses!

    C / C++ / MFC help question

  • Single application instance
    J Joe Moldovan

    Does anyone know of a simple way to ensure that an application has only a single instance running? When the app is clicked again the running instance should be restored and activated. I am doing all this now with an event and a background thread. It works fine but I seem to recall that there is a simpler way of doing this and I can't find it anywhere. Apropos, is it possible to send a windows message, like WM_SHOWWINDOW, between applications rather than within an application? By the way I have no problem getting the PID or the window handle if they are needed for the solution. Have Fun all.

    C / C++ / MFC help question

  • My registry won't register
    J Joe Moldovan

    You are an angel of mercy. It works!!! Thank you. (Lesson for others: Don't be stupid like me. Read the MSDN parameter doco very carefuly.)

    C / C++ / MFC sysadmin windows-admin help question

  • My registry won't register
    J Joe Moldovan

    Perhaps some kind soul out there can see what I'm doing wrong here: The following code tries to get some registry values. UCHAR ServerIP[ 16 ], ServerToPort[ 16 ], ServerFromPort[ 16 ]; UCHAR LocalIP[ 16 ], LocalToPort[ 16 ], LocalFromPort[ 16 ]; HKEY key1, key2; DWORD disp, type, size; LONG result; // Open the company key result = RegCreateKeyEx( HKEY_CURRENT_USER, "UHS", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key1, &disp ); // Open the Local subkey result = RegCreateKeyEx( key1, "Local", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp ); // Get the values of IP, InPort, OutPort result = RegQueryValueEx( key2, "IP", 0, &type, LocalIP, &size ); + result = RegQueryValueEx( key2, "ToPort", 0, &type, LocalToPort, &size ); + result = RegQueryValueEx( key2, "FromPort", 0, &type, LocalFromPort, &size ); // Open the Server subkey result = RegCreateKeyEx( key1, "Server", 0, "", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &key2, &disp ); // Get the values of IP, InPort, OutPort ? result = RegQueryValueEx( key2, "IP", 0, &type, ServerIP, &size ); result = RegQueryValueEx( key2, "ToPort", 0, &type, ServerToPort, &size ); result = RegQueryValueEx( key2, "FromPort", 0, &type, ServerFromPort, &size ); The registry entries are just IPs and port numbers and the editor shows they are OK. When the above code is run it fills in everything EXCEPT ServerIP. This call returns an error "234" which the ISDN helpfully identifies as "More data available". If I leave out the two calls marked with "+" the thing works and I get the ServerIP. I have tried to change the order of calling things but no matter what I do, one of the values returns an error. I have tried all kinds of other things like having individual key handles, flushing etc. but nothing works. My registry is not corrupt and I have tried this on two different machines in different offices. Hope someone knows what's happening.

    C / C++ / MFC sysadmin windows-admin help question
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups