Monday, May 24, 2010

Question about visual c++?

I made a regular DLL by Visual C++ 6 and some functions in it returns a CString object. but when i link it dynamically to a Visual C++ .Net program it receives the string completely wrong , i don't know why, please help me , what i can do to repair this broblem

Question about visual c++?
I'd have to see the code to be sure, but I suspect the problem is that the string you are returning is allocated from within the DLL. If you do this, when the stack frame of the DLL is released the memory is tossed, and becomes random.





If this is the problem, there are 2 ways to deal with it. One is to pass a pointer to a sufficiently large object in the call of the utility function and fill the result into that. The other is to use alloc() to allocate the memory explicitly in the DLL, and then explicitly release it when you are done with it.
Reply:To clarify, I think the string is *staticly* allocated inside the DLL. Of course if it dynamically allocated (through malloc()) there would not be a problem. Report It


garland flower

No comments:

Post a Comment