Re: Return non-unicode string from dll
Quote:
Originally Posted by
ill_comms
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
Re: Return non-unicode string from dll
Quote:
Originally Posted by
rxbagain
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
Re: Return non-unicode string from dll
Quote:
Originally Posted by
rxbagain
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
... 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.
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;
Re: Return non-unicode string from dll
Quote:
Originally Posted by
ill_comms
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.
Quote:
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.
Quote:
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.
Quote:
(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
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