If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register or Login
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

[RESOLVED] Making dll with one of the Codeguru articles

Hi!
I make a dll and its using by this tutorial. I make absolutely the same files with the same code. Ok. It works just fine. Now I add my function with #include vector, using namespace std and fstream of course:

Re: Making dll with one of the Codeguru articles

Originally Posted by 330xi

Hi!
I make a dll and its using by this tutorial. I make absolutely the same files with the same code. Ok. It works just fine. Now I add my function with #include vector, using namespace std and fstream of course:

You should not be passing vectors and any objects such as this acrosss DLL boundaries. You cannot guarantee that

1) the vector that your application uses is exactly the same one that exists in the DLL (and I mean exactly the same one, down to the byte level).

2) The vector that your application uses is using the exact same heap manager internally as the one in the DLL.

If the error wasn't caused by the vector, it still doesn't matter -- you would have run into it anyway as soon as you try and do anything with vector. The reason for the error would be more than likely caused by using different vector classes (the public interface is the same, but the internals are different), or that your application uses one heap, the DLL uses another heap, and you're trying to manipulate the vector in some way that causes the wrong heap manager to be used.

Look at the tutorial -- you see simple, integral types passed and returned (BOOL, DWORD, pointers to these types, etc.). You don't see things such as vectors, list, streams, etc. being passed. There is a reason for this, as I've pointed out above.

Also on a side note, you should be passing objects by reference or const reference, not by value. Why are you passing vector by value? You're invoking the call to the copy constructor when you pass objects by value, and this is probably where everything falls apart. Even so, don't pass vectors or any "complex" C++ type (including your own classes) unless you can make the guarantee that the internals of the class are exactly the same, and the DLL and the application is using the same heap manager.

Re: Making dll with one of the Codeguru articles

Oh, thanks a lot for such detailed answer, Paul! It really helped. At least directed me for many other interesting articles. As for my application and dll I have reorganised them in the other way, with no such objects passing, with no problems at all.