Strange memory access error after calling dll

Discussion in 'C++' started by Mongoose7, Mar 8, 2006.

  1. Mongoose7

    Mongoose7 Guest

    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<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> >
    >::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
     
    Mongoose7, Mar 8, 2006
    #1
    1. Advertising

  2. Mongoose7

    Ben Pope Guest

    Mongoose7 wrote:
    > 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<char,StrTraitMFC<char,ATL::ChTraitsCRT<char> >
    >> ::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
    --
    I'm not just a number. To many, I'm known as a string...
     
    Ben Pope, Mar 8, 2006
    #2
    1. Advertising

  3. Mongoose7

    Kaz Kylheku Guest

    Mongoose7 wrote:
    > 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
     
    Kaz Kylheku, Mar 8, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anushi
    Replies:
    5
    Views:
    8,996
  2. Weston Fryatt
    Replies:
    2
    Views:
    1,035
    Weston Fryatt
    Jan 1, 2005
  3. Capsule

    calling c# dll from c++ dll

    Capsule, Oct 18, 2005, in forum: C++
    Replies:
    3
    Views:
    995
    Victor Bazarov
    Oct 18, 2005
  4. Pradeep
    Replies:
    2
    Views:
    260
    mlimber
    Jul 23, 2008
  5. H. Simpson
    Replies:
    4
    Views:
    342
    H. Simpson
    Aug 3, 2004
Loading...

Share This Page