21 Years, 1 Month :omg:
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
21 Years, 1 Month :omg:
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Internally it's just continuous memory that is allocated for a 2 dimensional array (For any no. of dimensions for that matter). The compiler uses the specified dimensions to calculate the offset into the memory to fetch. For instance, offset of Chart[2][3]
could be calculated as -
(sizeof(ChartNode) * MAXROW * 2) + (sizeof(ChartNode) * 3)
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
As others have pointed out, the issue is with pBuffer
not associated with any allocated memory. In addition to this, I would like to point out one more flaw in your code, although it doesn't matter in this case. The third parameter to SetFilePointer[^] must be an address of a LONG
variable. PLONG
does not declare a LONG
variable. It's only a pointer to a LONG
variable. Here SetFilePointer
will actually try to write to memory 0
. What you need to do is declare a LONG
variable and provide its address -
LONG highValue; SetFilePointer(..., ..., &highValue, ...);
You can also pass a nullptr
, if you're not intersted in that value.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Since the value of SIZE
is constant and the same for all instances of the class, I suggest it be made a static const
. That way you wouldn't need to assign a value to it in the assignment operator overload.
static const int SIZE = <value>;
The first thing that came to mind is to search for g_iNum
in the entire code base and put breakpoints where ever it is being accessed. ;P
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Since the tasks are not waiting on any object or variable, there will be no dead lock. I guess you do need to add if (rcvd == false)
in task B before the line rcvd = true;
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Will need to look at the destructor code. Since you're returning temporary objects, you could try changing the function signature to WorkPackage**&&** PackageQueue::GetWorkPackage
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Now I get it - Edge Computing
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
:laugh:
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
This is a COM (Component Object Model) thing. Basically the COM runtime takes type library information embedded in the COM DLL and creates headers and helper methods including some exception handling so that client C++ programs can call into the DLL.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
There are some great articles here on CodeProject - Tree Controls[^] Be sure to pick the ones written in C++.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
The most basic thing to do for your need is to handle the WM_NCHITTEST[^] message. The LPARAM
parameter gives you the mouse coordinates on your window and then you figure out if it is over your customized title bar and return HTCAPTION
from the message handler. You may also want to check when to return HTCLOSE
, HTMAXBUTTON
, HTMINBUTTON
, HTSYSMENU
etc.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
What you basically need to do is to sort the array in descending order. There are several sorting algorithms. This the first google search link I found for sorting - Sorting Arrays[^] Go through them, try them and understand them.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
The documentation for GetTickCount64
says to include windows.h - https://msdn.microsoft.com/en-us/ms724411[^] When searching for the method declaration, I was able to find it in a file called sysinfoapi.h
This file is part of the Windows SDK. On my machine I have 2 SDKs available and so 2 copies of sysinfoapi.h
C:\Program Files (x86)\Windows Kits\10\Include\10.0.15063.0\um\sysinfoapi.h
C:\Program Files (x86)\Windows Kits\8.1\Include\um\sysinfoapi.h
Try compiling after downloading and installing the SDK from here - https://developer.microsoft.com/en-us/windows/downloads/windows-8-1-sdk[^]
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
One more thing that I would like to add is that you should initialize variable i
to 0
.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
You could use a structure as below -
struct TreeNode
{
int i;
CString str;
std::vector children;
};
Create one instance of TreeNode
that would be the root. The root can then have children who can have children etc. You could use std::string
or std::wstring
instead of CString
. You can use the push_back
or emplace_back
methods to add children.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
As Richard said, the expression only contains integers and so you should get the result of an integer division (3). However, if at least one of the operands / variables are of float type, all integers will be automatically converted to float type. Say, for example - y = (float)17 / 5;
Having said this, the answer may be slightly different from the expected 3.4 because of how floating point numbers are represented. Please check this - Floating point inaccuracy examples - Stack Overflow[^]
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
It's possible that the compiler patches the call with a default argument. What is the value in channel? I'm guessing it is 0. Anyway this is not valid in standard C and will surely not compile in GCC or Microsoft C compilers.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
To open a handle to a USB device, you have to use the SetupDixxx APIs to enumerate and find the device. Here is an example for enumerating USB devices - http://www.velleman.eu/images/tmp/usbfind.c[^] Once the correct VID/PID pair is found, you can use the DevIntfDetailData->DevicePath
in a call to CreateFile
.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)
Move the memory allocation to a class of its own so that the new happens in its constructor and delete happens in its destructor. That should be the only responsibility of the allocating class. In the class whos constructor throws, create an object of the allocating class on the stack. Since destructors are only called for objects that are fully constructed, the allocating class destructor is always guaranteed to be called.
«_Superman_» _I love work. It gives me something to do between weekends.
_Microsoft MVP (Visual C++) (October 2009 - September 2013)