Passing string over DLL boundaries.

Discussion in 'C++' started by Ò»Ê×Ê«, Aug 24, 2008.

  1. Ò»Ê×Ê«

    Ò»Ê×Ê« Guest

    Hi all,

    This a problem about windows dll.

    I wrote a dll export this API to learn how strings are passed over the
    dll boundaries.

    extern "C" PINVOKELIB_API char * TestStringAsResult()
    {
    STRSAFE_LPWSTR result = (STRSAFE_LPWSTR)CoTaskMemAlloc( 1000 * 1000
    * 100 );
    StringCchCopy( result, 1000 , (STRSAFE_LPWSTR)"This is return
    value" );
    return (char *) result;
    }

    In my opinion, as the function allocated memory but do not release
    it, any call of it would leak 100M bytes memory.

    But that doesn't happen! Is there some mechanism that automatically
    release memory of string passed over dll boundaries?

    Thanks a lot!
     
    Ò»Ê×Ê«, Aug 24, 2008
    #1
    1. Advertising

  2. Ò»Ê×Ê«

    Ian Collins Guest

    一首诗 wrote:
    > Hi all,
    >
    > This a problem about windows dll.
    >

    Then you really should ask in a windows group, this isn't a C++ question.

    --
    Ian Collins.
     
    Ian Collins, Aug 24, 2008
    #2
    1. Advertising

  3. 一首诗 wrote:
    > extern "C" PINVOKELIB_API char * TestStringAsResult()
    > {
    > STRSAFE_LPWSTR result = (STRSAFE_LPWSTR)CoTaskMemAlloc( 1000 * 1000
    > * 100 );
    > StringCchCopy( result, 1000 , (STRSAFE_LPWSTR)"This is return
    > value" );
    > return (char *) result;
    > }
    >
    > In my opinion, as the function allocated memory but do not release
    > it, any call of it would leak 100M bytes memory.
    >
    > But that doesn't happen! Is there some mechanism that automatically
    > release memory of string passed over dll boundaries?


    Without knowing what STRSAVE_LPWSTR does it's impossible to say.
    However, that name itself may be telling us something.
     
    Juha Nieminen, Aug 24, 2008
    #3
  4. Ò»Ê×Ê«

    Ian Collins Guest

    Juha Nieminen wrote:

    >
    > Without knowing what STRSAVE_LPWSTR does it's impossible to say.
    > However, that name itself may be telling us something.


    That this isn't a C++ question?

    --
    Ian Collins.
     
    Ian Collins, Aug 24, 2008
    #4
  5. Ian Collins wrote:
    > Juha Nieminen wrote:
    >
    >> Without knowing what STRSAVE_LPWSTR does it's impossible to say.
    >> However, that name itself may be telling us something.

    >
    > That this isn't a C++ question?


    It could be, if we knew what STRSAVE_LPWSTR is.
     
    Juha Nieminen, Aug 24, 2008
    #5
    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. Laura
    Replies:
    1
    Views:
    419
    Laura
    Jun 3, 2004
  2. John Harrison

    pass char* over dll-boundaries

    John Harrison, Sep 3, 2004, in forum: C++
    Replies:
    8
    Views:
    829
  3. ben mitch
    Replies:
    21
    Views:
    930
    Chris Dollin
    Jun 16, 2008
  4. ben mitch
    Replies:
    22
    Views:
    858
    Chris Dollin
    Jun 16, 2008
  5. Tuxedo
    Replies:
    31
    Views:
    231
    Kaz Kylheku
    Mar 20, 2014
Loading...

Share This Page