Re: [OT] Re: pass char* over dll-boundaries
From: Howard (alicebt_at_hotmail.com)
Date: 09/03/04
- Next message: Howard: "Re: doModal"
- Previous message: John Harrison: "Re: Linked list inserting items from two different funcion"
- In reply to: Ekim: "Re: [OT] Re: pass char* over dll-boundaries"
- Next in thread: Howard: "Re: [OT] Re: pass char* over dll-boundaries"
- Reply: Howard: "Re: [OT] Re: pass char* over dll-boundaries"
- Reply: Ekim: "Re: [OT] Re: pass char* over dll-boundaries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 03 Sep 2004 15:48:09 GMT
"Ekim" <the.newsletter@gmx.net> wrote in message
news:2pr63fFoniarU1@uni-berlin.de...
> "John Harrison" <john_andronicus@hotmail.com> wrote in message
> news:2pr3idFnlhnuU1@uni-berlin.de...
> >
> > "Ekim" <the.newsletter@gmx.net> wrote in message
> > news:2pr02eFo4hqgU1@uni-berlin.de...
> > > 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.
> > >
> >
> > [snip]
> >
> > Passing memory from an executable to a DLL is not something that is
> defined
> > by the C++ language, so this question is off topic here. But I think you
> > will find that the problem is that memory allocated in one DLL or
> executable
> > cannot be access in another DLL or executable. So that is the problem,
not
> > the way that you have declared the method or the buffer.
> >
> > For details on how to solve this problem please ask in a topical
> newsgroup,
> > news:comp.os.ms-windows.programmer.win32 for instance.
> >
> > John
>
> Good, my question is not really about DLL-boundaries, but about
> buffer-passing over functions in c++ in general.
>
Well, your original question *was* about passing between different
applications, which is *ver* different from just passing between functions
in the same application.
> So just a simple example:
> ----------------
> static char* tmpString = NULL;
> static int tmpLength = -1;
>
> void MyFunction(char* inputString, int inputSize) // here I get the
> correct buffer
> {
> tmpString = inputString; // copy buffer into global variable
This does *not* copy the buffer, it merely makes tmpString point to the same
character(s) as inputString points to. If inputString is deleted, then
tmpString will become an invalid pointer.
> tmpLength = inputSize;
> }
>
> // now I want to print the buffer in any method like this:
> void AnyMethod()
> {
> printf("Buffer: %s\n", tmpString);
> }
>
> I guess the above code works. But is there for example a possibility to
> transform the char* "inputString" I got in MyFunction into a byte-array of
> the length "inputSize" I got in MyFunction?
>
What's to transform? You can use a char* pointer in the same fashion as an
array variable. If you need a *separate* char array, then use new
char[size] (and later delete[]) to instantiate a char* pointer (to an array
of char), and strcpy the contents from one string to the other.
But you'll probably save yoursefl a lot of effort if you start using the
std::string class for most string handling.
(So what happened to your original problem of passing the string from a
DLL?)
-Howard
- Next message: Howard: "Re: doModal"
- Previous message: John Harrison: "Re: Linked list inserting items from two different funcion"
- In reply to: Ekim: "Re: [OT] Re: pass char* over dll-boundaries"
- Next in thread: Howard: "Re: [OT] Re: pass char* over dll-boundaries"
- Reply: Howard: "Re: [OT] Re: pass char* over dll-boundaries"
- Reply: Ekim: "Re: [OT] Re: pass char* over dll-boundaries"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|