Archived

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

Craazer

Is this an DLL problem?

Recommended Posts

Craazer    122
Hi! I''ve been working my DLL based engine for some time now, and I have ran in to a few problems whit STL... NOTE: I use dlls as statically linked so I dont use load librarys or anything like that. And c++ First this function crashes in dll if its called outside the dll.
void Pusher(vector<COLOR>& vec)
{
 vec.push_back(COLOR()); // assertion fails, invalid pointer

}

// and the calling code "in the exe":

vector<COLOR> rainbow;
Pusher(rainbow);

And Here''s another one wich I tested long time A go so it might not be a real problem but I''l show it any way.

void DrawText(string text)
{
 // in this example DXDrawText takes char* as first parameter and int length as second.

 DXDrawText(text.c_str(),text.lenght()); // accessing text in any way crashes the app

}

// and the calling code wich shouldn''t be to much wrong:

string str = "text wich never got to the screen...";
DrawText(str);

So my brilliant conclusion is that classes doesn''t work whit dlls.....?

Share this post


Link to post
Share on other sites
SiCrane    11839
Using classes with DLL is very error prone in practice. I advise against it whenever possible. That being said, it is possible to use STL objects in DLLs, you just need to properly export the classes. For an example of the syntax necessary to do this take a look at this article from MSDN.

Share this post


Link to post
Share on other sites