Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

sprawl

DLL

This topic is 6924 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there any problem returning pointers from functions in a dll -- IN .dll -- char *func() { char *buf = new buf[20]; strcpy(buf,"hello"); return buf; } this dll is called from a cpp program. like printf("%s\n",the_dll_func()); and the dll_func is declared to use C style linking when i run the main program it just outputs garbage. anyone have a clue? //sprawl

Share this post


Link to post
Share on other sites
Advertisement
I have done something similar lots of times with no problems.

Have you tested if your dll can return other things such as numbers?

Share this post


Link to post
Share on other sites
yes, i have done a function like this
bool func(int parameter)
{
if(parameter=123)
return true;
else
return false;
}

and that one works without problems

Share this post


Link to post
Share on other sites
Ok, now I would try to do 3 things:

1. Print the value of the pointer from the DLL and then again from the EXE. This can give you tip about if the pointer has changed and where we then should look for a solution.

2. Are you sure that you are compiling the modules in the same way. If for instance one of your modules are compiled as 16-bit code it can cause the named problem because the size of a pointer differs in the two modes.

3. I am guessing here: Try declaring the pointer as "far".

Edited by - felonius on May 11, 2000 4:50:11 AM

Share this post


Link to post
Share on other sites
Actually it was me that was unattentive, the trouble was caused when i closed and reopened msvc then it changed the configuration from win32 release to win32 debug, and i was still loading the win32 release .dll but i was changing the win32 debug .dll.

So the problem was that it was still returning a int and not a char pointer. so there of the mysterious problem!

but thank you very much for the help and time!
//Andreas

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!