PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.cplus > Return char* From DLL
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Return char* From DLL

Réponse
 
LinkBack Outils de la discussion
Vieux 06/02/2008, 11h29   #1
Samant.Trupti@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Return char* From DLL

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
  Réponse avec citation
Vieux 06/02/2008, 14h53   #2
GArlington
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Return char* From DLL

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


  Réponse avec citation
Vieux 06/02/2008, 15h01   #3
GArlington
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Return char* From DLL

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...
  Réponse avec citation
Vieux 06/02/2008, 15h14   #4
Joe Greer
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Return char* From DLL

"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
  Réponse avec citation
Vieux 06/02/2008, 19h33   #5
fred.l.kleinschmidt@boeing.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Return char* From DLL

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


  Réponse avec citation
Vieux 07/02/2008, 10h09   #6
James Connell
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Return char* From DLL

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.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 11h22.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15107 seconds with 14 queries