my question is as follows:
I've got a DLL in which I have a method GetBuffer (this one is extern,
exported, is called from outside this program) which shall pass a
char-buffer to the calling-function for further handling.
If I've confused you, here's the code snippet (it's within a simple
Win32-Dll-project):
char* buffer; // global buffer - this one points to my buffer (for
puttiing it simple in here I assume memory is already allocated and buffer
points to the correct string)
int bufferLen; // global bufferlength - value assigned beforehand,
too
extern "C" __declspec(dllexport)
void GetBuffer(int *length, char retBuffer[]) // out-paramaters (buffer
shall be returned)
{
*length = bufferLen;
memcpy(retBuffer, buffer, bufferLen);
}
----------------------------------------------------------------------------
-
I call this function and want to make use of the buffer within a simple
win32-c++-console-application like this:
extern "C" __declspec(dllimport) void GetBuffer(int *length, char
retBuffer[]);
int _tmain(int argc, _TCHAR* argv[])
{
char retBuffer[1000];
int length;
GetBuffer(&length, retBuffer); // call exported function
printf("Buffer: %s\n", retBuffer);
}
---------------------------------------------------------------------------
Still confused? Ok: I just want to get the char*-buffer into my win32-app
that uses this dll - so I just want to ask what I have to do that I can
"export" the char* buffer? I'm not sure if I can use a char*-parameter in
the GetBuffer-function or if I am to use a char[]-array as tried above.
-----
Fact is, that if I execute the above code, I get a memory-access-error - so
I must have made a crucial mistake.
I appreciate your hints,
ekim!