473,394 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Return char* From DLL

Hi All,

I am facing a problem can anyone help.

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
Feb 6 '08 #1
4 5172
On Feb 6, 11:29 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
Hi All,

I am facing a problem can anyone help.

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
Feb 6 '08 #2
On Feb 6, 11:29 am, "Samant.Tru...@gmail.com"
<Samant.Tru...@gmail.comwrote:
Hi All,

I am facing a problem can anyone help.

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...
Feb 6 '08 #3
"Sa***********@gmail.com" <Sa***********@gmail.comwrote in
news:86**********************************@d4g2000p rg.googlegroups.com:
Hi All,

I am facing a problem can anyone help.

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
Feb 6 '08 #4
Sa***********@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.
Feb 7 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: starket | last post by:
Hi folks, I'm new to programming, please help, char * b, q, *r; b=getbuf(); q = *b; r= anotherfunction(b); /* we want to use ‘q' and ‘r' here*/ char * getbuf() {
23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
9
by: Steven | last post by:
Hello, I have a question about strcmp(). I have four words, who need to be compared if it were two strings. I tried adding the comparison values like '(strcmp(w1, w2) + strcmp(w3, w4))', where...
22
by: Michael Rasmussen | last post by:
Hi all, Not sure if this is OT? I have a function in a library written in C++ which returns a strdup(s.c_str()) to an application written i C. Running Valgrind on my C-application shows this...
3
by: kikazaru | last post by:
Is it possible to return covariant types for virtual methods inherited from a base class using virtual inheritance? I've constructed an example below, which has the following structure: Shape...
12
by: Aff | last post by:
Brothers , i am facing a problem which is as follow: class poly { private: char name; int capacity; public: poly(char , int );
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
2
by: utab | last post by:
Dear all, I tried sth easy(actually this was an exercise) but I tried to use the standard lib. heavily for this problem(as far as I can). There was one point I could not figure out. The problem...
10
by: vignesh4u | last post by:
I am trying to implement the Split function in C ie. if i have a string: char* S="This is a test"; and if i try to split based on space ' ' it should return an array of strings like: ...
4
by: | last post by:
The output is: 1234 After getline: 1234 After renew: 1234 After retnp: İİİİİİİİİİİİİİİİG After getp: İİİİİİİİİİİİİİİİG -----What happen after renew/retnp call?------- Why not return a true...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.