Strange memory access error after calling dll

M

Mongoose7

Hi,

I am using vc7 to call a dll function from another dll. The function
seems to execute correctly (it writes binary data to the registry) but
when it comes out of the function, and tries to execute a standard
windows debug trace (or any other line of code for that matter, I tried
replacing the debug line with) it crashes giving a first chance
exception, and then a access violation. I have a feeling that this has
something to do with the target dll being called, though I am not sure
what.

Below is the debug disassembly.

if (_ProfileRegistryWriteBinary( HKEY_CURRENT_USER, szSubKey,
sKey, pDataOut.cbData, pDataOut.pbData )) // Local stub to the dll
method.
0475132D mov eax,dword ptr [ebp-18h]
04751330 push eax
04751331 mov ecx,dword ptr [pDataOut]
04751334 push ecx
04751335 mov edx,dword ptr [sKey]
04751338 push edx
04751339 mov eax,dword ptr [szSubKey]
0475133C push eax
0475133D push 80000001h
04751342 call _ProfileRegistryWriteBinary (47515D0h)
04751347 add esp,14h
0475134A movzx ecx,al
0475134D test ecx,ecx
0475134F je _StorePrivateData+118h (4751378h)
{
debug ("Private data has been written successfully :)");
04751351 push ecx
04751352 mov ecx,esp

/*****************************************************************
04751354 mov dword ptr [ebp-118h],esp <- Crashes on this line
*****************************************************************/

0475135A push offset string "Private data has been written
su"... (4815D04h)
0475135F call
ATL::CStringT said:
::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > > (4751710h)
04751364 mov dword ptr [ebp-144h],eax
0475136A call debug (4751450h)
0475136F add esp,4
bRetval = true;
04751372 mov byte ptr [bRetval],1
}

Thanks a Lot!

Mongoose7
 
B

Ben Pope

Mongoose7 said:
Hi,

I am using vc7 to call a dll function from another dll. The function
seems to execute correctly (it writes binary data to the registry) but
when it comes out of the function, and tries to execute a standard
windows debug trace (or any other line of code for that matter, I tried
replacing the debug line with) it crashes giving a first chance
exception, and then a access violation. I have a feeling that this has
something to do with the target dll being called, though I am not sure
what.

Below is the debug disassembly.

if (_ProfileRegistryWriteBinary( HKEY_CURRENT_USER, szSubKey,
sKey, pDataOut.cbData, pDataOut.pbData )) // Local stub to the dll
method.
0475132D mov eax,dword ptr [ebp-18h]
04751330 push eax
04751331 mov ecx,dword ptr [pDataOut]
04751334 push ecx
04751335 mov edx,dword ptr [sKey]
04751338 push edx
04751339 mov eax,dword ptr [szSubKey]
0475133C push eax
0475133D push 80000001h
04751342 call _ProfileRegistryWriteBinary (47515D0h)
04751347 add esp,14h
0475134A movzx ecx,al
0475134D test ecx,ecx
0475134F je _StorePrivateData+118h (4751378h)
{
debug ("Private data has been written successfully :)");
04751351 push ecx
04751352 mov ecx,esp

/*****************************************************************
04751354 mov dword ptr [ebp-118h],esp <- Crashes on this line
*****************************************************************/

0475135A push offset string "Private data has been written
su"... (4815D04h)
0475135F call
ATL::CStringT said:
::CStringT<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> > > (4751710h)
04751364 mov dword ptr [ebp-144h],eax
0475136A call debug (4751450h)
0475136F add esp,4
bRetval = true;
04751372 mov byte ptr [bRetval],1
}

Thanks a Lot!

Mongoose7

Could be anything, but I suspect one of your char* are invalid, probably
not pointing to an array of char long enough to hold the result, or not
pointing to anything at all.

In case you hadn't noticed, this is a C++ language group, not a VC7,
Windows, or assembler group. As such 99% of your post is off topic.

Try posting your C++ code to a relevant newsgroup, probably something in
the microsoft.public. hierarchy.

Ben Pope
 
K

Kaz Kylheku

Mongoose7 said:
Hi,

I am using vc7 to call a dll function from another dll.

Off topic. This has nothing to do with C++, but with Windows
architectural issues.
The function
seems to execute correctly (it writes binary data to the registry) but
when it comes out of the function, and tries to execute a standard
windows debug trace (or any other line of code for that matter, I tried
replacing the debug line with) it crashes giving a first chance
exception, and then a access violation.

Perhaps the calling conventions are wrong.
/*****************************************************************
04751354 mov dword ptr [ebp-118h],esp <- Crashes on this line
*****************************************************************/

Perhaps the function clobbered the EBP register (frame pointer) but did
not restore it.

Maybe that could happen in code that is compiled to not use frame
pointers for stack frame linkage, freeing that register for general
use. .

Or an EBP value was restored, but from corrupt memory.

Anyway, the newsgroup you want is

microsoft.public.win32.programmer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top