GuidesHottest Forum Q&A on CodeGuru - January 19th

Hottest Forum Q&A on CodeGuru – January 19th content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.


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:

Why do get I compiler error C2065 when compiling my VC++ 6.0 project in VC7?


tiff, a junior member, converted his project from VC++ 6.0 to VC7 and got compiler error 2065. He accepted all default conversions from VC7, but it still does not work. What can be done here?

When I convert a Visual C++ 6.0 project to Visual C++ .NET by
opening the project using .NET environment, and accepting all VC 7.0
conversion defaults, the new project would not compile, and gives
this error:
Compiler error C2065: '_mbstowcsz': undeclared identifier.
This functions compiles ok on VC++ 6.0.

Because VC++6.0 and VC++.NET put this function in different
locations, I did change the included path, and made it use Dynamic
ATL because in VC++.NET this function is in atlmfc/include. But
nothing works.

So, guys, do you know why this does not work? This question is again for you. Can you answer it? If yes, e-mail me and I will publish the answer in next week’s column.

Should I call destroywindow before deleting an object?


brraj is curious whether he should call DestroyWindow() prior deleting the object. Do you know whether this is correct or not?

I have a CEdit *m_pEdit pointer; it will be dynamically created
by using the new and create functions and deleted by using delete.
My question is before deleting should we call the DestroyWindow
function? For example:
delete m_pEdit;
m_pEdit = 0;
Is the destroywindow necessary?
My senior says that window will not be destroyed if I don't call

Well, your senior is correct. You will need to call DestroyWindow() before calling delete. Any class derived from CWnd will call DestroyWindow from its destructor. But remember, if you derive your own class from a CWnd-derived class, and you override the function, you will need to call DestroyWindow explicitly in your own code.

Where is the error log?


paraglidersd is working on a project that is nearly finished. But, he still gets an error in which he needs the error log on the system. Unfortunately, he is not able to find the log. Do you know where such a log file is located?

I am running an Visual C++ application on a laptop that does not 
have Visual Studio installed. I (obviously) created the application
on a different machine. This application is a simple Win32
application with no interactive windows. It merely runs (after
double-clicking it) and waits for information to come across a
serial port. It has some threading.

The error I am receiving is "Application-so-and-so has generated
errors and will be closed by Windows. You will need to restart the
program. An error log is being created."

I cannot find the error log anywhere on my system. I dont even know
what the name of the log file would be. I couldn't find anything on
MSDN. Help? I am on a deadline and am pulling my hair out.

The error log could be the Dr. Watson Log. Enter DRWTSN32 in START/RUN. Also, check that you have the correct version of the DLLs on your laptop. These are the DLLs required on the laptop:


An another option is to debug your application remotely.

After suggesting all that, paraglidersd found the solution on his own. The program used a logging function that inherited from another code. The error was in the logic of the code.

How do I search for keys using wildcards in a map?


Aks82 is working with maps where he needs to search for wildcards. Is it possible?

I am planning to create a map for my given data set. I was
wondering whether there is a way to search for keys by using regular
expressions. Basically, if the user forgets the key, can s/he search
for the key using wildcards?

Fr example, if HostID is one such key, is there a way I can search
for all keys that begin with 'Host' as 'Host*' or something?

I know that the find() method allows one to search for the key as an
exact expression. But my tool needs to be able to search for the
'keys' using regular expressions.

Unfortunately, there isn’t any function to search for wildcards. But, to get the desired result, you can use the std::lower_bound() function. Here is how it might look:

#include <iostream>
#include <map>
#include <string>

using namespace std;

typedef std::pair<string,int> PAIR;

int main()
    map<string,int> my_map;
    my_map.insert( PAIR("Server1",1) );
    my_map.insert( PAIR("Host3",3) );
    my_map.insert( PAIR("Server2",2) );
    my_map.insert( PAIR("Host1",1) );
    my_map.insert( PAIR("Something Else",6) );
    my_map.insert( PAIR("Host2",2) );
    my_map.insert( PAIR("guest",44) );
    my_map.insert( PAIR("HostID",32) );

    // find all entries that start with "Host"

    string str_to_find = "Host";
    int nLength = str_to_find.length();

    map<string,int>::iterator it = my_map.lower_bound("Host");

    while (it != my_map.end())
        if (it->first.substr(0,nLength) != str_to_find) break;

        cout << it->first << " " << ;it->second << endl;

    return 0;

How can I use a *void -> *short in printf?


yiannakop asked a very interesting question.

Hi everyone. Suppose I have the following code:
void *var;
int c;       // c given by user...
switch (c)
  case 1:
     var = (short*)malloc(sizeof(short));
     printf("content of var: %dn",*(short*)var);
  case 2:    // same for float
The above program works fine with all types (int, float, double),
but not for short. I suppose %d for shorts is not right under
Solaris 5.7?

The following code should work:


Microsoft says that %h is a MS-specific extension. Orginally quote from MSDN:

“The optional prefixes to type, h, l, and L, specify the .size. of argument (long or short, single-byte character or wide character, depending upon the type specifier that they modify). These type-specifier prefixes are used with type characters in printf functions or wprintf functions to specify interpretation of arguments, as shown in the following table. These prefixes are Microsoft extensions and are not ANSI-compatible.”

But, the C99 standard also contains this extension. Take a look at the whole thread to learn more about this topic.

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories