I've got a C++ dll and I've used boost library to implement multithreading and then I’d like to use this dll in a C# program.
I did it and my program is running as I expected and there isn’t any problems in my system.
When I create an installer with using of Advanced Installer and install it as a new program in my system, (which I've developed application on it) everything is ok too and there isn't any problems. But when I installed this program in other systems and run it, at first, program will run normally but when it wants to create threads and run them, program will be stopped.
A part of my codes in C++ dll are as follow:
struct ThreadParams
{
int thetaStart,
thetaEnd,
rStart;
vector<string> files;
}thParams;
const int NUM_OF_THREADS = 5;
extern "C"
{
__declspec(dllexport) int __stdcall Start(const char *path)
{
thParams.files = listFilesInDirectory(path);
int step = thParams.files.size()/NUM_OF_THREADS;
thParams.rStart = 1;
thParams.thetaStart = 0;
thParams.thetaEnd = 360;
boost::thread_group tgroup;
FILE *output_text;
char *buffer = new char[128];
for (int i = 0; i < NUM_OF_THREADS; i++)
{
sprintf(buffer,"out%d.txt",i+1);
output_text = fopen(buffer,"wt");
int start = i*step;
int end = (thParams.files.size() - (start+step)) >= step ? (start+step) : thParams.files.size();
tgroup.create_thread(boost::bind(ThreadProcess,start,end,output_text,i+1));
}
tgroup.join_all();
_fcloseall();
delete buffer;
buffer = NULL;
}
}
void ThreadProcess(int start, int end, FILE *out, int threadID)
{
for(int i = start; i < end; ++i)
{
fprintf(out,"%s\n",thParams.files[i].c_str());
}
}
Could anybody help me to resolve this problem, please?
Thanks in advance.