Re: Pointer corruption calling across a DLL boundary

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Doug Harrison [MVP] (dsh_at_mvps.org)
Date: 03/08/04


Date: Mon, 08 Mar 2004 17:43:31 -0600

Nick Bishop wrote:

>"Feng Yuan [MSFT]" <fyuan@online.microsoft.com> wrote in message news:<eh$6GyYAEHA.752@TK2MSFTNGP09.phx.gbl>...
>> Make sure they are compiled using the same compile option. One thing could
>> be wrong is struct packing.
>>
>> This kind of problem could normally be figured out easily by stepping throug
>> in assembly code.
>
>and we also got this answer.
>
>> There's no difference. Maybe the compiler or linker chokes on
>> exported array variables. Try char** instead of char*[].

Except in function parameter declarations, there's a huge difference between
char** and char*[], which respectively declare a pointer to a pointer and an
array of indeterminate size of pointers. In the array to pointer conversion,
char*[whatever] is converted to char**, so Ritchie thought it cool to allow
the array syntax when declaring function parameters. But in order to do
this:

//In the Big Program, the workaround is to declare a local copy of the
//pointer.
//static const char* const myOneTwo[] =
// {
// "One", "Two", 0
// };

The object myOneTwo must be an array. You can't just replace it with char**.
And the above is not a local copy of a pointer; it's an array, a duplication
of the entire array defined by your DLL.

I agree with Feng Yuan. You need to look at the disassembly of the call
point and determine exactly what is being passed to your function. In
addition, you should be linking every module you expect to share C++ objects
like this with the same CRT DLL.

-- 
Doug Harrison
Microsoft MVP - Visual C++


Relevant Pages

  • Re: Copying an array slice (Was: Re: Difficulties with passing multi-dimensional arrays)
    ... > the pointer to array of unknown size. ... but it still compiles without a cast. ... unknown at compile time so nothing can be checked. ...
    (comp.lang.c)
  • Re: A taxonomy of types
    ... array semantics, ...) ... you mean "following correct offset operator semantics"... ... What does exist is based exclusively on pointer type. ... they can't be compiled if the compiler does not know how to compile them, ...
    (comp.lang.misc)
  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... It also returned the value of the pointer. ...
    (microsoft.public.vc.language)
  • Re: variable length array
    ... it's legal to have one incomplete dimension. ... how would I declare u for 3 dimensions or more? ... legal to step through a 2D array as if it were a long 1D array. ... I showed the definition of the array and the pointer above. ...
    (comp.lang.c)
  • Re: Passing an array of structuresfrom a pointer?
    ... an array of struct. ... You cannot assign a pointer to struct to a long* ... to only declare structs in headers and then define the ...
    (microsoft.public.vc.language)