News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Returning A String

Started by Robert Collins, February 02, 2005, 06:20:12 PM

Previous topic - Next topic

Robert Collins

Is it possible to return a string in C? I want to call a C written DLL passing it a string (no problem here) and the DLL function will modify the string and return it back to the caller.

UncannyDude

Modify in place? If so, you already know where's the string(you passed a pointer to it, remember?)
If it are to return a new string, IIRC return will put in eax. Or you can pass the string as a pointer to the string proper(by reference)

Assure to not overrun your buffer.

Robert Collins

Quote from: UncannyDude on February 02, 2005, 10:51:11 PM
Modify in place? If so, you already know where's the string(you passed a pointer to it, remember?)
If it are to return a new string, IIRC return will put in eax. Or you can pass the string as a pointer to the string proper(by reference)

Assure to not overrun your buffer.

UncannyDude,

I am asking about "C", not MASM. The calling program will be either be in MASM or some other language but the DLL is in "C". The caller passes the DLL a string value, the DLL will do something with this string and return to the caller the results of the 'something' as a return value (not to actually modify the sending argument).

Example:


Caller:       '
              '
              Results = DoSomethingToArgument(StringArgument)
              '
              '
       
DLL:          returnvalue _stdcall DoSomethingToArgument(LPSTR StringData)
              {
                // Take the input argument and do something with it
                // return the results back to the caller as a seperate value
              }   



hutch--

The choices are much the same as in MASM, pass an original string and a buffer or pass the original string and have the result written back to it. There are variations, allocate memory and pass the handle so that the called procedure can reallocate it if it needs to be bigger.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Robert Collins

OK :bg Thanks to you both. I see what to do now.