CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Return non-unicode string from dll

    Quote Originally Posted by ill_comms View Post
    This is something else I haven't tried yet. Passing a buffer through by reference.
    Don't do it.

    A "reference" is a C++ thing, and it is a compiler specific thing. There is no concrete knowledge of how a reference is implemented internally, therefore it cannot be safely shared.

    If you read the C++ specification on what a reference is, the specification only gives you information on how a reference is to behave. The underlying mechanics of a reference type is implementation-defined.

    Unless that DLL is going to be used by applications built with the same compiler, compiler version, and same compiler options, there is no guarantee that the reference will be the same thing between app and DLL.

    Regards,

    Paul McKenzie

  2. #17
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Return non-unicode string from dll

    Quote Originally Posted by rxbagain View Post
    If MapBasic behaves exactly like VB, you can return a BSTR containing ANSI string and VB (or MapBasic) will automatically release the pointer using SysFreeString.
    Yes, that is another option (a variation of option 1 that I mentioned earlier).

    Regards,

    Paul McKenzie

  3. #18
    Join Date
    Mar 2009
    Posts
    51

    Re: Return non-unicode string from dll

    Quote Originally Posted by rxbagain View Post
    If MapBasic behaves exactly like VB, you can return a BSTR ... and VB (or MapBasic) will automatically release the pointer using SysFreeString.
    That is correct and would normally be the best solution.

    However:
    Quote Originally Posted by rxbagain View Post
    ... containing ANSI string ...
    No, a BSTR is UNICODE in Windows:

    http://msdn.microsoft.com/en-us/library/ms221069.aspx

    If he should not return a UNICODE string then he cannot return a BSTR.

  4. #19
    Join Date
    Oct 2005
    Posts
    27

    Re: Return non-unicode string from dll

    Not sure if we're on the same page or not. From my program in MapBasic I can pass through variables either by reference or ByVal, that's all I meant.

    I pass through other buffer variables by reference with all windows API calls. And like you say in the Option 3 the dll populates it. Now all I'm trying to do declare it somehow in here:

    (Cstring &myBuffer, int bufferSize) or (char &myBuffer, int bufferSize)

    and populate it

    myBuffer = myCstringValue;

  5. #20
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Return non-unicode string from dll

    Quote Originally Posted by ill_comms View Post
    Not sure if we're on the same page or not. From my program in MapBasic I can pass through variables either by reference or ByVal, that's all I meant.
    The definition of "reference" to a C++ programmer is different than a "reference" for MapBasic. Do not confuse the two, as they are vastly different.

    Again, a C++ reference is only known by C++ programs. It is a C++ invention and has nothing to do with "reference" in terms of MapBasic.
    I pass through other buffer variables by reference with all windows API calls.
    There are no Windows API calls that take "references". They either take integral values, doubles, POD structs or pointers to these types. If you mean "pass by reference" as using pointers, then pointers are not references in C++. A reference is a reference, and a pointer is a pointer.
    And like you say in the Option 3 the dll populates it. Now all I'm trying to do declare it somehow in here:
    A CString is only known to MFC, C++ based programs. It is unknown to any other other system.
    (Cstring &myBuffer, int bufferSize) or (char &myBuffer, int bufferSize)
    I think your confusion is the "&" symbol. The proper declaration would be:
    Code:
    LONG MyFunction(char *buffer, LONG bufferSize);
    Something like that. Note that buffer is a pointer, not a reference.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 6th, 2009 at 03:27 AM.

  6. #21
    Join Date
    Oct 2005
    Posts
    27

    Re: Return non-unicode string from dll

    Hi Paul,
    thanks you're correct about the pointer, I was using terminology coming from the MapBasic guide book, it leaves alot to be desired.

    I think you guys have given me enough to carry on by myself now. And I have multiple options if I do anything like this again.... which is highly likely. Thanks for your time and double that for your patience.

    Regards Hayden

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured