Hi. Thanks for the answer. Then I have a strange bug I don't see. I post you an example:
Code:
#include <stdio.h>
#include <windows.h>
#include <process.h>
#include "debug.h"
#define OK 1
#define ERR 0
int (__stdcall *f_status) (char *) = NULL;
void thread_func(void *dummy) {
debug_msg("Thread running");
f_status("Thread running");
}
int __declspec(dllexport) __stdcall _RegisterStatusFunc (int (__stdcall *statusfunc) (char*)) {
long thread1 = 1;
debug_msg("Registering 'RegisterStatusFunc'");
f_status=statusfunc;
f_status("First call to f_status successfully");
thread1 = beginthread(thread_func,0, NULL);
if (thread1 == -1) {
debug_msg("Error creating main thread");
return ERR;
}
debug_msg_si("Thread ID",thread1);
return OK;
}
BOOL WINAPI __declspec(dllexport) DllMain (HINSTANCE hInst, DWORD Reason, LPVOID Reserved)
{
if(Reason==DLL_PROCESS_ATTACH) {
init_debug();
debug_msg("PROCESS_ATTACH");
f_status=NULL;
return TRUE;
}
if(Reason==DLL_PROCESS_DETACH) {
debug_msg("PROCESS_DETACH");
return TRUE;
}
if (Reason==DLL_THREAD_ATTACH) {
debug_msg("THREAD_ATTACH");
return TRUE;
}
if (Reason==DLL_THREAD_DETACH) {
debug_msg("THREAD_DETACH");
return TRUE;
}
return FALSE;
}
if I run this dll with the line:
Code:
thread1 = beginthread(thread_func,0, NULL);
it crash.
If I run this dll, but replace this line with:
without using a thread, it does not crash.
In first case, I see the thread running, as I have a log in my debug file. It crash when call to f_status.
Second case, not using threads, it does not crash and the status message is send to the calling program.
Maybe is a calling convention problem, or a call with different code of compilers, ...... I dont know.
I have tried the above code with differents compilers (VC, BCC55, lcc32, ...) and I have this problem with all.
Any idea? It looks simple, but I dont see the point.
thx in advance.