Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

msvcirt.dll having a cow

Status
Not open for further replies.

Panthaur

IS-IT--Management
Jul 26, 2002
78
US
Hi All,

I'm having a really weird problem with a program I am working on. I have a program that runs fine 2-3 times, and anytime after that, it gives me one of the Windows XP Dialog box saying that it must shut down my program. The program in question is a console mode app which does a few things. It reads data from an INI file, it asks the user for some input, it reads and writes registry information, it communicates with a small robotic platform on the parallel port, and eventually writes out an INI file again.

What I seem to be narrowing the problem down to is that the program has no problems operating properly if I turn the registry reading and writing functions off, but if I turn them on, then when it comes to the following statement:

ofile.open("file.ini");

I get a lovely XP "PROGRAM HAS CAUSED A PROBLEM, WANT TO SEND A REPORT TO MS?". I looked in the detail section of that dialog box, and this is the information in the detail section:

Error signature:
AppName: foot_control.exe (the name of my console mode app)
AppVer: 0.0.0.0
ModName: msvcirt.dll
ModVer: 7.0.2600.0
Offset: 00004a65

That's how I know that it's something with msvcirt.dll. Now, if I reboot my computer, then run it, it will work 2-3 mores times, then continue screwing up again.

PLEASE HELP!

Thanks,
Panthaur
 
Is it an XP specific error?

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Unfortunately, I don't know. I haven't another computer to test it on.
 
In this case, I think, is a error in your program. Use debugger to see exactly what step does not execute and what are variable values at that moment. See what is exactly inside, and you still experiencing problems on fixing the piece of code with trouble, put there that piece.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Unfortunately, I have 2 problems there. #1 - I have no clue how to use the debugger in a c++ app. When I go into debug mode, it seems to be assembler codes, and I don't know how to read that. Problem number #2, I put a bunch of print statements in to trap where in the program it is screwing up, and it's at the line where it opens the INI file for output, which works fine if I disable the registry writing functions!??!?!
 
in this case your error is not in opening file but in manipulating registry. In my opinion you have errors on using registry functions.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I have 2 other programs modified to use this same functionality, and they work just fine. It seems to have something to do with writing a stream out to the file system.

 
Here are my registry functions. Did I do something wrong in them?

// the subroutine returns a value from a registry key
int GetMessage (char keyname[20], char keymessage[1000])
{
DWORD dwLastError = NO_ERROR;
HKEY hKey = NULL;

// open the registry key
dwLastError = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
TEXT("Software\\PCQ\\QTCOM"),
0,
KEY_QUERY_VALUE,
&hKey);

// if there is no error then query the registry key and get the value from it,
// then close the registry key
if (NO_ERROR == dwLastError) {
unsigned char buffer[_MAX_PATH];
unsigned long datatype;
unsigned long bufferlength = sizeof(buffer);

RegQueryValueEx(hKey, keyname, NULL, &datatype, buffer, &bufferlength);
RegCloseKey(hKey);

// copy the returned value from the key to the keymessage variable of this function
strcpy(keymessage, reinterpret_cast <CONST CHAR *>( buffer ));
}

return 0;
}

// this routine saves the message information to the registry
void SetMessage(char keyname[20], char keymessage[1000])
{
DWORD dwLastError = NO_ERROR;
HKEY hKey = NULL;

printf(&quot;%s - %s\n&quot;, keyname, keymessage);

// create an instance of the registry key
dwLastError = RegCreateKeyEx(
HKEY_LOCAL_MACHINE,
TEXT(&quot;Software\\PCQ\\QTCOM&quot;),
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS,
NULL,
&hKey,
NULL);

if (NO_ERROR != dwLastError)
{
printf(&quot;ERROR: RegCreateKeyEx failed with error code %d.\n&quot;, dwLastError);
}

// Add this new value to the registry key
dwLastError = RegSetValueEx(
hKey,
keyname,
0,
REG_SZ,
reinterpret_cast <CONST BYTE *>( keymessage ),
strlen(keymessage)+1);

if (NO_ERROR != dwLastError)
{
printf(&quot;ERROR: RegSetValueEx failed with error code %d.\n&quot;,dwLastError);
}

RegCloseKey(hKey);
}
 
>I have 2 other programs modified to use this same >functionality, and they work just fine.

It is a confirmation of what I said, you have an error in your program. Find it. When you find the error, fix it. If you can not, put the error in the forum and say what exactly the problem is.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
>have no clue how to use the debugger in a c++ app. When I go into debug mode, it seems to be assembler codes

We're talking about VC++, right?
Have you tried by setting a breakpoint before you run it? Are you doing a debug build?

/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
Sorry, I should re-iterate. I know how to use the debugger, but most of what I read is nonsense to me, and what it does do doesn't seem to help much with this problem anyway. I know where it is breaking, it dies at the:

ofile.open(&quot;file.ini&quot;);

point of the program. Does anyone see anything wrong with my registry functions?

Panthaur
 
maybe you have done something wrong weth ofile.
before:
ofile.open(&quot;file.ini&quot;);

try to put this:
if(ofile.bad())ofile.clear();
or just only:
ofile.clear();



Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I don't think there is anything wrong with ofile.open because it has been working successfully on 1000's of computers for the past 2 years. I only have a problem if I make use of the registry functions?!?!?

Panthaur
 
>I don't think....

you should not think. You should verify.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Ok, I will rephrase. ofile.open has been working perfectly for 2 years without any problems. The only time it screws up is when registry functions are used. Additionally, the ofile.open portion of the program was written by a VERY experience c++ program. The functionality that I am adding in has to do with the registry functions.

Panthaur
 
Ok, I will rephrase.
You should verify what are you adding.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
I know that. That's why I posted the code above. I need someone who knows c++ a whole lot better than me to look at my code and tell me if I have done anything wrong.

As far as I can tell, it's OK, but I DON'T KNOW!

Panthaur
 
>The only time it screws up is when registry functions are used

Good. You've probably tracked down the problem, or its location anyway...

Now, is there something looking fishy?

Well you do this:
Code:
      RegQueryValueEx(hKey, keyname, NULL, &datatype, buffer, &bufferlength);
        RegCloseKey(hKey);

        // copy the returned value from the key to the keymessage variable of this function
        strcpy(keymessage, reinterpret_cast <CONST CHAR *>( buffer ));

What would happen if you try to read more than your buffer can hold?
From MSDN:
&quot;If the buffer specified by lpData parameter is not large enough to hold the data, the function returns the value ERROR_MORE_DATA, and stores the required buffer size, in bytes, into the variable pointed to by lpcbData. In this case, the contents of the lpValue buffer are undefined&quot;

Perhaps that is not the problem, but I usually get suspicios at code that operates on undefined data...


/Per

if (typos) cout << &quot;My fingers are faster than my brain. Sorry for the typos.&quot;;
 
Hi,
1. Try ton run your program under the Dependency Walker for Win32 (Microsoft) and you get a lot of info about all dll that are used and how.
2. Two years ago I got malfunctioning application due to the msvcirt.dll. It is possible the msvcirt.dll file is not compatible with other dll that your program is unsing. This happens when you install other applications that install their ms*.dll files. Check also: msvcrt.dll msvcp60.dll.

3. Take a new machine.
Install there only the infrastructure (OS, dlls etc...) that your app needs to work.
Run the application.

-obislavu-
 
I was getting a little suspicious of the _MAX_PATH statment in the code, so I printf'd it and I get a value of 260, which is different than my keymessage length?!?! Is that what you are talking about?

Panthaur

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top