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
T

Tydia kun

@Tydia kun
About
Posts
20
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Broken code?
    T Tydia kun

    It's the whole point of MY overload operator =, I meant.

    C / C++ / MFC question debugging help tutorial

  • urgent :: how to break a character string into single characters?
    T Tydia kun

    The pointer is basically a pointer to an array of chars. You can simply loop through them one by one and print 7 chars, then print a new line. char* a = some_string; int length = strlen(a); while(length > 0) { for (int i = 0; i < 7; i++) { length--; cout << *a++; } cout << endl; }

    C / C++ / MFC tutorial question

  • how to create array of classes
    T Tydia kun

    SomeClass myClass[1000]; SomeClass* pMyClass = new SomeClass[2000]; Is that what you're asking for?

    C / C++ / MFC data-structures tutorial

  • Template overload of operator ++/--
    T Tydia kun

    I'd like to do an overlord of operator ++ and -- for my class with templates, like this: template<typename T> CValueHandler& operator ++ (); But the thing is, that while it compiles fine, I can't call that overloaded operator. SomeClass myClass; myClass++; Compiler simply complains it can't find a suitable overload. So, my question is, is it possible to overload ++/-- and use templates too? I can't seem to find a good place to fit in a template type either: SomeClass myClass; myClass<UINT64>++; Doesn't work either. Using Visual Studio 2005.

    C / C++ / MFC question csharp visual-studio wpf

  • How to copy file much faster?
    T Tydia kun

    Ah, of course. You're absolutely right. One thread can take care of copying and one thread can take care of everything else that needs to be done meanwhile... But then again, you don't need to use synchronus file copy either... You can asynchronous. While the file is copying, the program can do other stuff like readying more data copy or something, as long as it doesn't read or write to the same HD, since that would slow things down.

    C / C++ / MFC tutorial question learning

  • How to copy file much faster?
    T Tydia kun

    There's just one problem here. First and foremost, it depends on WHERE and TO you copy. The HD is far slower than the processor and memory, so the bottleneck is THERE. Copying two files (or more) from the same HD and to the same HD, then it will slow down the operation at least 2x. If the source and destination is different for each file, then yes, you can use threads. Otherwise you're just slowing down things.

    C / C++ / MFC tutorial question learning

  • Copying from unsigned char * to the CString
    T Tydia kun

    Does not surprise me that it gives you an access violation when doing that. The first and foremost rule to remember is: DO NOT USE MEMCPY ON CLASSES. Classes work independently, managing their own memory and so on. Therefore, you should use the exposed interfaces in the classes to do stuff. In this case, you're overwriting important data in the class, not to mention that the class's internal buffer is nowhere large enough to hold your data. As mentioned, use CString.GetBuffer(LengthOfBuffer). It returns a pointer to a buffer. Copy data using memcpy/CopyMemory. Then call CString.ReleaseBuffer(LengthOfData). That should do the trick.

    C / C++ / MFC help

  • Broken code?
    T Tydia kun

    That wouldn't work unless you overlord a operator = (CBuffer<int>) or simply make a template operator = such as template<typename T2> operator = (CBuffer<T2>). That way, the compiler can call the overloaded operator = and pass bufferOfInt to it with T2 = int. Memcpy is a very stupid (and dangerous) way of assigning a class to another class since classes are built around handling its own memory and variables. If you read about templates, then you know that you can specify a type for a template and the compiler will generate a function with that type when the template function is invoked. Take for example template<typename T2> operator = (CBuffer<T2>) When you do bufferOfString = bufferOfInt, it generates an overloaded function operator = (CBuffer<int>) And calls it. That's it.

    C / C++ / MFC question debugging help tutorial

  • Broken code?
    T Tydia kun

    Templates are templates - they can be of any type. That's why the overloaded assignment operator takes a new template type of T2. That's the power of templates.

    C / C++ / MFC question debugging help tutorial

  • Broken code?
    T Tydia kun

    Constant? As in non-template function? If that's the case, that's a no-go. I also added a return type of CBuffer& to return *this, so it should work with a=b=c now, I think.

    C / C++ / MFC question debugging help tutorial

  • Broken code?
    T Tydia kun

    Yes, they are and that's the whole point of the overloaded assignment operator (=). It takes a CBuffer of different type (or the same type) and copies the data from that buffer into its own buffer. But somehow the compiler didn't understand that.

    C / C++ / MFC question debugging help tutorial

  • Broken code?
    T Tydia kun

    What indeed? That it doesn't call the overloaded operator function is quite enough. Showing all the code would be pretty long and boring and irrelevant, so I'll show the important snippets of the declaration/definition of the variables and the class. template< class T1, class T2> long GetRegValuePtrNew(const char* strKey, const char* strName, CBuffer< T1> Buffer, /*bool bUseTempBuffer, */CBuffer< T2> RetBuf = (T2*)THROW_ERROR, DWORD* pType = NULL) throw(...) { ... Buffer = RetBuf; ... } template< typename T> class CBuffer { ... template< typename T2> void operator = (CBuffer< T2>& rBuffer); ... }; There's the basic declaration, so the obvious thing is that the compiler should generate code that calls CBuffer::operator =, but it doesn't, as you can see from the asm snippet I gave you. This is all the relevant parts of the code, but I can post the whole function/class if it's necessary. It's just that it would be so long. I also want to made it clear that I intentionally put spaces after a < since otherwise it's interpreted as HTML code and not shown. In REAL code I would NEVER do that, since I HATE it, it looks POOR. Just wanted to say that ;) EDIT: Actually, I seem to have fixed the problem. The problem was that the compiler was confused, but it still shouldn't have generated faulty code. It should complain, should it not? Consider this: As you saw above, the assignment operator takes a CBuffer of a DIFFERENT type than the type of the actual class (it takes T2 instead of T). In the above template, T1 and T2 = UINT64, the same type. Adding the following: void operator = (CBuffer& rBuffer); ...Fixes the problem. It seems the compiler gets confused and cannot interpret T2 as T (so if there's a var of CBuffer< UINT64>, the assignment operator can't take a CBuffer< UINT64> as argument, because it's the same type as the class type T). I got around it by adding an additional operator that takes the class's type T (CBuffer< T>) as argument and now it works. Of course, this shouldn't really be, AFAIK. Here is the new code: void operator = (CBuffer& rBuffer) { Assign(rBuffer); } template void operator = (CBuffer& rBuffer) { Assign(rBuffer); } template void Assign(CBuffer& rBuffer)... As plainly visible, both overloads call Assign, which takes a new template type T2 as argument, and both functions (well, I only tested the first, though) call the Assign fu

    C / C++ / MFC question debugging help tutorial

  • Broken code?
    T Tydia kun

    This really bothers me. See, I have a class and two variables of the same class, CBuffer, named Buffer and RetBuf. So, there's a line of code that says Buffer = RetBuf (class CBuffer has an overloaded operator = that takes another CBuffer& as argument). So even in debug, the compiler generates the following code: 004B1E48 mov eax,dword ptr [ebp+18h] 004B1E4B mov dword ptr [ebp+10h],eax 004B1E4E mov ecx,dword ptr [ebp+1Ch] 004B1E51 mov dword ptr [ebp+14h],ecx WHICH IS COMPLETELY WRONG! Does anyone know why this may happen and how to fix such a thing? I already tried a rebuild without success. All we long-time developers should know that unless there's an overload that takes a CBuffer& as argument, this operation is impossible. But there is one such overload, though, although the compiler does not generate code to call it, but instead perform pointer assigns! It's like it's thinking they're pointers, and therefore trying to assign the RetBuf pointer to the Buffer pointer, which again is not possible since there's no cast and they're different types! This boggles my mind! What IS the compiler doing?!

    C / C++ / MFC question debugging help tutorial

  • Converting audio to wav
    T Tydia kun

    I'm trying to find a solution to a little problem that involves being able to decode any type of media and save it into a wave-file. Of course, this is done through DirectShow. I've actually tried this, but it doesn't seem to work. I have a simple AVI-source, which I convert to matroska using mkvmerge. Anyway, the file contains a video tracks and a audio track (MP3). So I use Haali's Media Splitter, FFDShow, WavDest and File Writer, in that order. But the output audio file seems corrupted since it won't play! Connecting an audio rendered after FFDShow plays the audio perfectly fine and clear. I have no idea what can be wrong here, so if anyone has any idea or an alternative suggestion, please indulge me. Thanks.

    C / C++ / MFC help learning

  • Getting the process that owns the window
    T Tydia kun

    I really must have missed it or interpreted the message wrong. Thanks again. This non-linear way of showing posts in this forum really makes a mess out of things -_-

    C / C++ / MFC tutorial

  • Getting the process that owns the window
    T Tydia kun

    Yes, I have the hwnd. But as I mentioned, unless there's a way to get the process id or handle from a hwnd, I need to enumerate all processes and enumerate all their windows and compare those handles to the handle for the window I want to find, thus finding the owning process. Get me?

    C / C++ / MFC tutorial

  • Getting the process that owns the window
    T Tydia kun

    I have a window handle, but not a process id or process handle, because I don't know how to get either from a WINDOW handle. I know there's lots of functions and I've looked over them once or twice, but there's no function that returns a process id or handle from a window handle from what I can see.

    C / C++ / MFC tutorial

  • Getting the process that owns the window
    T Tydia kun

    Sure, I'll use it if there's no better way, but it's pretty much the same - get the handle and compare it to the process's handles, if I read correctly. There has to be a way to get a process handle from a window handle. A process must own that window, and it's possible to enumerate a process's windows, so why not the other way?

    C / C++ / MFC tutorial

  • Getting the process that owns the window
    T Tydia kun

    I've thought of getting the handle, then enumerating processes and trying to enumate windows for those processes and matching the handles, but that's seems just so far fetched. Isn't there an easier way?

    C / C++ / MFC tutorial

  • Getting the process that owns the window
    T Tydia kun

    Hi, I've been trying to figure out how to get the owner process or a window. Basically, I want to use GetForegroundWindow() to identify the current window that has focus and then be able to, from this, get the process that owns the window. It should be possible as it's the very same thing Task Manager does. If anyone knows how to do it, I'd be grateful. Thanks.

    C / C++ / MFC tutorial
  • Login

  • Don't have an account? Register

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