Hottest Forum Q&A on CodeGuru - November 3rd


Lots of hot topics are covered in the Discussion Forums on CodeGuru. If you missed the forums this week, you missed some interesting ways to solve a problem. Some of the hot topics this week include:

What is the difference between calling by pointer and calling by reference? (top)


avi123 knows that there are three common ways to pass a parameter to a function.

  • Calling by value
  • Calling by pointer
  • Calling by reference

But, he is not is not sure about the difference between the second and third options. Do you know? Actually, it's simple.

  • When calling by pointer, the value can be 0.
  • When calling by reference, the value must be valid.

But, if you are just passing an object, using a reference is better in terms of readability. As from the perspective of efficiency, both are the same. However, if you need to pass a pointer to an array of objects, there is no choice but to use a pointer. This is because the address stored by the reference cannot be modified after initialization.

How can I cast params together and pass them to a thread? (top)


Daviesrt needs to pass some parameters to a thread. Actually, it isn't a big problem. Right? But, besides that, he also wants to cast them and then pass them to the thread.

I am writing a thread to control a timer. I need to pass
"theEvent" and "theLock" to this thread, where "theEvent" and
"theLock" are
theEvent = new CEvent(FALSE,FALSE, "Something happened");
theLock  = new CSingleLock(theEvent);
How can I cast these together and pass them to the thread?
UINT StartClock(LPVOID pParam)
Is it possible??

Andreas Masur answered the question with a very nice, simple, and practical example code. Here is his answer:

Usually, you allocate the structure you wish to pass on the heap (thus, dynamically). Then, before the thread terminates, you would release the previously allocated memory. However, this might resolve in memory leaks if the thread function terminates unexpectedly (as when a function throws an exception, and so forth) because your 'delete' statement will not be processed in this case. To avoid this, you can use an auto pointer instead...

#include <memory>

struct MyStruct
  int m_Int;
  MyStruct(int i) { m_Int = i; }

// Create thread
MyStruct *pData = new MyStruct(10);
AfxBeginThread(MyThreadFunc, pData);
UINT MyThreadFunc(void *pvParam)
  std::auto_ptr<MyStruct> Struct(static_cast<MyStruct*>(pvParam));
  return 0;

The above code will not leak memory irregardless of how the thread function terminates...

How do I determine what error code is 0040e864? (top)


Ralf Schneider developed an application that works fine on his system. Besides that, he has also tested the application on different OSes, such as windows 95, OSR2, 98, and XP and it runs without any problems, but the application still crashes on the customer's system. Ralf is not able to reproduce the error. The only information he got is that his application causes the following exception.

  • MyProg cause an exception 10H in module MyProg.exe at 0137: 0040e864
Several users complain it crashed immediately on their machines
including windows 95, 95 OSR2, and 98. It says somthing like:
MyProg cause an exception 10H in module MyProg.exe at
0137: 0040e864

Stack dump:

I tested the software on my company's Windows 95, OSR2, 98, and XP
machines and it works fine. I just cannot reproduce those crashes,
and they are too far away for me to be on site. Does anyone have
a clue on how to debug this problem?

Basically, you'll need a MAP file to track the error code. Without having a mapfile, it's nearly impossible to determine the error. According to MSDN, the error occurs when an unmasked floating-point exception has signaled a previous instruction. Here is the snippet from MSDN KB 150314 What Are Fatal Exception errors:

16 (10h): Coprocessor Error Fault
This interrupt occurs when an unmasked floating-point exception has
signaled a previous instruction. ( Because the 80386 does not have
access to the Floating Point unit, it checks the ERROR\ pin to test
for this condition.) This is also triggered by a WAIT instruction
if the Emulate Math Coprocessor bit at CR0 is set.

So, the problem is a uninitialized float variable. Ralf confirmed that; he has sent a new version to his customer and now it runs!

How can I call a .dll with arguments? (top)


myth7676 needs to start a DLL with arguments. Huh, why would somebody need to do that? You have an EXE for that purpose.

I have a .dll, say test.dll and i want to call this .dll like:
test.dll /filename /start address.
The DLL should take the filename and start address as parameters
and do something with them inside. Can this be done?

The only solution I know would be to export functions from an EXE and call them as if the EXE were a DLL.

What is the maximum size of a structure that can be defined in VC++? (top)


Varadha has defined a structure in his application. But, when he starts the application, it crashes with an unhandled Exception. His first thought is that there may be a maximum size for a structure.

When i define the following structure.
typedef struct summa
  int a;
  int b;
  char c[1062144];
and run the application, I get the following error.
Unhandled Exception: ..... Stack Overflow.
Is there a constraint on the maximum size of the Structure that
can be defined in VC++?

The exception appears because it's too big for the stack. You could allocate it with new and put it on the heap instead. Or, you could increase the size of your stack in the linker options. Or, you could use a std::string or std::vector<char> as a structure member that essentially puts that memory on the heap.

About the Author

Sonu Kapoor

Sonu Kapoor is an ASP.NET MVP and MCAD. He is the owner of the popular .net website DotNetSlackers publishs the latest .net news and articles - it contains forums and blogs as well. His blog can be seen at:


  • There are no comments yet. Be the first to comment!

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Live Event Date: October 29, 2014 @ 11:00 a.m. ET / 8:00 a.m. PT Are you interested in building a cognitive application using the power of IBM Watson? Need a platform that provides speed and ease for rapidly deploying this application? Join Chris Madison, Watson Solution Architect, as he walks through the process of building a Watson powered application on IBM Bluemix. Chris will talk about the new Watson Services just released on IBM bluemix, but more importantly he will do a step by step cognitive …

  • Managing your company's financials is the backbone of your business and is vital to the long-term health and viability of your company. To continue applying the necessary financial rigor to support rapid growth, the accounting department needs the right tools to most efficiently do their job. Read this white paper to understand the 10 essentials of a complete financial management system and how the right solution can help you keep up with the rapidly changing business world.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds