|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi All,
I am facing a problem can anyone . I have a function in DLL void getString(char *string) { strcpy(string, "My String); printf("In Dll %s", string); } I am calling this function in my win32 consol app char mystr[50]; strcpy(mystr, "Test"); getString(myStr); printf("in main %s", mystr); The result I am getting is: In Dll My String In Main Test Why DLL is unable to retutn value? If I use this function in main it is working fine. DLL not working. Can anyone please explain? Thanks Trupti |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Feb 6, 11:29 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.com> wrote: > Hi All, > > I am facing a problem can anyone . > > I have a function in DLL > void getString(char *string) > { > strcpy(string, "My String); > printf("In Dll %s", string); > > } > > I am calling this function in my win32 consol app > > char mystr[50]; > strcpy(mystr, "Test"); > getString(myStr); > printf("in main %s", mystr); > > The result I am getting is: > In Dll My String > In Main Test > > Why DLL is unable to retutn value? Your DLL (function) is NOT returning a value [void getString(char *string)], you are attempting to modify the char* pointer. AFAIR it used to work, try to print out the address of those strings both in DLL's printf() and main's printf(). > If I use this function in main it > is working fine. DLL not working. > Can anyone please explain? > Thanks > Trupti |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Feb 6, 11:29 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.com> wrote: > Hi All, > > I am facing a problem can anyone . > > I have a function in DLL > void getString(char *string) > { > strcpy(string, "My String); > printf("In Dll %s", string); > > } > > I am calling this function in my win32 consol app > > char mystr[50]; > strcpy(mystr, "Test"); > getString(myStr); > printf("in main %s", mystr); > > The result I am getting is: > In Dll My String > In Main Test > > Why DLL is unable to retutn value? If I use this function in main it > is working fine. DLL not working. > Can anyone please explain? > Thanks > Trupti If you want to return a value try char* getString(char *string){ .... return yourString; } P.S. You will have to allocate memory to that string inside your DLL function... |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
"Samant.Trupti@gmail.com" <Samant.Trupti@gmail.com> wrote in
news:868e7f92-f997-4ae8-b426-8dcb8a47634a@d4g2000prg.googlegroups.com: > Hi All, > > I am facing a problem can anyone . > > I have a function in DLL > void getString(char *string) > { > strcpy(string, "My String); > printf("In Dll %s", string); > } > > I am calling this function in my win32 consol app > > char mystr[50]; > strcpy(mystr, "Test"); > getString(myStr); > printf("in main %s", mystr); > > The result I am getting is: > In Dll My String > In Main Test > > Why DLL is unable to retutn value? If I use this function in main it > is working fine. DLL not working. > Can anyone please explain? > Thanks > Trupti > I can say that I have done things like that without trouble. Off hand, I would say to check your compiler options to make sure that your dll is compiled the same way your console app is. Otherwise, I am left with the thought that the posted code doesn't match exactly what is in your actual code. I really think that there is some compiler option that is different and causing the issue. joe |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On Feb 6, 3:29am, "Samant.Tru...@gmail.com" <Samant.Tru...@gmail.com>
wrote: > Hi All, > > I am facing a problem can anyone . > > I have a function in DLL > void getString(char *string) > { > strcpy(string, "My String); > printf("In Dll %s", string); > > } > > I am calling this function in my win32 consol app > > char mystr[50]; > strcpy(mystr, "Test"); > getString(myStr); myStr has not been defined > printf("in main %s", mystr); mystr is not the same entity as myStr > > The result I am getting is: > In Dll My String > In Main Test > > Why DLL is unable to retutn value? If I use this function in main it > is working fine. DLL not working. > Can anyone please explain? Cut and paste the exact code that you think is a problem. The above snippets will not compile. -- Fred Kleinschmidt |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
Samant.Trupti@gmail.com wrote:
> > I am calling this function in my win32 consol app > > Why DLL is unable to retutn value? If I use this function in main it > is working fine. DLL not working. > Can anyone please explain? I have this problem with MS VC8 and up. That compiler refuses to allow char * to be returned from a DLL ( although it will return other pointer values ). This problem does not occur in any other compiler I have, nor in versions of MSVC below V8. |
|
![]() |
| Outils de la discussion | |
|
|