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
X

x87Bliss

@x87Bliss
About
Posts
34
Topics
14
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • try-catch dynamic memory cleanup
    X x87Bliss

    Thanks very much for the descriptive information. The example code is an excellent solution for my problem. I really appreciate you taking the time to answer that thoroughly.

    C / C++ / MFC performance help tutorial question

  • try-catch dynamic memory cleanup
    X x87Bliss

    I am somewhat familiar with a try-catch block and that it automatically destructs objects on exception. However, I'm curious if it automatically frees dynamically allocated memory from the "new" operator?

    void failfunc()
    {
    throw 1; // obviously not practical, just for example
    }

    void main()
    {
    try
    {
    char *mystr = new char[512]; // something in the try block determines the size needed, so must be allocated in the try block
    failfunc(); // would normally actually do something
    delete [] mystr;
    }
    catch (int ierr)
    {
    //tell user an error occured
    if (mystr != NULL) delete [] mystr; // is this line needed, or will the exception have freed mystr?
    }
    }

    C / C++ / MFC performance help tutorial question

  • CWinThread - How to ask is still running?
    X x87Bliss

    My progress dialog creates a worker thread using AfxBeginThread. When the user clicks cancel, I don't want the window to close if the thread is still running. I want to have the thread safely finish first. There is a BOOL variable that the worker thread checks on occasion while running. If this is true, it begins to cancel. The worker thread only reads this variable, the Progress Dialog writes to it if needed. Should the worker thread be suspended before this variable is written? Or will it be OK since they will never Write at the same time. Secondly, and most importantly, I currently have the Worker Thread Post a WM_USER message, with certain WPARAM and LPARAM for the reason, when it has ended. Is there any other way to check if the thread is running or not, and what the controlling function's return value was? Thanks

    C / C++ / MFC tutorial question

  • URLDownloadToCacheFile problem - possible workarounds?
    X x87Bliss

    My program needs to download a file off the internet to get some information needed to continue. It does not need to save the information, just needs to read it once for the next step. I have tried

    CString TempFile;
    URLDownloadToCacheFile(NULL, _T("http://validurl/script.cfm?key=value"), TempFile.GetBufferSetLength(MAX_PATH), MAX_PATH, validcallback);

    Once those lines run, TempFile gets filled with a valid path to a temporary file, but the file doesn't actually exist - therefore I can't open it. The following code is what I'm using now, and it works. But I don't like it because it has a hard-coded temporary filename (therefore multiple instances may conflict).

    CString TempFile;
    TempFile.GetEnvironmentVariable(_(T"TEMP"));
    TempFile.Appened(_T("\\MyProg.tmp"));
    URLDownloadToFile(NULL, _T("sameurlasabove"), TempFile, validcallback);

    After those lines run, the file is created and contains the needed information. But again, it uses a hardcoded temp file, therefore multiple instances cannot run. So now for the questions: First of all, is URLDownloadToCacheFile failing because it's a text file generated by a script, and not a binary data file (like a jpg), therefore it doesn't cache it? Second, what is more practical in this situation. Would you implement code to generate a "random" temporary filename that's not in use? Or should I write code that can read the file right off the internet without saving it to disk first? I don't want to shoot a fly with a cannon, but I'm not sure which is the cannon.

    C / C++ / MFC question tools help lounge

  • Convert from TCHAR* to char*
    X x87Bliss

    Thanks. Sorry, I apparently am not good at searching; I could only find the functions for WCHAR and char, not TCHAR. Those macros are perfect.

    C / C++ / MFC

  • Convert from TCHAR* to char*
    X x87Bliss

    I am writing an application that communicates with an external device. I need to copy a CString (TCHAR*) to a multibyte string buffer (char*) - the catch is I need the code to be able to compile with UNICODE on or off. Basically I need a function that can copy either a WCHAR* or char* to a char*. Currently I have:

    CString szVal = _T("Some User Input String"); // i.e. not always the same value
    char* Buf;
    size_t BufLen;
    #ifdef UNICODE
    wcstombs_s(&szBufLen, NULL, NULL, szVal, _TRUNCATE); // get the req'd length including NULL
    szBuf = new char[szBufLen];
    wcstombs_s(&szBufLen, szBuf, szBufLen, szVal, _TRUNCATE); // convert and copy
    #else
    szBuf = new char[szVal.GetLength() + 1];
    strcpy(szBuf, szVal);
    #endif
    // more code
    delete [] szBuf;

    The above works, but I would prefer not having to use the preprocessor directives if posssible. The function _tcscpy will not convert from WCHAR to char when needed. I know I can easily write my own overloaded function, but I was hoping there was already a function defined.

    C / C++ / MFC

  • Another question on "Good Practices" involving code file size...
    X x87Bliss

    Thanks :-D That's some of the most useful info I've seen. The F12 will definitely come in handy.

    C / C++ / MFC question csharp c++ visual-studio tutorial

  • Font / Background theme (settings export) that's easier on the eyes.
    X x87Bliss

    I wanted to know where I could find a good theme for Visual Studio 2008 that has a black background with colored text. It'd be much easier on the eyes. I have found one by the name "Vibrant Inks" or something. However, I am not too fond with the text color choices. And it actually makes it worse since only the text editor's background changes, which makes the bright contrast of the surrounding controls (solution explorer, etc..) more prevalent. Are there settings that can be changed inside of Visual Studio to address this? Or is it something that would have to be done at the OS level? (I have Win Vista 32b) Thanks for any info.

    Visual Studio csharp visual-studio question

  • Another question on "Good Practices" involving code file size...
    X x87Bliss

    Besides just making classes for specific functionality, I also decided to start using '#pragma region' directives; so I can collapse groups of functions together. It's been very useful. I barely know anything about pragma statements. In my case I don't have to worry about it, since I will be using Visual Studio always to compile this. I am just wondering what would happen if a different compiler saw '#pragma region' if it'd skip over it, or have an error?

    C / C++ / MFC question csharp c++ visual-studio tutorial

  • Another question on "Good Practices" involving code file size...
    X x87Bliss

    My application has a main window that provides most of the functionality. The window itself is nice and clean, and very user friendly IMO. However, the class CPP file for it is growing large and hard to navigate (I have to use Ctrl+F to find most functions). The reason for this is there are a lot of possible interactions the user can have with the interface, each having a unique function. The .cpp file is currently 24kb (845 lines including whitespace); which is a lot for me, I usually don't write large programs. I want to try to keep the code organized, and I'd like to know some good practices for doing this. (If I become a programmer as a job, I want to know how to make the code "presentable" and not just a mess.) Is it just a matter of trying to keep the functions sorted in groups (i.e. everything having to do with interaction of the list control together, then everything with the media player together, etc.. etc..) Or is there more that I can do to try to keep it organized? Lastly, Visual Studio 2008 defaults to making wizard generated message handlers public. I would think that they should be protected in most cases. Is there a convention here that I'm not aware of, or should I indeed move the ones that other classes shouldn't be calling to protected? Thanks again for any info!

    C / C++ / MFC question csharp c++ visual-studio tutorial

  • Creating a linked list; need to know good practices.
    X x87Bliss

    I'm creating a linked list that stores two strings in each node. I quickly drafted the code as: struct SongInfo { CString Title; CString Address; SongInfo* next; }; void CreateList() { // not an actual function, just to illustrate my allocation ... if (bINeedAnother) { cur->next = new SongInfo; cur = cur->next; } ... } I am using CStrings since the length of the strings is unknown. However, since once they are initialized they don't change, I am thinking I should change it to dynamically allocated WCHAR pointers, with the appropriate length for each string. Or is there another practice that would be better? The other question is on the allocation of the nodes. The number of nodes can be as few as 10, and I've seen as much as 300. Is it a bad idea to allocate one node at a time (i.e. can I rely on Windows to keep the memory unfragmented)? If so, what is a good practice here? (Sorry for the noobish questions, my programming professor sucked, and her linked lists ALWAYS crashed, and she ALWAYS blamed the OS.)

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

  • Can you make an MCIWnd a child to the main window, but run in a seperate thread?
    X x87Bliss

    My MFC application consists of one main dialog, and it has an MCIWnd control created at the bottom for simple media playing functionality. I currently use MCIWndCreate in the main window's OnInitDialog function, creating it as a child window. Most of the media it plays is streamed from the internet. This creates a problem when the user seeks in the MCIWnd, and it has to access the internet for more data. The MCIWnd freezes the whole app until it is able to resume playing (once it finished downloading more data). Usually it only takes a few seconds; however, it tends to be bothersome still. I was wondering if there was a way to create the MCIWnd as a child of the main window, but have all of its functionality run in a seperate thread, so that the main thread can continue uninterupted while MCIWnd downloads its data. Thanks for reading the lengthy post and providing any help. :)

    C / C++ / MFC help c++ question career

  • LPT I/O Port Access in Vista [modified]
    X x87Bliss

    Thank you all for your info and security concerns. This is just a personal program, I am not designing it for public release. I only allow TotalIO to run during the timeframe that I need it. I will have to give GiveIO a try, since that should be much more secure, thanks for that tip. And Steve's info on the allowed port range also clears it up: "up to about 0xf00". As my LPT port is on port 0xCD00 - thanks to the add-on card. It's no wonder TotalIO "isn't doing it's job" if you will. Again, thank you all. TotalIO's failure, and your comments, is like a wake-up call to stop doing the I/O the quick and dirty way.

    C / C++ / MFC help question

  • LPT I/O Port Access in Vista [modified]
    X x87Bliss

    I used to use the LPT port in a program in Windows XP. In order to get access to the port, I used TotalIO. Now I am using Windows Vista 32-bit, but I can't get TotalIO to work. It says the service is loaded successfully, but I still do not get access to the x86 assembly in and out instructions. I still get the priveledged instruction error. I have even tried running as Admininstrator with XP compatibility. Has anyone had any success with getting port access in Vista that has any tips? Please note: I want to avoid using inpout32.dll; although if it is the only option I will. The reason is, in my experience, TotalIO is MUCH MUCH faster than inpout32.dll.

    modified on Thursday, February 7, 2008 9:03 PM

    C / C++ / MFC help question

  • C++ Quick Filespace Allocation
    X x87Bliss

    I generally use what MSDN calls CRT lowlevel file I/O functions. These are the ones defined in io.h and fcntl.h; open, lseeki64, telli64, close, etc... There doesn't seem to be a function to allocate filespace quickly. For this example I would want to create a 10MB file. If I write 10485760 \0's to the file, it will obviously make the file 10MB - however it is slow (well for LARGE files). I did experiment by using the following code on winvista 32-bit. char c = 0; int newfile = open("newfile", _O_WRONLY | _O_BINARY | _O_TRUNC | _O_CREAT, _S_IREAD | _S_IWRITE); lseeki64(newfile, 10485759, SEEK_SET); //seek 1 byte short of 10MB write(newfile, &c, 1); //write \0 at this 10MB position. close(newfile); This seemed to do the trick, and the resulting 10MB file was \0 filled. However, I didn't think you were allowed to seek past the end of a file with lseek. Is this behavior expected to work on all OSs, or will some have an error with the seek? Is there any better way to do it? Basically what I am trying to accomplish is telling the OS that I am going to need X amount of disk space BEFORE I start writing the actual data, without taking up much time. The files are usually around 8GB, but may be even larger than that. My goal is to minimize fragmentation and the possibility of running out of disk space unexpectedly in the middle of writing to the file. Finally, the contents of the allocated file are unimportant and don't have to be \0 filled (i.e. garbage is ok), but will this way or an alternative guarantee \0 filling?

    C / C++ / MFC c++ help tutorial question

  • CRichEditCtrl problem
    X x87Bliss

    Have you tried SetSel to move the caret to the end of the text, so this way it doesn't have to scroll it into position. SetSel, I think that's the name, should take 2 parameters, the first selected character and the last selected character. If they are the same, then it just moves the caret to that position. Should be something like... int Length = GetLength(); SetSel(Length, Length); SetSel may even have a third bool parameter too that tells it whether to scroll to the newly selected text. Using SetSel and telling it to scroll to the newly selected text may even fix the other scrolling problem. Good Luck.

    C / C++ / MFC help tutorial question lounge

  • CRichEditCtrl problem
    X x87Bliss

    It should only flicker as you're resizing, which shouldn't be that big of a deal? If it's flickering all time you probably have the scrolling code in the wrong place. A lot of controls flicker during resize AFAIK. You should be able to search up ways around that. I think it involves drawing the dialog off-screen and then repainting it on-screen, like a double buffer. I'm sure there are other ways too. I just know that you'll be able to find something.

    C / C++ / MFC help tutorial question lounge

  • CRichEditCtrl problem
    X x87Bliss

    I recreated the problem in Wordpad, as you mentioned before, and created a program to send window messages to it to fix it. And this is what worked for me. You can send these messages from within your own program where necessary. I only made a seperate app, because I couldn't just rewrite wordpad :-P

    ::SendMessage(HandleOfRichEditControl, WM_VSCROLL, SB_LINEDOWN, 0);
    ::SendMessage(HandleOfRichEditControl, WM_VSCROLL, SB_ENDSCROLL, 0);

    The one with ENDSCROLL may not be needed, but it is sent after LINEDOWN when I press the down arrow on the scroll bar. So it may be needed for more accurate emulation of the user pressing it. Who knows.

    C / C++ / MFC help tutorial question lounge

  • Custom Window Messages
    X x87Bliss

    how can you make an app be able to send and recieve custom window messages between the windows (or even between two applications assuming you have the appropriate window handle) Can you just use a integer in the Message parameter that isn't already used? If so, what are the ranges of unused window message values? Or do you have to do special code to "register" or w/e the custom window message? Thanks

    C / C++ / MFC question

  • How to change other program's resource at runtime
    X x87Bliss

    I don't believe there are any functions that will allow you to change an images resources in memory. If you're doing a simple replacement, like replacing one bitmap with another, if they are the same size, you can use WriteProcessMemory(...) You can find a whole section in MSDN about the debugging functions. You'll have to find out the memory address of the resource. If you're trying to do more advanced resource changing operations, you're stuck with having to edit the image file; unless you probably do a LOT of work of modifying the PE header and allocating more memory and such, I don't even know if it is technically possible. What kind of resource are you trying to change, and if possible, why? It may be better to come up with a different solution.

    C / C++ / MFC csharp design tutorial question learning
  • Login

  • Don't have an account? Register

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